Skip to content

Commit 6b76766

Browse files
committed
fix(selection): Include fallback locktime in locktime accumulation
This allows the caller to specify an absolute locktime greater than may be required by a planned input.
1 parent 1b5f01c commit 6b76766

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

src/selection.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ pub struct PsbtParams {
3131

3232
/// Fallback tx locktime.
3333
///
34-
/// The locktime to use if no inputs specifies a required absolute locktime.
34+
/// The locktime to use if no input specifies a required absolute locktime.
3535
///
36-
/// It is best practive to set this to the latest block height to avoid fee sniping.
36+
/// It is best practice to set this to the latest block height to avoid fee sniping.
3737
pub fallback_locktime: absolute::LockTime,
3838

3939
/// [`Sequence`] value to use by default if not provided by the input.
@@ -99,11 +99,8 @@ impl std::error::Error for CreatePsbtError {}
9999

100100
impl Selection {
101101
/// Returns none if there is a mismatch of units in `locktimes`.
102-
///
103-
// TODO: As according to BIP-64... ?
104102
fn _accumulate_max_locktime(
105103
locktimes: impl IntoIterator<Item = absolute::LockTime>,
106-
fallback: absolute::LockTime,
107104
) -> Option<absolute::LockTime> {
108105
let mut acc = Option::<absolute::LockTime>::None;
109106
for locktime in locktimes {
@@ -119,9 +116,6 @@ impl Selection {
119116
acc => *acc = Some(locktime),
120117
};
121118
}
122-
if acc.is_none() {
123-
acc = Some(fallback);
124-
}
125119
acc
126120
}
127121

@@ -132,8 +126,8 @@ impl Selection {
132126
lock_time: Self::_accumulate_max_locktime(
133127
self.inputs
134128
.iter()
135-
.filter_map(|input| input.absolute_timelock()),
136-
params.fallback_locktime,
129+
.filter_map(|input| input.absolute_timelock())
130+
.chain([params.fallback_locktime]),
137131
)
138132
.ok_or(CreatePsbtError::LockTypeMismatch)?,
139133
input: self

0 commit comments

Comments
 (0)