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