Skip to content

Improve timelock code #414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,12 +485,12 @@ pub enum SatisfiedConstraint {
preimage: [u8; 32],
},
///Relative Timelock for CSV.
RelativeTimeLock {
RelativeTimelock {
/// The value of RelativeTimelock
time: u32,
},
///Absolute Timelock for CLTV.
AbsoluteTimeLock {
AbsoluteTimelock {
/// The value of Absolute timelock
time: u32,
},
Expand Down Expand Up @@ -1197,7 +1197,7 @@ mod tests {
let after_satisfied: Result<Vec<SatisfiedConstraint>, Error> = constraints.collect();
assert_eq!(
after_satisfied.unwrap(),
vec![SatisfiedConstraint::AbsoluteTimeLock { time: 1000 }]
vec![SatisfiedConstraint::AbsoluteTimelock { time: 1000 }]
);

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

//Check Sha256
Expand Down
4 changes: 2 additions & 2 deletions src/interpreter/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ impl<'txin> Stack<'txin> {
) -> Option<Result<SatisfiedConstraint, Error>> {
if age >= *n {
self.push(Element::Satisfied);
Some(Ok(SatisfiedConstraint::AbsoluteTimeLock { time: *n }))
Some(Ok(SatisfiedConstraint::AbsoluteTimelock { time: *n }))
} else {
Some(Err(Error::AbsoluteLocktimeNotMet(*n)))
}
Expand All @@ -254,7 +254,7 @@ impl<'txin> Stack<'txin> {
) -> Option<Result<SatisfiedConstraint, Error>> {
if height >= *n {
self.push(Element::Satisfied);
Some(Ok(SatisfiedConstraint::RelativeTimeLock { time: *n }))
Some(Ok(SatisfiedConstraint::RelativeTimelock { time: *n }))
} else {
Some(Err(Error::RelativeLocktimeNotMet(*n)))
}
Expand Down
6 changes: 3 additions & 3 deletions src/miniscript/analyzable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub enum AnalysisError {
/// Miniscript contains at least one path that exceeds resource limits
BranchExceedResouceLimits,
/// Contains a combination of heightlock and timelock
HeightTimeLockCombination,
HeightTimelockCombination,
/// Malleable script
Malleable,
}
Expand All @@ -58,7 +58,7 @@ impl fmt::Display for AnalysisError {
AnalysisError::BranchExceedResouceLimits => {
f.write_str("At least one spend path exceeds the resource limits(stack depth/satisfaction size..)")
}
AnalysisError::HeightTimeLockCombination => {
AnalysisError::HeightTimelockCombination => {
f.write_str("Contains a combination of heightlock and timelock")
}
AnalysisError::Malleable => f.write_str("Miniscript is malleable")
Expand Down Expand Up @@ -128,7 +128,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
} else if self.has_repeated_keys() {
Err(AnalysisError::RepeatedPubkeys)
} else if self.has_mixed_timelocks() {
Err(AnalysisError::HeightTimeLockCombination)
Err(AnalysisError::HeightTimelockCombination)
} else {
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion src/miniscript/limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub const MAX_STANDARD_P2WSH_SCRIPT_SIZE: usize = 3600;
/// The Threshold for deciding whether `nLockTime` is interpreted as
/// time or height.
// https://github.com/bitcoin/bitcoin/blob/9ccaee1d5e2e4b79b0a7c29aadb41b97e4741332/src/script/script.h#L39
pub const HEIGHT_TIME_THRESHOLD: u32 = 500_000_000;
pub const LOCKTIME_THRESHOLD: u32 = 500_000_000;

/// Bit flag for deciding whether sequence number is
/// interpreted as height or time
Expand Down
4 changes: 2 additions & 2 deletions src/miniscript/satisfy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use bitcoin::secp256k1::XOnlyPublicKey;
use bitcoin::util::taproot::{ControlBlock, LeafVersion, TapLeafHash};

use crate::miniscript::limits::{
HEIGHT_TIME_THRESHOLD, SEQUENCE_LOCKTIME_DISABLE_FLAG, SEQUENCE_LOCKTIME_TYPE_FLAG,
LOCKTIME_THRESHOLD, SEQUENCE_LOCKTIME_DISABLE_FLAG, SEQUENCE_LOCKTIME_TYPE_FLAG,
};
use crate::util::witness_size;
use crate::{Miniscript, MiniscriptKey, ScriptContext, Terminal, ToPublicKey};
Expand Down Expand Up @@ -155,7 +155,7 @@ pub struct After(pub u32);
impl<Pk: MiniscriptKey + ToPublicKey> Satisfier<Pk> for After {
fn check_after(&self, n: u32) -> bool {
// if n > self.0; we will be returning false anyways
if n < HEIGHT_TIME_THRESHOLD && self.0 >= HEIGHT_TIME_THRESHOLD {
if n < LOCKTIME_THRESHOLD && self.0 >= LOCKTIME_THRESHOLD {
false
} else {
n <= self.0
Expand Down
Loading