@@ -4473,7 +4473,7 @@ fn get_v2_channel_reserve_satoshis(channel_value_satoshis: u64, dust_limit_satos
44734473/// input_count: Number of contributed inputs.
44744474/// witness_weight: The witness weight for contributed inputs.
44754475#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
4476- fn estimate_funding_transaction_fee (
4476+ fn estimate_v2_funding_transaction_fee (
44774477 is_initiator: bool, input_count: usize, witness_weight: Weight,
44784478 funding_feerate_sat_per_1000_weight: u32,
44794479) -> u64 {
@@ -4504,7 +4504,7 @@ pub(super) fn calculate_our_funding_satoshis(
45044504 total_witness_weight: Weight, funding_feerate_sat_per_1000_weight: u32,
45054505 holder_dust_limit_satoshis: u64,
45064506) -> Result<u64, APIError> {
4507- let estimated_fee = estimate_funding_transaction_fee (is_initiator, funding_inputs.len(), total_witness_weight, funding_feerate_sat_per_1000_weight);
4507+ let estimated_fee = estimate_v2_funding_transaction_fee (is_initiator, funding_inputs.len(), total_witness_weight, funding_feerate_sat_per_1000_weight);
45084508
45094509 let mut total_input_satoshis = 0u64;
45104510 for (idx, input) in funding_inputs.iter().enumerate() {
@@ -12253,40 +12253,43 @@ mod tests {
1225312253 }
1225412254
1225512255 #[test]
12256- fn test_estimate_funding_transaction_fee () {
12257- use crate::ln::channel::estimate_funding_transaction_fee ;
12256+ fn test_estimate_fv2_unding_transaction_fee () {
12257+ use crate::ln::channel::estimate_v2_funding_transaction_fee ;
1225812258 use bitcoin::Weight;
1225912259
12260- let witness_weight = Weight::from_wu(300);
12261-
12260+ // 2 inputs with weight 300, initiator, 2000 sat/kw feerate
1226212261 assert_eq!(
12263- estimate_funding_transaction_fee (true, 2, witness_weight , 2000),
12262+ estimate_v2_funding_transaction_fee (true, 2, Weight::from_wu(300) , 2000),
1226412263 1668
1226512264 );
1226612265
12266+ // higher feerate
1226712267 assert_eq!(
12268- estimate_funding_transaction_fee (true, 2, witness_weight , 3000),
12268+ estimate_v2_funding_transaction_fee (true, 2, Weight::from_wu(300) , 3000),
1226912269 2502
1227012270 );
1227112271
12272+ // only 1 input
1227212273 assert_eq!(
12273- estimate_funding_transaction_fee (true, 1, witness_weight , 2000),
12274+ estimate_v2_funding_transaction_fee (true, 1, Weight::from_wu(300) , 2000),
1227412275 1348
1227512276 );
1227612277
12278+ // 0 input weight
1227712279 assert_eq!(
12278- estimate_funding_transaction_fee (true, 1, Weight::from_wu(0), 2000),
12280+ estimate_v2_funding_transaction_fee (true, 1, Weight::from_wu(0), 2000),
1227912281 748
1228012282 );
1228112283
12284+ // not initiator
1228212285 assert_eq!(
12283- estimate_funding_transaction_fee (false, 1, Weight::from_wu(0), 2000),
12286+ estimate_v2_funding_transaction_fee (false, 1, Weight::from_wu(0), 2000),
1228412287 320
1228512288 );
1228612289 }
1228712290
12288- fn prepare_input(value : u64) -> (TxIn, TransactionU16LenLimited) {
12289- let input_1_prev_out = TxOut { value: Amount::from_sat(value ), script_pubkey: ScriptBuf::default() };
12291+ fn prepare_funding_input(funding_input_sats : u64) -> (TxIn, TransactionU16LenLimited) {
12292+ let input_1_prev_out = TxOut { value: Amount::from_sat(funding_input_sats ), script_pubkey: ScriptBuf::default() };
1229012293 let input_1_prev_tx = Transaction {
1229112294 input: vec![], output: vec![input_1_prev_out],
1229212295 version: Version::TWO, lock_time: bitcoin::absolute::LockTime::ZERO,
@@ -12303,26 +12306,32 @@ mod tests {
1230312306 use crate::ln::channel::calculate_our_funding_satoshis;
1230412307 use bitcoin::Weight;
1230512308
12306- let inputs_1 = [
12307- prepare_input(20_000),
12308- ];
12309- let inputs_2 = [
12310- prepare_input(200_000),
12311- prepare_input(100_000),
12312- ];
12313- let witness_weight = Weight::from_wu(300);
12314-
1231512309 // normal use case, output is less than the available inputs
1231612310 assert_eq!(
12317- calculate_our_funding_satoshis(true, &inputs_2, witness_weight, 2000, 1000)
12318- .unwrap(),
12311+ calculate_our_funding_satoshis(
12312+ true,
12313+ &[
12314+ prepare_funding_input(200_000),
12315+ prepare_funding_input(100_000),
12316+ ],
12317+ Weight::from_wu(300),
12318+ 2000,
12319+ 1000,
12320+ ).unwrap(),
1231912321 298332
1232012322 );
1232112323
1232212324 // below dust limit
1232312325 assert_eq!(
12324- calculate_our_funding_satoshis(true, &inputs_1, witness_weight, 2000, 20_000)
12325- .unwrap(),
12326+ calculate_our_funding_satoshis(
12327+ true,
12328+ &[
12329+ prepare_funding_input(20_000),
12330+ ],
12331+ Weight::from_wu(300),
12332+ 2000,
12333+ 20_000,
12334+ ).unwrap(),
1232612335 0
1232712336 );
1232812337 }
0 commit comments