-
Notifications
You must be signed in to change notification settings - Fork 154
Closed
Description
We currently use age/height as identifiers for values related to CLTV and CSV. However we get them mixed up in the at_age
/at_height
functions. I do not know if this is intentional, an accidental mixup that is not a problem, or a bug. In finalize.rs
we have:
let cltv = psbt.unsigned_tx.lock_time;
let csv = psbt.unsigned_tx.input[index].sequence;
let interpreter =
interpreter::Interpreter::from_txdata(spk, script_sig, witness, cltv, csv)
.map_err(|e| Error::InputError(InputError::Interpreter(e), index))?;
And in from_txdata
we have
pub fn from_txdata(
spk: &bitcoin::Script,
script_sig: &'txin bitcoin::Script,
witness: &'txin Witness,
age: u32,
height: u32,
) -> Result<Self, Error> {
Note cltv
is passed as age
and csv
is passed as height
. In the following functions they are the opposite
/// Filter a policy by eliminating relative timelock constraints
/// that are not satisfied at the given age.
pub fn at_age(mut self, time: u32) -> Policy<Pk> {
self = match self {
Policy::Older(t) => {
if t > time {
Policy::Unsatisfiable
} else {
Policy::Older(t)
}
}
Policy::Threshold(k, subs) => {
Policy::Threshold(k, subs.into_iter().map(|sub| sub.at_age(time)).collect())
}
x => x,
};
self.normalized()
}
/// Filter a policy by eliminating absolute timelock constraints
/// that are not satisfied at the given age.
pub fn at_height(mut self, time: u32) -> Policy<Pk> {
self = match self {
Policy::After(t) => {
if !timelock::absolute_timelocks_are_same_unit(t, time) {
Policy::Unsatisfiable
} else if t > time {
Policy::Unsatisfiable
} else {
Policy::After(t)
}
}
Policy::Threshold(k, subs) => {
Policy::Threshold(k, subs.into_iter().map(|sub| sub.at_height(time)).collect())
}
x => x,
};
self.normalized()
}
Metadata
Metadata
Assignees
Labels
No labels