@@ -915,20 +915,18 @@ impl NegotiationContext {
915
915
fn check_counterparty_fees (
916
916
& self , counterparty_fees_contributed : u64 ,
917
917
) -> Result < ( ) , AbortReason > {
918
- let counterparty_weight_contributed = self
918
+ let mut counterparty_weight_contributed = self
919
919
. remote_inputs_weight ( )
920
920
. to_wu ( )
921
921
. saturating_add ( self . remote_outputs_weight ( ) . to_wu ( ) ) ;
922
- let mut required_counterparty_contribution_fee =
923
- fee_for_weight ( self . feerate_sat_per_kw , counterparty_weight_contributed) ;
924
922
if !self . holder_is_initiator {
925
923
// if is the non-initiator:
926
924
// - the initiator's fees do not cover the common fields (version, segwit marker + flag,
927
925
// input count, output count, locktime)
928
- let tx_common_fields_fee =
929
- fee_for_weight ( self . feerate_sat_per_kw , TX_COMMON_FIELDS_WEIGHT ) ;
930
- required_counterparty_contribution_fee += tx_common_fields_fee;
926
+ counterparty_weight_contributed += TX_COMMON_FIELDS_WEIGHT ;
931
927
}
928
+ let required_counterparty_contribution_fee =
929
+ fee_for_weight ( self . feerate_sat_per_kw , counterparty_weight_contributed) ;
932
930
if counterparty_fees_contributed < required_counterparty_contribution_fee {
933
931
return Err ( AbortReason :: InsufficientFees ) ;
934
932
}
@@ -2432,16 +2430,12 @@ mod tests {
2432
2430
outputs_b : vec ! [ ] ,
2433
2431
expect_error : Some ( ( AbortReason :: InsufficientFees , ErrorCulprit :: NodeA ) ) ,
2434
2432
} ) ;
2435
- let p2wpkh_fee = fee_for_weight ( TEST_FEERATE_SATS_PER_KW , P2WPKH_INPUT_WEIGHT_LOWER_BOUND ) ;
2436
- let outputs_fee = fee_for_weight (
2437
- TEST_FEERATE_SATS_PER_KW ,
2438
- get_output_weight ( & generate_p2wsh_script_pubkey ( ) ) . to_wu ( ) ,
2439
- ) ;
2440
- let tx_common_fields_fee =
2441
- fee_for_weight ( TEST_FEERATE_SATS_PER_KW , TX_COMMON_FIELDS_WEIGHT ) ;
2442
-
2443
- let amount_adjusted_with_p2wpkh_fee =
2444
- 1_000_000 - p2wpkh_fee - outputs_fee - tx_common_fields_fee + 1 ;
2433
+ let outputs_weight = get_output_weight ( & generate_p2wsh_script_pubkey ( ) ) . to_wu ( ) ;
2434
+ let amount_adjusted_with_p2wpkh_fee = 1_000_000
2435
+ - fee_for_weight (
2436
+ TEST_FEERATE_SATS_PER_KW ,
2437
+ P2WPKH_INPUT_WEIGHT_LOWER_BOUND + TX_COMMON_FIELDS_WEIGHT + outputs_weight,
2438
+ ) ;
2445
2439
do_test_interactive_tx_constructor ( TestSession {
2446
2440
description : "Single contribution, with P2WPKH input, insufficient fees" ,
2447
2441
inputs_a : generate_inputs ( & [ TestOutput :: P2WPKH ( 1_000_000 ) ] ) ,
@@ -2473,9 +2467,11 @@ mod tests {
2473
2467
outputs_b : vec ! [ ] ,
2474
2468
expect_error : None ,
2475
2469
} ) ;
2476
- let p2wsh_fee = fee_for_weight ( TEST_FEERATE_SATS_PER_KW , P2WSH_INPUT_WEIGHT_LOWER_BOUND ) ;
2477
- let amount_adjusted_with_p2wsh_fee =
2478
- 1_000_000 - p2wsh_fee - outputs_fee - tx_common_fields_fee + 1 ;
2470
+ let amount_adjusted_with_p2wsh_fee = 1_000_000
2471
+ - fee_for_weight (
2472
+ TEST_FEERATE_SATS_PER_KW ,
2473
+ P2WSH_INPUT_WEIGHT_LOWER_BOUND + TX_COMMON_FIELDS_WEIGHT + outputs_weight,
2474
+ ) ;
2479
2475
do_test_interactive_tx_constructor ( TestSession {
2480
2476
description : "Single contribution, with P2WSH input, insufficient fees" ,
2481
2477
inputs_a : generate_inputs ( & [ TestOutput :: P2WSH ( 1_000_000 ) ] ) ,
@@ -2507,9 +2503,11 @@ mod tests {
2507
2503
outputs_b : vec ! [ ] ,
2508
2504
expect_error : None ,
2509
2505
} ) ;
2510
- let p2tr_fee = fee_for_weight ( TEST_FEERATE_SATS_PER_KW , P2TR_INPUT_WEIGHT_LOWER_BOUND ) ;
2511
- let amount_adjusted_with_p2tr_fee =
2512
- 1_000_000 - p2tr_fee - outputs_fee - tx_common_fields_fee;
2506
+ let amount_adjusted_with_p2tr_fee = 1_000_000
2507
+ - fee_for_weight (
2508
+ TEST_FEERATE_SATS_PER_KW ,
2509
+ P2TR_INPUT_WEIGHT_LOWER_BOUND + TX_COMMON_FIELDS_WEIGHT + outputs_weight,
2510
+ ) ;
2513
2511
do_test_interactive_tx_constructor ( TestSession {
2514
2512
description : "Single contribution, with P2TR input, insufficient fees" ,
2515
2513
inputs_a : generate_inputs ( & [ TestOutput :: P2TR ( 1_000_000 ) ] ) ,
0 commit comments