Skip to content

Commit

Permalink
Be uniform in spelling of timelock
Browse files Browse the repository at this point in the history
We currently use the form "time lock" and also "timelock" (implies
`TimeLock`, `Timelock`). Which we use is not important but we should be
uniform. Favour "timelock" (and `Timelock`).
  • Loading branch information
tcharding committed May 19, 2022
1 parent 51de643 commit a36f608
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 50 deletions.
8 changes: 4 additions & 4 deletions src/interpreter/mod.rs
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
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
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
54 changes: 27 additions & 27 deletions src/miniscript/types/extra_props.rs
Expand Up @@ -13,7 +13,7 @@ use crate::{script_num_size, MiniscriptKey, Terminal};

/// Helper struct Whether any satisfaction of this fragment contains any timelocks
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Default, Hash)]
pub struct TimeLockInfo {
pub struct TimelockInfo {
/// csv with heights
pub csv_with_height: bool,
/// csv with times
Expand Down Expand Up @@ -54,7 +54,7 @@ impl OpLimits {
}
}

impl TimeLockInfo {
impl TimelockInfo {
/// Whether the current contains any possible unspendable
/// path
pub fn contains_unspendable_path(self) -> bool {
Expand All @@ -73,9 +73,9 @@ impl TimeLockInfo {
Self::combine_threshold(1, once(a).chain(once(b)))
}

pub(crate) fn combine_threshold<I>(k: usize, sub_timelocks: I) -> TimeLockInfo
pub(crate) fn combine_threshold<I>(k: usize, sub_timelocks: I) -> TimelockInfo
where
I: IntoIterator<Item = TimeLockInfo>,
I: IntoIterator<Item = TimelockInfo>,
{
// timelocks calculation
// Propagate all fields of `TimelockInfo` from each of the node's children to the node
Expand All @@ -86,7 +86,7 @@ impl TimeLockInfo {
// If `k > 1` we have the additional consideration that if any two children have conflicting
// timelock requirements, this represents an inaccessible spending branch.
sub_timelocks.into_iter().fold(
TimeLockInfo::default(),
TimelockInfo::default(),
|mut timelock_info, sub_timelock| {
// If more than one branch may be taken, and some other branch has a requirement
// that conflicts with this one, set `contains_combination`
Expand Down Expand Up @@ -131,7 +131,7 @@ pub struct ExtData {
/// the cost for the witness stack, the second one is the cost for scriptSig.
pub max_dissat_size: Option<(usize, usize)>,
/// The timelock info about heightlocks and timelocks
pub timelock_info: TimeLockInfo,
pub timelock_info: TimelockInfo,
/// Maximum stack + alt stack size during satisfaction execution
/// This does **not** include initial witness elements. This element only captures
/// the additional elements that are pushed during execution.
Expand Down Expand Up @@ -163,7 +163,7 @@ impl Property for ExtData {
stack_elem_count_dissat: None,
max_sat_size: Some((0, 0)),
max_dissat_size: None,
timelock_info: TimeLockInfo::default(),
timelock_info: TimelockInfo::default(),
exec_stack_elem_count_sat: Some(1),
exec_stack_elem_count_dissat: None,
}
Expand All @@ -178,7 +178,7 @@ impl Property for ExtData {
stack_elem_count_dissat: Some(0),
max_sat_size: None,
max_dissat_size: Some((0, 0)),
timelock_info: TimeLockInfo::default(),
timelock_info: TimelockInfo::default(),
exec_stack_elem_count_sat: None,
exec_stack_elem_count_dissat: Some(1),
}
Expand All @@ -199,7 +199,7 @@ impl Property for ExtData {
SigType::Schnorr => Some((66, 66)),
},
max_dissat_size: Some((1, 1)),
timelock_info: TimeLockInfo::default(),
timelock_info: TimelockInfo::default(),
exec_stack_elem_count_sat: Some(1), // pushes the pk
exec_stack_elem_count_dissat: Some(1),
}
Expand All @@ -220,7 +220,7 @@ impl Property for ExtData {
SigType::Ecdsa => Some((35, 35)),
SigType::Schnorr => Some((34, 34)),
},
timelock_info: TimeLockInfo::default(),
timelock_info: TimelockInfo::default(),
exec_stack_elem_count_sat: Some(2), // dup and hash push
exec_stack_elem_count_dissat: Some(2),
}
Expand All @@ -243,7 +243,7 @@ impl Property for ExtData {
stack_elem_count_dissat: Some(k + 1),
max_sat_size: Some((1 + 73 * k, 1 + 73 * k)),
max_dissat_size: Some((1 + k, 1 + k)),
timelock_info: TimeLockInfo::default(),
timelock_info: TimelockInfo::default(),
exec_stack_elem_count_sat: Some(n), // n pks
exec_stack_elem_count_dissat: Some(n),
}
Expand All @@ -265,7 +265,7 @@ impl Property for ExtData {
stack_elem_count_dissat: Some(n),
max_sat_size: Some(((n - k) + 66 * k, (n - k) + 66 * k)),
max_dissat_size: Some((n, n)),
timelock_info: TimeLockInfo::default(),
timelock_info: TimelockInfo::default(),
exec_stack_elem_count_sat: Some(2), // the two nums before num equal verify
exec_stack_elem_count_dissat: Some(2),
}
Expand All @@ -285,7 +285,7 @@ impl Property for ExtData {
stack_elem_count_dissat: Some(1),
max_sat_size: Some((33, 33)),
max_dissat_size: Some((33, 33)),
timelock_info: TimeLockInfo::default(),
timelock_info: TimelockInfo::default(),
exec_stack_elem_count_sat: Some(2), // either size <32> or <hash256> <32 byte>
exec_stack_elem_count_dissat: Some(2),
}
Expand All @@ -300,7 +300,7 @@ impl Property for ExtData {
stack_elem_count_dissat: Some(1),
max_sat_size: Some((33, 33)),
max_dissat_size: Some((33, 33)),
timelock_info: TimeLockInfo::default(),
timelock_info: TimelockInfo::default(),
exec_stack_elem_count_sat: Some(2), // either size <32> or <hash256> <32 byte>
exec_stack_elem_count_dissat: Some(2),
}
Expand All @@ -315,7 +315,7 @@ impl Property for ExtData {
stack_elem_count_dissat: Some(1),
max_sat_size: Some((33, 33)),
max_dissat_size: Some((33, 33)),
timelock_info: TimeLockInfo::default(),
timelock_info: TimelockInfo::default(),
exec_stack_elem_count_sat: Some(2), // either size <32> or <hash256> <20 byte>
exec_stack_elem_count_dissat: Some(2),
}
Expand All @@ -330,7 +330,7 @@ impl Property for ExtData {
stack_elem_count_dissat: Some(1),
max_sat_size: Some((33, 33)),
max_dissat_size: Some((33, 33)),
timelock_info: TimeLockInfo::default(),
timelock_info: TimelockInfo::default(),
exec_stack_elem_count_sat: Some(2), // either size <32> or <hash256> <20 byte>
exec_stack_elem_count_dissat: Some(2),
}
Expand All @@ -349,7 +349,7 @@ impl Property for ExtData {
stack_elem_count_dissat: None,
max_sat_size: Some((0, 0)),
max_dissat_size: None,
timelock_info: TimeLockInfo {
timelock_info: TimelockInfo {
csv_with_height: false,
csv_with_time: false,
cltv_with_height: t < LOCKTIME_THRESHOLD,
Expand All @@ -370,7 +370,7 @@ impl Property for ExtData {
stack_elem_count_dissat: None,
max_sat_size: Some((0, 0)),
max_dissat_size: None,
timelock_info: TimeLockInfo {
timelock_info: TimelockInfo {
csv_with_height: (t & SEQUENCE_LOCKTIME_TYPE_FLAG) == 0,
csv_with_time: (t & SEQUENCE_LOCKTIME_TYPE_FLAG) != 0,
cltv_with_height: false,
Expand Down Expand Up @@ -518,7 +518,7 @@ impl Property for ExtData {
max_dissat_size: l
.max_dissat_size
.and_then(|(lw, ls)| r.max_dissat_size.map(|(rw, rs)| (lw + rw, ls + rs))),
timelock_info: TimeLockInfo::combine_and(l.timelock_info, r.timelock_info),
timelock_info: TimelockInfo::combine_and(l.timelock_info, r.timelock_info),
// Left element leaves a stack result on the stack top and then right element is evaluated
// Therefore + 1 is added to execution size of second element
exec_stack_elem_count_sat: opt_max(
Expand Down Expand Up @@ -549,7 +549,7 @@ impl Property for ExtData {
.max_sat_size
.and_then(|(lw, ls)| r.max_sat_size.map(|(rw, rs)| (lw + rw, ls + rs))),
max_dissat_size: None,
timelock_info: TimeLockInfo::combine_and(l.timelock_info, r.timelock_info),
timelock_info: TimelockInfo::combine_and(l.timelock_info, r.timelock_info),
// [X] leaves no element after evaluation, hence this is the max
exec_stack_elem_count_sat: opt_max(
l.exec_stack_elem_count_sat,
Expand Down Expand Up @@ -589,7 +589,7 @@ impl Property for ExtData {
max_dissat_size: l
.max_dissat_size
.and_then(|(lw, ls)| r.max_dissat_size.map(|(rw, rs)| (lw + rw, ls + rs))),
timelock_info: TimeLockInfo::combine_or(l.timelock_info, r.timelock_info),
timelock_info: TimelockInfo::combine_or(l.timelock_info, r.timelock_info),
exec_stack_elem_count_sat: cmp::max(
opt_max(
l.exec_stack_elem_count_sat,
Expand Down Expand Up @@ -632,7 +632,7 @@ impl Property for ExtData {
max_dissat_size: l
.max_dissat_size
.and_then(|(lw, ls)| r.max_dissat_size.map(|(rw, rs)| (lw + rw, ls + rs))),
timelock_info: TimeLockInfo::combine_or(l.timelock_info, r.timelock_info),
timelock_info: TimelockInfo::combine_or(l.timelock_info, r.timelock_info),
exec_stack_elem_count_sat: cmp::max(
l.exec_stack_elem_count_sat,
opt_max(r.exec_stack_elem_count_sat, l.exec_stack_elem_count_dissat),
Expand Down Expand Up @@ -666,7 +666,7 @@ impl Property for ExtData {
.and_then(|(lw, ls)| r.max_sat_size.map(|(rw, rs)| (lw + rw, ls + rs))),
),
max_dissat_size: None,
timelock_info: TimeLockInfo::combine_or(l.timelock_info, r.timelock_info),
timelock_info: TimelockInfo::combine_or(l.timelock_info, r.timelock_info),
exec_stack_elem_count_sat: cmp::max(
l.exec_stack_elem_count_sat,
opt_max(r.exec_stack_elem_count_sat, l.exec_stack_elem_count_dissat),
Expand Down Expand Up @@ -709,7 +709,7 @@ impl Property for ExtData {
(Some(l), None) => Some((2 + l.0, 1 + l.1)),
(None, None) => None,
},
timelock_info: TimeLockInfo::combine_or(l.timelock_info, r.timelock_info),
timelock_info: TimelockInfo::combine_or(l.timelock_info, r.timelock_info),
// TODO: fix elem count dissat bug
exec_stack_elem_count_sat: cmp::max(
l.exec_stack_elem_count_sat,
Expand Down Expand Up @@ -752,8 +752,8 @@ impl Property for ExtData {
max_dissat_size: a
.max_dissat_size
.and_then(|(wa, sa)| c.max_dissat_size.map(|(wc, sc)| (wa + wc, sa + sc))),
timelock_info: TimeLockInfo::combine_or(
TimeLockInfo::combine_and(a.timelock_info, b.timelock_info),
timelock_info: TimelockInfo::combine_or(
TimelockInfo::combine_and(a.timelock_info, b.timelock_info),
c.timelock_info,
),
exec_stack_elem_count_sat: cmp::max(
Expand Down Expand Up @@ -884,7 +884,7 @@ impl Property for ExtData {
stack_elem_count_dissat,
max_sat_size,
max_dissat_size,
timelock_info: TimeLockInfo::combine_threshold(k, timelocks),
timelock_info: TimelockInfo::combine_threshold(k, timelocks),
exec_stack_elem_count_sat,
exec_stack_elem_count_dissat,
})
Expand Down
22 changes: 11 additions & 11 deletions src/policy/concrete.rs
Expand Up @@ -38,7 +38,7 @@ use {
use super::ENTAILMENT_MAX_TERMINALS;
use crate::expression::{self, FromTree};
use crate::miniscript::limits::{LOCKTIME_THRESHOLD, SEQUENCE_LOCKTIME_TYPE_FLAG};
use crate::miniscript::types::extra_props::TimeLockInfo;
use crate::miniscript::types::extra_props::TimelockInfo;
use crate::{errstr, Error, ForEach, ForEachKey, MiniscriptKey};

/// Concrete policy which corresponds directly to a Miniscript structure,
Expand Down Expand Up @@ -94,7 +94,7 @@ pub enum PolicyError {
EntailmentMaxTerminals,
/// lifting error: Cannot lift policies that have
/// a combination of height and timelocks.
HeightTimeLockCombination,
HeightTimelockCombination,
/// Duplicate Public Keys
DuplicatePubKeys,
}
Expand Down Expand Up @@ -126,7 +126,7 @@ impl fmt::Display for PolicyError {
"Policy entailment only supports {} terminals",
ENTAILMENT_MAX_TERMINALS
),
PolicyError::HeightTimeLockCombination => {
PolicyError::HeightTimelockCombination => {
f.write_str("Cannot lift policies that have a heightlock and timelock combination")
}
PolicyError::DuplicatePubKeys => f.write_str("Policy contains duplicate keys"),
Expand Down Expand Up @@ -424,15 +424,15 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
pub fn check_timelocks(&self) -> Result<(), PolicyError> {
let timelocks = self.check_timelocks_helper();
if timelocks.contains_combination {
Err(PolicyError::HeightTimeLockCombination)
Err(PolicyError::HeightTimelockCombination)
} else {
Ok(())
}
}

// Checks whether the given concrete policy contains a combination of
// timelocks and heightlocks
fn check_timelocks_helper(&self) -> TimeLockInfo {
fn check_timelocks_helper(&self) -> TimelockInfo {
// timelocks[csv_h, csv_t, cltv_h, cltv_t, combination]
match *self {
Policy::Unsatisfiable
Expand All @@ -441,15 +441,15 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
| Policy::Sha256(_)
| Policy::Hash256(_)
| Policy::Ripemd160(_)
| Policy::Hash160(_) => TimeLockInfo::default(),
Policy::After(t) => TimeLockInfo {
| Policy::Hash160(_) => TimelockInfo::default(),
Policy::After(t) => TimelockInfo {
csv_with_height: false,
csv_with_time: false,
cltv_with_height: t < LOCKTIME_THRESHOLD,
cltv_with_time: t >= LOCKTIME_THRESHOLD,
contains_combination: false,
},
Policy::Older(t) => TimeLockInfo {
Policy::Older(t) => TimelockInfo {
csv_with_height: (t & SEQUENCE_LOCKTIME_TYPE_FLAG) == 0,
csv_with_time: (t & SEQUENCE_LOCKTIME_TYPE_FLAG) != 0,
cltv_with_height: false,
Expand All @@ -458,17 +458,17 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
},
Policy::Threshold(k, ref subs) => {
let iter = subs.iter().map(|sub| sub.check_timelocks_helper());
TimeLockInfo::combine_threshold(k, iter)
TimelockInfo::combine_threshold(k, iter)
}
Policy::And(ref subs) => {
let iter = subs.iter().map(|sub| sub.check_timelocks_helper());
TimeLockInfo::combine_threshold(subs.len(), iter)
TimelockInfo::combine_threshold(subs.len(), iter)
}
Policy::Or(ref subs) => {
let iter = subs
.iter()
.map(|&(ref _p, ref sub)| sub.check_timelocks_helper());
TimeLockInfo::combine_threshold(1, iter)
TimelockInfo::combine_threshold(1, iter)
}
}
}
Expand Down

0 comments on commit a36f608

Please sign in to comment.