Skip to content

Commit db273bb

Browse files
committed
[wip] Restrict aggregation to max 25 HolderHTLCOutput in 0FC chans
1 parent 0fb5ca6 commit db273bb

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

lightning/src/chain/package.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,9 +1183,6 @@ impl PartialEq for PackageTemplate {
11831183
}
11841184

11851185
impl PackageTemplate {
1186-
fn weight(&self) -> u64 {
1187-
self.inputs.iter().map(|(_, solving_data)| solving_data.weight()).sum::<usize>() as u64
1188-
}
11891186
#[rustfmt::skip]
11901187
pub(crate) fn can_merge_with(&self, other: &PackageTemplate, cur_height: u32, is_0fc_channel: bool) -> bool {
11911188
match (self.malleability, other.malleability) {
@@ -1249,14 +1246,11 @@ impl PackageTemplate {
12491246
// MUST be true, otherwise we are aggregating V2 tx claims with V3 tx claims
12501247
debug_assert!(self.inputs.iter().all(|(_, solving_data)| matches!(solving_data, PackageSolvingData::HolderHTLCOutput(_) )));
12511248
debug_assert!(other.inputs.iter().all(|(_, solving_data)| matches!(solving_data, PackageSolvingData::HolderHTLCOutput(_) )));
1252-
// See rust-bitcoin to_vbytes_ceil
1253-
let self_vbytes = (self.weight() + 3) / 4; // This is the weight of the witnesses alone, we need to add more here
1254-
let other_vbytes = (other.weight() + 3) / 4;
1255-
// What is a good offset to use here to leave room for the user-provided input-output pair?
1256-
// How much validation to do at coin-selection time in bump_transaction mod ?
1257-
// Just warn users in the docs not to use some really heavy witnesses to fee-bump their transactions?
1258-
// A 1-input-1-output p2wpkh-input p2wpkh-input transaction is 109.25vB.
1259-
if self_vbytes + other_vbytes < 10_000 - 200 {
1249+
// We aggregate max 25 holder HTLC outputs together to avoid hitting the max 10_000vB cap on TRUC singletons.
1250+
// Note we do not currently aggregate these with the anchor transaction that fee-bumps the 0-fee commitment transaction.
1251+
// Back-of-the-envelope, this lands us at max HTLC_SUCCESS_TX_WEIGHT.to_vbytes_ceil() * 25 ~= 4500 vB.
1252+
// You really have to try hard to provide a single 5_000vB input-output pair to fee-bump a 25-HTLC package.
1253+
if self.inputs.len() + other.inputs.len() <= 25 {
12601254
return true;
12611255
}
12621256
} else {

lightning/src/events/bump_transaction/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,15 @@ where
971971
assert!(signed_tx_fee >= expected_signed_tx_fee);
972972
}
973973

974+
// We'll read the 0FC bit from `&[HTLCDescriptor]` above once the testing PR lands
975+
if htlc_tx.vsize() > 10_000 {
976+
log_error!(
977+
self.logger,
978+
"0FC HTLC transaction is too big, make the input-output pair you provided smaller"
979+
);
980+
return Err(());
981+
}
982+
974983
log_info!(self.logger, "Broadcasting {}", log_tx!(htlc_tx));
975984
self.broadcaster.broadcast_transactions(&[&htlc_tx]);
976985
Ok(())

0 commit comments

Comments
 (0)