@@ -5889,6 +5889,7 @@ fn check_splice_contribution_sufficient(
5889
5889
is_initiator,
5890
5890
1, // spends the previous funding output
5891
5891
Weight::from_wu(FUNDING_TRANSACTION_WITNESS_WEIGHT),
5892
+ contribution.outputs(),
5892
5893
funding_feerate.to_sat_per_kwu() as u32,
5893
5894
));
5894
5895
@@ -5918,14 +5919,12 @@ fn check_splice_contribution_sufficient(
5918
5919
#[allow(dead_code)] // TODO(dual_funding): TODO(splicing): Remove allow once used.
5919
5920
#[rustfmt::skip]
5920
5921
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],
5922
5923
funding_feerate_sat_per_1000_weight: u32,
5923
5924
) -> u64 {
5924
- // Inputs
5925
5925
let mut weight = (input_count as u64) * BASE_INPUT_WEIGHT;
5926
-
5927
- // Witnesses
5928
5926
weight = weight.saturating_add(witness_weight.to_wu());
5927
+ weight = weight.saturating_add(outputs.iter().map(|txout| txout.weight().to_wu()).sum());
5929
5928
5930
5929
// If we are the initiator, we must pay for weight of all common fields in the funding transaction.
5931
5930
if is_initiator {
@@ -5962,7 +5961,7 @@ fn check_v2_funding_inputs_sufficient(
5962
5961
funding_inputs_len += 1;
5963
5962
total_input_witness_weight += Weight::from_wu(FUNDING_TRANSACTION_WITNESS_WEIGHT);
5964
5963
}
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);
5966
5965
5967
5966
let mut total_input_sats = 0u64;
5968
5967
for (idx, FundingTxInput { txin, prevtx, .. }) in funding_inputs.iter().enumerate() {
@@ -15949,31 +15948,31 @@ mod tests {
15949
15948
15950
15949
// 2 inputs with weight 300, initiator, 2000 sat/kw feerate
15951
15950
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),
15953
15952
1668
15954
15953
);
15955
15954
15956
15955
// higher feerate
15957
15956
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),
15959
15958
2502
15960
15959
);
15961
15960
15962
15961
// only 1 input
15963
15962
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),
15965
15964
1348
15966
15965
);
15967
15966
15968
15967
// 0 input weight
15969
15968
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),
15971
15970
748
15972
15971
);
15973
15972
15974
15973
// not initiator
15975
15974
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),
15977
15976
320
15978
15977
);
15979
15978
}
0 commit comments