Skip to content

Commit e8dd4b6

Browse files
committed
f - include output weights
1 parent 59fbd7e commit e8dd4b6

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

lightning/src/ln/channel.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5890,6 +5890,7 @@ fn check_splice_contribution_sufficient(
58905890
is_initiator,
58915891
1, // spends the previous funding output
58925892
Weight::from_wu(FUNDING_TRANSACTION_WITNESS_WEIGHT),
5893+
contribution.outputs(),
58935894
funding_feerate.to_sat_per_kwu() as u32,
58945895
));
58955896

@@ -5919,14 +5920,12 @@ fn check_splice_contribution_sufficient(
59195920
#[allow(dead_code)] // TODO(dual_funding): TODO(splicing): Remove allow once used.
59205921
#[rustfmt::skip]
59215922
fn estimate_v2_funding_transaction_fee(
5922-
is_initiator: bool, input_count: usize, witness_weight: Weight,
5923+
is_initiator: bool, input_count: usize, witness_weight: Weight, outputs: &[TxOut],
59235924
funding_feerate_sat_per_1000_weight: u32,
59245925
) -> u64 {
5925-
// Inputs
59265926
let mut weight = (input_count as u64) * BASE_INPUT_WEIGHT;
5927-
5928-
// Witnesses
59295927
weight = weight.saturating_add(witness_weight.to_wu());
5928+
weight = weight.saturating_add(outputs.iter().map(|txout| txout.weight().to_wu()).sum());
59305929

59315930
// If we are the initiator, we must pay for weight of all common fields in the funding transaction.
59325931
if is_initiator {
@@ -5963,7 +5962,7 @@ fn check_v2_funding_inputs_sufficient(
59635962
funding_inputs_len += 1;
59645963
total_input_witness_weight += Weight::from_wu(FUNDING_TRANSACTION_WITNESS_WEIGHT);
59655964
}
5966-
let estimated_fee = estimate_v2_funding_transaction_fee(is_initiator, funding_inputs_len, total_input_witness_weight, funding_feerate_sat_per_1000_weight);
5965+
let estimated_fee = estimate_v2_funding_transaction_fee(is_initiator, funding_inputs_len, total_input_witness_weight, &[], funding_feerate_sat_per_1000_weight);
59675966

59685967
let mut total_input_sats = 0u64;
59695968
for (idx, FundingTxInput { txin, prevtx, .. }) in funding_inputs.iter().enumerate() {
@@ -15952,31 +15951,31 @@ mod tests {
1595215951

1595315952
// 2 inputs with weight 300, initiator, 2000 sat/kw feerate
1595415953
assert_eq!(
15955-
estimate_v2_funding_transaction_fee(true, 2, Weight::from_wu(300), 2000),
15954+
estimate_v2_funding_transaction_fee(true, 2, Weight::from_wu(300), &[], 2000),
1595615955
1668
1595715956
);
1595815957

1595915958
// higher feerate
1596015959
assert_eq!(
15961-
estimate_v2_funding_transaction_fee(true, 2, Weight::from_wu(300), 3000),
15960+
estimate_v2_funding_transaction_fee(true, 2, Weight::from_wu(300), &[], 3000),
1596215961
2502
1596315962
);
1596415963

1596515964
// only 1 input
1596615965
assert_eq!(
15967-
estimate_v2_funding_transaction_fee(true, 1, Weight::from_wu(300), 2000),
15966+
estimate_v2_funding_transaction_fee(true, 1, Weight::from_wu(300), &[], 2000),
1596815967
1348
1596915968
);
1597015969

1597115970
// 0 input weight
1597215971
assert_eq!(
15973-
estimate_v2_funding_transaction_fee(true, 1, Weight::from_wu(0), 2000),
15972+
estimate_v2_funding_transaction_fee(true, 1, Weight::from_wu(0), &[], 2000),
1597415973
748
1597515974
);
1597615975

1597715976
// not initiator
1597815977
assert_eq!(
15979-
estimate_v2_funding_transaction_fee(false, 1, Weight::from_wu(0), 2000),
15978+
estimate_v2_funding_transaction_fee(false, 1, Weight::from_wu(0), &[], 2000),
1598015979
320
1598115980
);
1598215981
}

0 commit comments

Comments
 (0)