Skip to content

Commit 63e8f1c

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

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

lightning/src/chain/package.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,14 +1249,11 @@ impl PackageTemplate {
12491249
// MUST be true, otherwise we are aggregating V2 tx claims with V3 tx claims
12501250
debug_assert!(self.inputs.iter().all(|(_, solving_data)| matches!(solving_data, PackageSolvingData::HolderHTLCOutput(_) )));
12511251
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 {
1252+
// We aggregate max 25 holder HTLC outputs together to avoid hitting the max 10_000vB cap on TRUC singletons.
1253+
// Note we do not currently aggregate these with the anchor transaction that fee-bumps the 0-fee commitment transaction.
1254+
// Back-of-the-envelope, this lands us at max HTLC_SUCCESS_TX_WEIGHT.to_vbytes_ceil() * 25 ~= 4500 vB.
1255+
// You really have to try hard to provide a single 5_000vB input-output pair to fee-bump a 25-HTLC package.
1256+
if self.inputs.len() + other.inputs.len() <= 25 {
12601257
return true;
12611258
}
12621259
} 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)