Skip to content

Commit bb7b9c8

Browse files
committed
f - include output weights
1 parent 1830a7a commit bb7b9c8

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
@@ -5889,6 +5889,7 @@ fn check_splice_contribution_sufficient(
58895889
is_initiator,
58905890
1, // spends the previous funding output
58915891
Weight::from_wu(FUNDING_TRANSACTION_WITNESS_WEIGHT),
5892+
contribution.outputs(),
58925893
funding_feerate.to_sat_per_kwu() as u32,
58935894
));
58945895

@@ -5918,14 +5919,12 @@ fn check_splice_contribution_sufficient(
59185919
#[allow(dead_code)] // TODO(dual_funding): TODO(splicing): Remove allow once used.
59195920
#[rustfmt::skip]
59205921
fn estimate_v2_funding_transaction_fee(
5921-
is_initiator: bool, input_count: usize, witness_weight: Weight,
5922+
is_initiator: bool, input_count: usize, witness_weight: Weight, outputs: &[TxOut],
59225923
funding_feerate_sat_per_1000_weight: u32,
59235924
) -> u64 {
5924-
// Inputs
59255925
let mut weight = (input_count as u64) * BASE_INPUT_WEIGHT;
5926-
5927-
// Witnesses
59285926
weight = weight.saturating_add(witness_weight.to_wu());
5927+
weight = weight.saturating_add(outputs.iter().map(|txout| txout.weight().to_wu()).sum());
59295928

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

59675966
let mut total_input_sats = 0u64;
59685967
for (idx, FundingTxInput { txin, prevtx, .. }) in funding_inputs.iter().enumerate() {
@@ -15949,31 +15948,31 @@ mod tests {
1594915948

1595015949
// 2 inputs with weight 300, initiator, 2000 sat/kw feerate
1595115950
assert_eq!(
15952-
estimate_v2_funding_transaction_fee(true, 2, Weight::from_wu(300), 2000),
15951+
estimate_v2_funding_transaction_fee(true, 2, Weight::from_wu(300), &[], 2000),
1595315952
1668
1595415953
);
1595515954

1595615955
// higher feerate
1595715956
assert_eq!(
15958-
estimate_v2_funding_transaction_fee(true, 2, Weight::from_wu(300), 3000),
15957+
estimate_v2_funding_transaction_fee(true, 2, Weight::from_wu(300), &[], 3000),
1595915958
2502
1596015959
);
1596115960

1596215961
// only 1 input
1596315962
assert_eq!(
15964-
estimate_v2_funding_transaction_fee(true, 1, Weight::from_wu(300), 2000),
15963+
estimate_v2_funding_transaction_fee(true, 1, Weight::from_wu(300), &[], 2000),
1596515964
1348
1596615965
);
1596715966

1596815967
// 0 input weight
1596915968
assert_eq!(
15970-
estimate_v2_funding_transaction_fee(true, 1, Weight::from_wu(0), 2000),
15969+
estimate_v2_funding_transaction_fee(true, 1, Weight::from_wu(0), &[], 2000),
1597115970
748
1597215971
);
1597315972

1597415973
// not initiator
1597515974
assert_eq!(
15976-
estimate_v2_funding_transaction_fee(false, 1, Weight::from_wu(0), 2000),
15975+
estimate_v2_funding_transaction_fee(false, 1, Weight::from_wu(0), &[], 2000),
1597715976
320
1597815977
);
1597915978
}

0 commit comments

Comments
 (0)