Skip to content

Commit 5f5c275

Browse files
committed
Correct ANCHOR_INPUT_WITNESS_WEIGHT constant
`ANCHOR_INPUT_WITNESS_WEIGHT` is too high by two weight units, likely it was calculated to include the SegWit marker bytes, but it is used to describe an `Input::satisfaction_weight`, which does not expect the marker bytes. This corrects that oversight, reducing the constant by two and adding the marker bytes back in our own internal weight calculations. It also fixes a second issue where the constant was too low by one when `grind_signatures` is not set, as that may result in a signature being one byte longer than we expect.
1 parent 5a2372c commit 5f5c275

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

lightning/src/events/bump_transaction.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ where
670670

671671
let package_fee = total_input_amount -
672672
anchor_psbt.unsigned_tx.output.iter().map(|output| output.value).sum();
673-
let package_weight = unsigned_tx_weight + total_satisfaction_weight + commitment_tx.weight().to_wu();
673+
let package_weight = unsigned_tx_weight + 2 /* wit marker */ + total_satisfaction_weight + commitment_tx.weight().to_wu();
674674
if package_fee.to_sat() * 1000 / package_weight < package_target_feerate_sat_per_1000_weight.into() {
675675
// On the first iteration of the loop, we may undershoot the target feerate because
676676
// we had to add an OP_RETURN output in `process_coin_selection` which we didn't
@@ -695,7 +695,7 @@ where
695695

696696
#[cfg(debug_assertions)] {
697697
let signed_tx_weight = anchor_tx.weight().to_wu();
698-
let expected_signed_tx_weight = unsigned_tx_weight + total_satisfaction_weight;
698+
let expected_signed_tx_weight = unsigned_tx_weight + 2 /* wit marker */ + total_satisfaction_weight;
699699
// Our estimate should be within a 1% error margin of the actual weight and we should
700700
// never underestimate.
701701
assert!(expected_signed_tx_weight >= signed_tx_weight &&

lightning/src/ln/chan_utils.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ pub(crate) const MIN_ACCEPTED_HTLC_SCRIPT_WEIGHT: usize = 136;
6868
pub const MAX_ACCEPTED_HTLC_SCRIPT_WEIGHT: usize = 143;
6969

7070
/// The upper bound weight of an anchor input.
71-
pub const ANCHOR_INPUT_WITNESS_WEIGHT: u64 = 116;
71+
#[cfg(feature = "grind_signatures")]
72+
pub const ANCHOR_INPUT_WITNESS_WEIGHT: u64 = 114;
73+
/// The upper bound weight of an anchor input.
74+
#[cfg(not(feature = "grind_signatures"))]
75+
pub const ANCHOR_INPUT_WITNESS_WEIGHT: u64 = 115;
76+
7277
/// The upper bound weight of an HTLC timeout input from a commitment transaction with anchor
7378
/// outputs.
7479
pub const HTLC_TIMEOUT_INPUT_ANCHOR_WITNESS_WEIGHT: u64 = 288;

0 commit comments

Comments
 (0)