Skip to content

Commit d557334

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 be91587 commit d557334

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

lightning/src/chain/package.rs

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -731,10 +731,14 @@ pub struct PackageTemplate {
731731
// Untractable packages have been counter-signed and thus imply that we can't aggregate
732732
// them without breaking signatures. Fee-bumping strategy will also rely on CPFP.
733733
malleability: PackageMalleability,
734-
// Block height after which the earlier-output belonging to this package is mature for a
735-
// competing claim by the counterparty. As our chain tip becomes nearer from the timelock,
736-
// the fee-bumping frequency will increase. See `OnchainTxHandler::get_height_timer`.
737-
soonest_conf_deadline: u32,
734+
/// Block height at which our counterparty can potentially claim this output as well (assuming
735+
/// they have the keys or information required to do so).
736+
///
737+
/// This is used primarily by external consumers to decide when an output becomes "pinnable"
738+
/// because the counterparty can potentially spend it. It is also used internally by
739+
/// [`Self::get_height_timer`] to identify when an output must be claimed by, depending on the
740+
/// type of output.
741+
counterparty_spendable_height: u32,
738742
// Determines if this package can be aggregated.
739743
// Timelocked outputs belonging to the same transaction might have differing
740744
// satisfying heights. Picking up the later height among the output set would be a valid
@@ -763,7 +767,7 @@ impl PackageTemplate {
763767
/// This is an important limit for aggregation as after this height our counterparty may be
764768
/// able to pin transactions spending this output in the mempool.
765769
pub(crate) fn counterparty_spendable_height(&self) -> u32 {
766-
self.soonest_conf_deadline
770+
self.counterparty_spendable_height
767771
}
768772
pub(crate) fn aggregable(&self) -> bool {
769773
self.aggregable
@@ -790,7 +794,6 @@ impl PackageTemplate {
790794
match self.malleability {
791795
PackageMalleability::Malleable => {
792796
let mut split_package = None;
793-
let timelock = self.soonest_conf_deadline;
794797
let aggregable = self.aggregable;
795798
let feerate_previous = self.feerate_previous;
796799
let height_timer = self.height_timer;
@@ -799,7 +802,7 @@ impl PackageTemplate {
799802
split_package = Some(PackageTemplate {
800803
inputs: vec![(outp.0, outp.1.clone())],
801804
malleability: PackageMalleability::Malleable,
802-
soonest_conf_deadline: timelock,
805+
counterparty_spendable_height: self.counterparty_spendable_height,
803806
aggregable,
804807
feerate_previous,
805808
height_timer,
@@ -836,8 +839,8 @@ impl PackageTemplate {
836839
self.inputs.push((k, v));
837840
}
838841
//TODO: verify coverage and sanity?
839-
if self.soonest_conf_deadline > merge_from.soonest_conf_deadline {
840-
self.soonest_conf_deadline = merge_from.soonest_conf_deadline;
842+
if self.counterparty_spendable_height > merge_from.counterparty_spendable_height {
843+
self.counterparty_spendable_height = merge_from.counterparty_spendable_height;
841844
}
842845
if self.feerate_previous > merge_from.feerate_previous {
843846
self.feerate_previous = merge_from.feerate_previous;
@@ -971,10 +974,10 @@ impl PackageTemplate {
971974
match input {
972975
PackageSolvingData::RevokedOutput(_) => {
973976
// Revoked Outputs will become spendable by our counterparty at the height
974-
// where the CSV expires, which is also our `soonest_conf_deadline`.
977+
// where the CSV expires, which is also our `counterparty_spendable_height`.
975978
height_timer = cmp::min(
976979
height_timer,
977-
timer_for_target_conf(self.soonest_conf_deadline),
980+
timer_for_target_conf(self.counterparty_spendable_height),
978981
);
979982
},
980983
PackageSolvingData::RevokedHTLCOutput(_) => {
@@ -995,10 +998,10 @@ impl PackageTemplate {
995998
PackageSolvingData::HolderHTLCOutput(outp) if outp.preimage.is_some() => {
996999
// We have the same deadline here as for `CounterpartyOfferedHTLCOutput`. Note
9971000
// that `outp.cltv_expiry` is always 0 in this case, but
998-
// `soonest_conf_deadline` holds the real HTLC expiry.
1001+
// `counterparty_spendable_height` holds the real HTLC expiry.
9991002
height_timer = cmp::min(
10001003
height_timer,
1001-
timer_for_target_conf(self.soonest_conf_deadline),
1004+
timer_for_target_conf(self.counterparty_spendable_height),
10021005
);
10031006
},
10041007
PackageSolvingData::CounterpartyReceivedHTLCOutput(outp) => {
@@ -1100,13 +1103,13 @@ impl PackageTemplate {
11001103
}).is_some()
11011104
}
11021105

1103-
pub (crate) fn build_package(txid: Txid, vout: u32, input_solving_data: PackageSolvingData, soonest_conf_deadline: u32) -> Self {
1106+
pub (crate) fn build_package(txid: Txid, vout: u32, input_solving_data: PackageSolvingData, counterparty_spendable_height: u32) -> Self {
11041107
let (malleability, aggregable) = PackageSolvingData::map_output_type_flags(&input_solving_data);
11051108
let inputs = vec![(BitcoinOutPoint { txid, vout }, input_solving_data)];
11061109
PackageTemplate {
11071110
inputs,
11081111
malleability,
1109-
soonest_conf_deadline,
1112+
counterparty_spendable_height,
11101113
aggregable,
11111114
feerate_previous: 0,
11121115
height_timer: 0,
@@ -1122,7 +1125,7 @@ impl Writeable for PackageTemplate {
11221125
rev_outp.write(writer)?;
11231126
}
11241127
write_tlv_fields!(writer, {
1125-
(0, self.soonest_conf_deadline, required),
1128+
(0, self.counterparty_spendable_height, required),
11261129
(2, self.feerate_previous, required),
11271130
// Prior to 0.1, the height at which the package's inputs were mined, but was always unused
11281131
(4, 0u32, required),
@@ -1144,20 +1147,20 @@ impl Readable for PackageTemplate {
11441147
let (malleability, aggregable) = if let Some((_, lead_input)) = inputs.first() {
11451148
PackageSolvingData::map_output_type_flags(&lead_input)
11461149
} else { return Err(DecodeError::InvalidValue); };
1147-
let mut soonest_conf_deadline = 0;
1150+
let mut counterparty_spendable_height = 0;
11481151
let mut feerate_previous = 0;
11491152
let mut height_timer = None;
11501153
let mut _height_original: Option<u32> = None;
11511154
read_tlv_fields!(reader, {
1152-
(0, soonest_conf_deadline, required),
1155+
(0, counterparty_spendable_height, required),
11531156
(2, feerate_previous, required),
11541157
(4, _height_original, option), // Written with a dummy value since 0.1
11551158
(6, height_timer, option),
11561159
});
11571160
Ok(PackageTemplate {
11581161
inputs,
11591162
malleability,
1160-
soonest_conf_deadline,
1163+
counterparty_spendable_height,
11611164
aggregable,
11621165
feerate_previous,
11631166
height_timer: height_timer.unwrap_or(0),
@@ -1421,7 +1424,7 @@ mod tests {
14211424
if let Some(split_package) = package_one.split_package(&BitcoinOutPoint { txid, vout: 1 }) {
14221425
// Packages attributes should be identical
14231426
assert!(split_package.is_malleable());
1424-
assert_eq!(split_package.soonest_conf_deadline, package_one.soonest_conf_deadline);
1427+
assert_eq!(split_package.counterparty_spendable_height, package_one.counterparty_spendable_height);
14251428
assert_eq!(split_package.aggregable, package_one.aggregable);
14261429
assert_eq!(split_package.feerate_previous, package_one.feerate_previous);
14271430
assert_eq!(split_package.height_timer, package_one.height_timer);

0 commit comments

Comments
 (0)