@@ -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 ;
@@ -2844,7 +2849,7 @@ mod tests {
28442849 let outputs_weight = get_output_weight ( & generate_p2wsh_script_pubkey ( ) ) . to_wu ( ) ;
28452850 let amount_adjusted_with_p2wpkh_fee = 1_000_000
28462851 - fee_for_weight (
2847- TEST_FEERATE_SATS_PER_KW ,
2852+ ( TEST_FEERATE_SATS_PER_KW as u64 * REMOTE_FEE_TOLERANCE_PERCENT / 100 ) as u32 ,
28482853 P2WPKH_INPUT_WEIGHT_LOWER_BOUND + TX_COMMON_FIELDS_WEIGHT + outputs_weight,
28492854 ) ;
28502855 do_test_interactive_tx_constructor ( TestSession {
@@ -2880,7 +2885,7 @@ mod tests {
28802885 } ) ;
28812886 let amount_adjusted_with_p2wsh_fee = 1_000_000
28822887 - fee_for_weight (
2883- TEST_FEERATE_SATS_PER_KW ,
2888+ ( TEST_FEERATE_SATS_PER_KW as u64 * REMOTE_FEE_TOLERANCE_PERCENT / 100 ) as u32 ,
28842889 P2WSH_INPUT_WEIGHT_LOWER_BOUND + TX_COMMON_FIELDS_WEIGHT + outputs_weight,
28852890 ) ;
28862891 do_test_interactive_tx_constructor ( TestSession {
@@ -2916,7 +2921,7 @@ mod tests {
29162921 } ) ;
29172922 let amount_adjusted_with_p2tr_fee = 1_000_000
29182923 - fee_for_weight (
2919- TEST_FEERATE_SATS_PER_KW ,
2924+ ( TEST_FEERATE_SATS_PER_KW as u64 * REMOTE_FEE_TOLERANCE_PERCENT / 100 ) as u32 ,
29202925 P2TR_INPUT_WEIGHT_LOWER_BOUND + TX_COMMON_FIELDS_WEIGHT + outputs_weight,
29212926 ) ;
29222927 do_test_interactive_tx_constructor ( TestSession {
0 commit comments