Skip to content

Commit 4b0af69

Browse files
committed
fixup: cap aggregation of HTLCs in anchors_zero_fee_htlc_tx channels at max standard tx weight
1 parent fb3adc3 commit 4b0af69

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

lightning/src/events/bump_transaction/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -875,9 +875,15 @@ where
875875
// Cap the size of transactions claiming `HolderHTLCOutput` in 0FC channels.
876876
// Otherwise, we could hit the max 10_000vB size limit on V3 transactions
877877
// (BIP 431 rule 4).
878-
chan_utils::TRUC_MAX_WEIGHT
878+
chan_utils::MAX_TRUC_WEIGHT
879879
} else {
880-
u64::MAX
880+
// We should never hit this because HTLC-timeout transactions have a signed
881+
// locktime, HTLC-success transactions do not, and we never aggregate
882+
// packages with a signed locktime with packages that do not have a signed
883+
// locktime.
884+
// Hence in the worst case, we aggregate 483 success HTLC transactions,
885+
// and 483 * 705 ~= 341_000, and 341_000 < 400_000.
886+
chan_utils::MAX_STANDARD_TX_WEIGHT
881887
};
882888
let mut broadcasted_htlcs = 0;
883889
let mut batch_size = htlc_descriptors.len() - broadcasted_htlcs;

lightning/src/ln/chan_utils.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,11 @@ pub const P2A_ANCHOR_INPUT_WITNESS_WEIGHT: u64 = 1;
9696
/// The maximum value of a P2A anchor.
9797
pub const P2A_MAX_VALUE: u64 = 240;
9898

99-
/// The maximum weight of a TRUC transaction.
100-
pub const TRUC_MAX_WEIGHT: u64 = 10_000 * WITNESS_SCALE_FACTOR as u64;
99+
/// The maximum weight of a TRUC transaction, see BIP431
100+
pub const MAX_TRUC_WEIGHT: u64 = 10_000 * WITNESS_SCALE_FACTOR as u64;
101+
102+
/// The maximum weight of any standard transaction, see bitcoin/src/policy/policy.h
103+
pub const MAX_STANDARD_TX_WEIGHT: u64 = 400_000;
101104

102105
/// The upper bound weight of an HTLC timeout input from a commitment transaction with keyed anchor outputs.
103106
pub const HTLC_TIMEOUT_INPUT_KEYED_ANCHOR_WITNESS_WEIGHT: u64 = 288;

0 commit comments

Comments
 (0)