Skip to content

Commit d40003c

Browse files
committed
Merge #414: Improve timelock code
b084010 Use terse functional programming terms (Tobin C. Harding) 6f3303d Improve docs on TimelockInfo (Tobin C. Harding) b2f6ef0 Add unit test for combine_threshold (Tobin C. Harding) a36f608 Be uniform in spelling of timelock (Tobin C. Harding) 51de643 Rename comibine methods (Tobin C. Harding) ef6803f Use > 1 instead of >= 2 (Tobin C. Harding) d1fdbaa Use LOCKTIME_THRESHOLD same as bitcoin core (Tobin C. Harding) Pull request description: Done while working on a [timelock module](rust-bitcoin/rust-bitcoin#994). This is all the initial patches (except one) from #408 (which is a PR displaying usage of the new timelock module). Note, does _not_ do the 'make `TimelockInfo` fields pub crate' change - I was unsure if this was correct. Top commit has no ACKs. Tree-SHA512: aa54e2d884f7cb1fb5dcb2d828ada29830ac4a7a09b04797e6e2fb448df476cbb31345841735e6cf4d5b7b1f6783781859778805fffef708f259fe780c6ba677
2 parents 5649628 + b084010 commit d40003c

File tree

8 files changed

+111
-88
lines changed

8 files changed

+111
-88
lines changed

src/interpreter/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -485,12 +485,12 @@ pub enum SatisfiedConstraint {
485485
preimage: [u8; 32],
486486
},
487487
///Relative Timelock for CSV.
488-
RelativeTimeLock {
488+
RelativeTimelock {
489489
/// The value of RelativeTimelock
490490
time: u32,
491491
},
492492
///Absolute Timelock for CLTV.
493-
AbsoluteTimeLock {
493+
AbsoluteTimelock {
494494
/// The value of Absolute timelock
495495
time: u32,
496496
},
@@ -1197,7 +1197,7 @@ mod tests {
11971197
let after_satisfied: Result<Vec<SatisfiedConstraint>, Error> = constraints.collect();
11981198
assert_eq!(
11991199
after_satisfied.unwrap(),
1200-
vec![SatisfiedConstraint::AbsoluteTimeLock { time: 1000 }]
1200+
vec![SatisfiedConstraint::AbsoluteTimelock { time: 1000 }]
12011201
);
12021202

12031203
//Check Older
@@ -1207,7 +1207,7 @@ mod tests {
12071207
let older_satisfied: Result<Vec<SatisfiedConstraint>, Error> = constraints.collect();
12081208
assert_eq!(
12091209
older_satisfied.unwrap(),
1210-
vec![SatisfiedConstraint::RelativeTimeLock { time: 1000 }]
1210+
vec![SatisfiedConstraint::RelativeTimelock { time: 1000 }]
12111211
);
12121212

12131213
//Check Sha256

src/interpreter/stack.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ impl<'txin> Stack<'txin> {
235235
) -> Option<Result<SatisfiedConstraint, Error>> {
236236
if age >= *n {
237237
self.push(Element::Satisfied);
238-
Some(Ok(SatisfiedConstraint::AbsoluteTimeLock { time: *n }))
238+
Some(Ok(SatisfiedConstraint::AbsoluteTimelock { time: *n }))
239239
} else {
240240
Some(Err(Error::AbsoluteLocktimeNotMet(*n)))
241241
}
@@ -254,7 +254,7 @@ impl<'txin> Stack<'txin> {
254254
) -> Option<Result<SatisfiedConstraint, Error>> {
255255
if height >= *n {
256256
self.push(Element::Satisfied);
257-
Some(Ok(SatisfiedConstraint::RelativeTimeLock { time: *n }))
257+
Some(Ok(SatisfiedConstraint::RelativeTimelock { time: *n }))
258258
} else {
259259
Some(Err(Error::RelativeLocktimeNotMet(*n)))
260260
}

src/miniscript/analyzable.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub enum AnalysisError {
4141
/// Miniscript contains at least one path that exceeds resource limits
4242
BranchExceedResouceLimits,
4343
/// Contains a combination of heightlock and timelock
44-
HeightTimeLockCombination,
44+
HeightTimelockCombination,
4545
/// Malleable script
4646
Malleable,
4747
}
@@ -58,7 +58,7 @@ impl fmt::Display for AnalysisError {
5858
AnalysisError::BranchExceedResouceLimits => {
5959
f.write_str("At least one spend path exceeds the resource limits(stack depth/satisfaction size..)")
6060
}
61-
AnalysisError::HeightTimeLockCombination => {
61+
AnalysisError::HeightTimelockCombination => {
6262
f.write_str("Contains a combination of heightlock and timelock")
6363
}
6464
AnalysisError::Malleable => f.write_str("Miniscript is malleable")
@@ -128,7 +128,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
128128
} else if self.has_repeated_keys() {
129129
Err(AnalysisError::RepeatedPubkeys)
130130
} else if self.has_mixed_timelocks() {
131-
Err(AnalysisError::HeightTimeLockCombination)
131+
Err(AnalysisError::HeightTimelockCombination)
132132
} else {
133133
Ok(())
134134
}

src/miniscript/limits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub const MAX_STANDARD_P2WSH_SCRIPT_SIZE: usize = 3600;
1717
/// The Threshold for deciding whether `nLockTime` is interpreted as
1818
/// time or height.
1919
// https://github.com/bitcoin/bitcoin/blob/9ccaee1d5e2e4b79b0a7c29aadb41b97e4741332/src/script/script.h#L39
20-
pub const HEIGHT_TIME_THRESHOLD: u32 = 500_000_000;
20+
pub const LOCKTIME_THRESHOLD: u32 = 500_000_000;
2121

2222
/// Bit flag for deciding whether sequence number is
2323
/// interpreted as height or time

src/miniscript/satisfy.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use bitcoin::secp256k1::XOnlyPublicKey;
2828
use bitcoin::util::taproot::{ControlBlock, LeafVersion, TapLeafHash};
2929

3030
use crate::miniscript::limits::{
31-
HEIGHT_TIME_THRESHOLD, SEQUENCE_LOCKTIME_DISABLE_FLAG, SEQUENCE_LOCKTIME_TYPE_FLAG,
31+
LOCKTIME_THRESHOLD, SEQUENCE_LOCKTIME_DISABLE_FLAG, SEQUENCE_LOCKTIME_TYPE_FLAG,
3232
};
3333
use crate::util::witness_size;
3434
use crate::{Miniscript, MiniscriptKey, ScriptContext, Terminal, ToPublicKey};
@@ -155,7 +155,7 @@ pub struct After(pub u32);
155155
impl<Pk: MiniscriptKey + ToPublicKey> Satisfier<Pk> for After {
156156
fn check_after(&self, n: u32) -> bool {
157157
// if n > self.0; we will be returning false anyways
158-
if n < HEIGHT_TIME_THRESHOLD && self.0 >= HEIGHT_TIME_THRESHOLD {
158+
if n < LOCKTIME_THRESHOLD && self.0 >= LOCKTIME_THRESHOLD {
159159
false
160160
} else {
161161
n <= self.0

0 commit comments

Comments
 (0)