@@ -4473,7 +4473,7 @@ fn get_v2_channel_reserve_satoshis(channel_value_satoshis: u64, dust_limit_satos
4473
4473
/// input_count: Number of contributed inputs.
4474
4474
/// witness_weight: The witness weight for contributed inputs.
4475
4475
#[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 (
4477
4477
is_initiator: bool, input_count: usize, witness_weight: Weight,
4478
4478
funding_feerate_sat_per_1000_weight: u32,
4479
4479
) -> u64 {
@@ -4504,7 +4504,7 @@ pub(super) fn calculate_our_funding_satoshis(
4504
4504
total_witness_weight: Weight, funding_feerate_sat_per_1000_weight: u32,
4505
4505
holder_dust_limit_satoshis: u64,
4506
4506
) -> 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);
4508
4508
4509
4509
let mut total_input_satoshis = 0u64;
4510
4510
for (idx, input) in funding_inputs.iter().enumerate() {
@@ -12253,40 +12253,43 @@ mod tests {
12253
12253
}
12254
12254
12255
12255
#[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 ;
12258
12258
use bitcoin::Weight;
12259
12259
12260
- let witness_weight = Weight::from_wu(300);
12261
-
12260
+ // 2 inputs with weight 300, initiator, 2000 sat/kw feerate
12262
12261
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),
12264
12263
1668
12265
12264
);
12266
12265
12266
+ // higher feerate
12267
12267
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),
12269
12269
2502
12270
12270
);
12271
12271
12272
+ // only 1 input
12272
12273
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),
12274
12275
1348
12275
12276
);
12276
12277
12278
+ // 0 input weight
12277
12279
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),
12279
12281
748
12280
12282
);
12281
12283
12284
+ // not initiator
12282
12285
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),
12284
12287
320
12285
12288
);
12286
12289
}
12287
12290
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() };
12290
12293
let input_1_prev_tx = Transaction {
12291
12294
input: vec![], output: vec![input_1_prev_out],
12292
12295
version: Version::TWO, lock_time: bitcoin::absolute::LockTime::ZERO,
@@ -12303,26 +12306,32 @@ mod tests {
12303
12306
use crate::ln::channel::calculate_our_funding_satoshis;
12304
12307
use bitcoin::Weight;
12305
12308
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
-
12315
12309
// normal use case, output is less than the available inputs
12316
12310
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(),
12319
12321
298332
12320
12322
);
12321
12323
12322
12324
// below dust limit
12323
12325
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(),
12326
12335
0
12327
12336
);
12328
12337
}
0 commit comments