@@ -257,6 +257,9 @@ impl_writeable_tlv_based!(ConstructedTransaction, {
257257 ( 11 , shared_output_index, required) ,
258258} ) ;
259259
260+ /// The percent tolerance given to the remote when estimating if they paid enough fees.
261+ const REMOTE_FEE_TOLERANCE_PERCENT : u64 = 95 ;
262+
260263impl ConstructedTransaction {
261264 fn new ( context : NegotiationContext ) -> Result < Self , AbortReason > {
262265 let remote_inputs_value = context. remote_inputs_value ( ) ;
@@ -315,8 +318,10 @@ impl ConstructedTransaction {
315318
316319 // - the peer's paid feerate does not meet or exceed the agreed feerate (based on the minimum fee).
317320 let remote_fees_contributed = remote_inputs_value. saturating_sub ( remote_outputs_value) ;
318- let required_remote_contribution_fee =
319- fee_for_weight ( context. feerate_sat_per_kw , remote_weight_contributed) ;
321+ let required_remote_contribution_fee = fee_for_weight (
322+ ( context. feerate_sat_per_kw as u64 * REMOTE_FEE_TOLERANCE_PERCENT / 100 ) as u32 ,
323+ remote_weight_contributed,
324+ ) ;
320325 if remote_fees_contributed < required_remote_contribution_fee {
321326 return Err ( AbortReason :: InsufficientFees ) ;
322327 }
@@ -2379,7 +2384,7 @@ mod tests {
23792384 use super :: {
23802385 get_output_weight, ConstructedTransaction , InteractiveTxSigningSession , TxInMetadata ,
23812386 P2TR_INPUT_WEIGHT_LOWER_BOUND , P2WPKH_INPUT_WEIGHT_LOWER_BOUND ,
2382- P2WSH_INPUT_WEIGHT_LOWER_BOUND , TX_COMMON_FIELDS_WEIGHT ,
2387+ P2WSH_INPUT_WEIGHT_LOWER_BOUND , REMOTE_FEE_TOLERANCE_PERCENT , TX_COMMON_FIELDS_WEIGHT ,
23832388 } ;
23842389
23852390 const TEST_FEERATE_SATS_PER_KW : u32 = FEERATE_FLOOR_SATS_PER_KW * 10 ;
@@ -2846,7 +2851,8 @@ mod tests {
28462851 - fee_for_weight (
28472852 TEST_FEERATE_SATS_PER_KW ,
28482853 P2WPKH_INPUT_WEIGHT_LOWER_BOUND + TX_COMMON_FIELDS_WEIGHT + outputs_weight,
2849- ) ;
2854+ ) * REMOTE_FEE_TOLERANCE_PERCENT
2855+ / 100 ;
28502856 do_test_interactive_tx_constructor ( TestSession {
28512857 description : "Single contribution, with P2WPKH input, insufficient fees" ,
28522858 inputs_a : generate_inputs ( & [ TestOutput :: P2WPKH ( 1_000_000 ) ] ) ,
@@ -2882,7 +2888,8 @@ mod tests {
28822888 - fee_for_weight (
28832889 TEST_FEERATE_SATS_PER_KW ,
28842890 P2WSH_INPUT_WEIGHT_LOWER_BOUND + TX_COMMON_FIELDS_WEIGHT + outputs_weight,
2885- ) ;
2891+ ) * REMOTE_FEE_TOLERANCE_PERCENT
2892+ / 100 ;
28862893 do_test_interactive_tx_constructor ( TestSession {
28872894 description : "Single contribution, with P2WSH input, insufficient fees" ,
28882895 inputs_a : generate_inputs ( & [ TestOutput :: P2WSH ( 1_000_000 ) ] ) ,
@@ -2918,7 +2925,8 @@ mod tests {
29182925 - fee_for_weight (
29192926 TEST_FEERATE_SATS_PER_KW ,
29202927 P2TR_INPUT_WEIGHT_LOWER_BOUND + TX_COMMON_FIELDS_WEIGHT + outputs_weight,
2921- ) ;
2928+ ) * REMOTE_FEE_TOLERANCE_PERCENT
2929+ / 100 ;
29222930 do_test_interactive_tx_constructor ( TestSession {
29232931 description : "Single contribution, with P2TR input, insufficient fees" ,
29242932 inputs_a : generate_inputs ( & [ TestOutput :: P2TR ( 1_000_000 ) ] ) ,
0 commit comments