Skip to content

Commit 9bd87e9

Browse files
committed
Expose the timelock of transaction packages
1 parent 7d6938a commit 9bd87e9

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

lightning/src/chain/package.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,21 @@ impl PackageSolvingData {
387387
_ => { panic!("API Error!"); }
388388
}
389389
}
390+
fn absolute_tx_timelock(&self, output_conf_height: u32) -> u32 {
391+
// Get the absolute timelock at which this output can be spent given the height at which
392+
// this output was confirmed. We use `output_conf_height + 1` as a safe default as we can
393+
// be confirmed in the next block and transactions with time lock `current_height + 1`
394+
// always propagate.
395+
let absolute_timelock = match self {
396+
PackageSolvingData::RevokedOutput(_) => output_conf_height + 1,
397+
PackageSolvingData::RevokedHTLCOutput(_) => output_conf_height + 1,
398+
PackageSolvingData::CounterpartyOfferedHTLCOutput(_) => output_conf_height + 1,
399+
PackageSolvingData::CounterpartyReceivedHTLCOutput(ref outp) => std::cmp::max(outp.htlc.cltv_expiry, output_conf_height + 1),
400+
PackageSolvingData::HolderHTLCOutput(ref outp) => std::cmp::max(outp.cltv_expiry, output_conf_height + 1),
401+
PackageSolvingData::HolderFundingOutput(_) => output_conf_height + 1,
402+
};
403+
absolute_timelock
404+
}
390405
}
391406

392407
impl Writeable for PackageSolvingData {
@@ -598,6 +613,10 @@ impl PackageTemplate {
598613
}
599614
amounts
600615
}
616+
pub(crate) fn package_timelock(&self) -> u32 {
617+
self.inputs.iter().map(|(_, outp)| outp.absolute_tx_timelock(self.height_original))
618+
.max().expect("There must always be at least one output to spend in a PackageTemplate")
619+
}
601620
pub(crate) fn package_weight(&self, destination_script: &Script) -> usize {
602621
let mut inputs_weight = 0;
603622
let mut witnesses_weight = 2; // count segwit flags

0 commit comments

Comments
 (0)