Skip to content

Commit 4990215

Browse files
committed
Rename soonest_conf_deadline to counterparty_spendable_height
This renames the field in `PackageTemplate` which describes the height at which a counterparty can make a claim to an output to match its actual use. Previously it had been set based on when a counterparty can claim an output but also used for other purposes. In the previous commit we cleaned up its use for fee-bumping-rate, so here we can rename it as it is now only used as the `counteraprty_spendable_height`.
1 parent 0d4cea6 commit 4990215

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

lightning/src/chain/package.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -735,10 +735,11 @@ pub struct PackageTemplate {
735735
// Untractable packages have been counter-signed and thus imply that we can't aggregate
736736
// them without breaking signatures. Fee-bumping strategy will also rely on CPFP.
737737
malleability: PackageMalleability,
738-
// Block height after which the earlier-output belonging to this package is mature for a
739-
// competing claim by the counterparty. As our chain tip becomes nearer from the timelock,
740-
// the fee-bumping frequency will increase. See `OnchainTxHandler::get_height_timer`.
741-
soonest_conf_deadline: u32,
738+
// Block height at which our counterparty can potentially claim this output as well (assuming
739+
// they have the keys or information required to do so).
740+
// For HTLCs we're claiming with a preimage and revoked outputs, we need to get our spend
741+
// on-chain before this height.
742+
counterparty_spendable_height: u32,
742743
// Determines if this package can be aggregated.
743744
// Timelocked outputs belonging to the same transaction might have differing
744745
// satisfying heights. Picking up the later height among the output set would be a valid
@@ -767,7 +768,7 @@ impl PackageTemplate {
767768
/// This is an important limit for aggregation as after this height our counterparty may be
768769
/// able to pin transactions spending this output in the mempool.
769770
pub(crate) fn counterparty_spendable_height(&self) -> u32 {
770-
self.soonest_conf_deadline
771+
self.counterparty_spendable_height
771772
}
772773
pub(crate) fn aggregable(&self) -> bool {
773774
self.aggregable
@@ -794,7 +795,6 @@ impl PackageTemplate {
794795
match self.malleability {
795796
PackageMalleability::Malleable => {
796797
let mut split_package = None;
797-
let timelock = self.soonest_conf_deadline;
798798
let aggregable = self.aggregable;
799799
let feerate_previous = self.feerate_previous;
800800
let height_timer = self.height_timer;
@@ -803,7 +803,7 @@ impl PackageTemplate {
803803
split_package = Some(PackageTemplate {
804804
inputs: vec![(outp.0, outp.1.clone())],
805805
malleability: PackageMalleability::Malleable,
806-
soonest_conf_deadline: timelock,
806+
counterparty_spendable_height: self.counterparty_spendable_height,
807807
aggregable,
808808
feerate_previous,
809809
height_timer,
@@ -840,8 +840,8 @@ impl PackageTemplate {
840840
self.inputs.push((k, v));
841841
}
842842
//TODO: verify coverage and sanity?
843-
if self.soonest_conf_deadline > merge_from.soonest_conf_deadline {
844-
self.soonest_conf_deadline = merge_from.soonest_conf_deadline;
843+
if self.counterparty_spendable_height > merge_from.counterparty_spendable_height {
844+
self.counterparty_spendable_height = merge_from.counterparty_spendable_height;
845845
}
846846
if self.feerate_previous > merge_from.feerate_previous {
847847
self.feerate_previous = merge_from.feerate_previous;
@@ -975,10 +975,10 @@ impl PackageTemplate {
975975
match input {
976976
PackageSolvingData::RevokedOutput(_) => {
977977
// Revoked Outputs will become spendable by our counterparty at the height
978-
// where the CSV expires, which is also our `soonest_conf_deadline`.
978+
// where the CSV expires, which is also our `counterparty_spendable_height`.
979979
height_timer = cmp::min(
980980
height_timer,
981-
timer_for_target_conf(self.soonest_conf_deadline),
981+
timer_for_target_conf(self.counterparty_spendable_height),
982982
);
983983
},
984984
PackageSolvingData::RevokedHTLCOutput(_) => {
@@ -999,10 +999,10 @@ impl PackageTemplate {
999999
PackageSolvingData::HolderHTLCOutput(outp) if outp.preimage.is_some() => {
10001000
// We have the same deadline here as for `CounterpartyOfferedHTLCOutput`. Note
10011001
// that `outp.cltv_expiry` is always 0 in this case, but
1002-
// `soonest_conf_deadline` holds the real HTLC expiry.
1002+
// `counterparty_spendable_height` holds the real HTLC expiry.
10031003
height_timer = cmp::min(
10041004
height_timer,
1005-
timer_for_target_conf(self.soonest_conf_deadline),
1005+
timer_for_target_conf(self.counterparty_spendable_height),
10061006
);
10071007
},
10081008
PackageSolvingData::CounterpartyReceivedHTLCOutput(outp) => {
@@ -1104,13 +1104,13 @@ impl PackageTemplate {
11041104
}).is_some()
11051105
}
11061106

1107-
pub (crate) fn build_package(txid: Txid, vout: u32, input_solving_data: PackageSolvingData, soonest_conf_deadline: u32) -> Self {
1107+
pub (crate) fn build_package(txid: Txid, vout: u32, input_solving_data: PackageSolvingData, counterparty_spendable_height: u32) -> Self {
11081108
let (malleability, aggregable) = PackageSolvingData::map_output_type_flags(&input_solving_data);
11091109
let inputs = vec![(BitcoinOutPoint { txid, vout }, input_solving_data)];
11101110
PackageTemplate {
11111111
inputs,
11121112
malleability,
1113-
soonest_conf_deadline,
1113+
counterparty_spendable_height,
11141114
aggregable,
11151115
feerate_previous: 0,
11161116
height_timer: 0,
@@ -1126,7 +1126,7 @@ impl Writeable for PackageTemplate {
11261126
rev_outp.write(writer)?;
11271127
}
11281128
write_tlv_fields!(writer, {
1129-
(0, self.soonest_conf_deadline, required),
1129+
(0, self.counterparty_spendable_height, required),
11301130
(2, self.feerate_previous, required),
11311131
// Prior to 0.1, the height at which the package's inputs were mined, but was always unused
11321132
(4, 0u32, required),
@@ -1148,20 +1148,20 @@ impl Readable for PackageTemplate {
11481148
let (malleability, aggregable) = if let Some((_, lead_input)) = inputs.first() {
11491149
PackageSolvingData::map_output_type_flags(&lead_input)
11501150
} else { return Err(DecodeError::InvalidValue); };
1151-
let mut soonest_conf_deadline = 0;
1151+
let mut counterparty_spendable_height = 0;
11521152
let mut feerate_previous = 0;
11531153
let mut height_timer = None;
11541154
let mut _height_original: Option<u32> = None;
11551155
read_tlv_fields!(reader, {
1156-
(0, soonest_conf_deadline, required),
1156+
(0, counterparty_spendable_height, required),
11571157
(4, _height_original, option), // Written with a dummy value since 0.1
11581158
(2, feerate_previous, required),
11591159
(6, height_timer, option),
11601160
});
11611161
Ok(PackageTemplate {
11621162
inputs,
11631163
malleability,
1164-
soonest_conf_deadline,
1164+
counterparty_spendable_height,
11651165
aggregable,
11661166
feerate_previous,
11671167
height_timer: height_timer.unwrap_or(0),
@@ -1425,7 +1425,7 @@ mod tests {
14251425
if let Some(split_package) = package_one.split_package(&BitcoinOutPoint { txid, vout: 1 }) {
14261426
// Packages attributes should be identical
14271427
assert!(split_package.is_malleable());
1428-
assert_eq!(split_package.soonest_conf_deadline, package_one.soonest_conf_deadline);
1428+
assert_eq!(split_package.counterparty_spendable_height, package_one.counterparty_spendable_height);
14291429
assert_eq!(split_package.aggregable, package_one.aggregable);
14301430
assert_eq!(split_package.feerate_previous, package_one.feerate_previous);
14311431
assert_eq!(split_package.height_timer, package_one.height_timer);

0 commit comments

Comments
 (0)