@@ -4706,11 +4706,13 @@ fn check_v2_funding_inputs_sufficient(
47064706 is_splice: bool, funding_feerate_sat_per_1000_weight: u32,
47074707) -> Result<u64, ChannelError> {
47084708 let mut total_input_witness_weight = Weight::from_wu(funding_inputs.iter().map(|(_, _, w)| w.to_wu()).sum());
4709+ let mut funding_inputs_len = funding_inputs.len();
47094710 if is_initiator && is_splice {
4710- // consider the weight of the witness needed for spending the old funding transaction
4711+ // consider the weight of the input and witness needed for spending the old funding transaction
4712+ funding_inputs_len += 1;
47114713 total_input_witness_weight += Weight::from_wu(FUNDING_TRANSACTION_WITNESS_WEIGHT);
47124714 }
4713- let estimated_fee = estimate_v2_funding_transaction_fee(is_initiator, funding_inputs.len() , total_input_witness_weight, funding_feerate_sat_per_1000_weight);
4715+ let estimated_fee = estimate_v2_funding_transaction_fee(is_initiator, funding_inputs_len , total_input_witness_weight, funding_feerate_sat_per_1000_weight);
47144716
47154717 let mut total_input_sats = 0u64;
47164718 for (idx, input) in funding_inputs.iter().enumerate() {
@@ -12953,7 +12955,7 @@ mod tests {
1295312955 true,
1295412956 2000,
1295512957 ).unwrap(),
12956- 1948 ,
12958+ 2268 ,
1295712959 );
1295812960
1295912961 // negative case, inputs clearly insufficient
@@ -12969,13 +12971,13 @@ mod tests {
1296912971 );
1297012972 assert_eq!(
1297112973 format!("{:?}", res.err().unwrap()),
12972- "Warn: Total input amount 100000 is lower than needed for contribution 220000, considering fees of 1410 . Need more inputs.",
12974+ "Warn: Total input amount 100000 is lower than needed for contribution 220000, considering fees of 1730 . Need more inputs.",
1297312975 );
1297412976 }
1297512977
1297612978 // barely covers
1297712979 {
12978- let expected_fee: u64 = 1948 ;
12980+ let expected_fee: u64 = 2268 ;
1297912981 assert_eq!(
1298012982 check_v2_funding_inputs_sufficient(
1298112983 (300_000 - expected_fee - 20) as i64,
@@ -13005,7 +13007,7 @@ mod tests {
1300513007 );
1300613008 assert_eq!(
1300713009 format!("{:?}", res.err().unwrap()),
13008- "Warn: Total input amount 300000 is lower than needed for contribution 298032, considering fees of 2143 . Need more inputs.",
13010+ "Warn: Total input amount 300000 is lower than needed for contribution 298032, considering fees of 2495 . Need more inputs.",
1300913011 );
1301013012 }
1301113013
0 commit comments