@@ -9515,7 +9515,7 @@ enum ExposureEvent {
95159515 AtUpdateFeeOutbound ,
95169516}
95179517
9518- fn do_test_max_dust_htlc_exposure ( dust_outbound_balance : bool , exposure_breach_event : ExposureEvent , on_holder_tx : bool ) {
9518+ fn do_test_max_dust_htlc_exposure ( dust_outbound_balance : bool , exposure_breach_event : ExposureEvent , on_holder_tx : bool , multiplier_dust_limit : bool ) {
95199519 // Test that we properly reject dust HTLC violating our `max_dust_htlc_exposure_msat`
95209520 // policy.
95219521 //
@@ -9530,7 +9530,12 @@ fn do_test_max_dust_htlc_exposure(dust_outbound_balance: bool, exposure_breach_e
95309530
95319531 let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
95329532 let mut config = test_default_channel_config ( ) ;
9533- config. channel_config . max_dust_htlc_exposure = MaxDustHTLCExposure :: FixedLimitMsat ( 5_000_000 ) ; // default setting value
9533+ config. channel_config . max_dust_htlc_exposure = if multiplier_dust_limit {
9534+ // Default test fee estimator rate is 253 sat/kw, so we set the multiplier to 5_000_000 / 253
9535+ // to get roughly the same initial value as the default setting when this test was
9536+ // originally written.
9537+ MaxDustHTLCExposure :: FeeRateMultiplier ( 5_000_000 / 253 )
9538+ } else { MaxDustHTLCExposure :: FixedLimitMsat ( 5_000_000 ) } ; // initial default setting value
95349539 let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
95359540 let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ Some ( config) , None ] ) ;
95369541 let mut nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
@@ -9640,7 +9645,7 @@ fn do_test_max_dust_htlc_exposure(dust_outbound_balance: bool, exposure_breach_e
96409645 ) , true , APIError :: ChannelUnavailable { .. } , { } ) ;
96419646 }
96429647 } else if exposure_breach_event == ExposureEvent :: AtHTLCReception {
9643- let ( route, payment_hash, _, payment_secret) = get_route_and_payment_hash ! ( nodes[ 1 ] , nodes[ 0 ] , if on_holder_tx { dust_inbound_htlc_on_holder_tx_msat } else { dust_htlc_on_counterparty_tx_msat + 1 } ) ;
9648+ let ( route, payment_hash, _, payment_secret) = get_route_and_payment_hash ! ( nodes[ 1 ] , nodes[ 0 ] , if on_holder_tx { dust_inbound_htlc_on_holder_tx_msat } else { dust_htlc_on_counterparty_tx_msat + 4 } ) ;
96449649 nodes[ 1 ] . node . send_payment_with_route ( & route, payment_hash,
96459650 RecipientOnionFields :: secret_only ( payment_secret) , PaymentId ( payment_hash. 0 ) ) . unwrap ( ) ;
96469651 check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
@@ -9658,13 +9663,19 @@ fn do_test_max_dust_htlc_exposure(dust_outbound_balance: bool, exposure_breach_e
96589663 // Outbound dust balance: 5200 sats
96599664 nodes[ 0 ] . logger . assert_log ( "lightning::ln::channel" . to_string ( ) ,
96609665 format ! ( "Cannot accept value that would put our exposure to dust HTLCs at {} over the limit {} on counterparty commitment tx" ,
9661- dust_htlc_on_counterparty_tx_msat * ( dust_htlc_on_counterparty_tx - 1 ) + dust_htlc_on_counterparty_tx_msat + 1 ,
9666+ dust_htlc_on_counterparty_tx_msat * ( dust_htlc_on_counterparty_tx - 1 ) + dust_htlc_on_counterparty_tx_msat + 4 ,
96629667 max_dust_htlc_exposure_msat) , 1 ) ;
96639668 }
96649669 } else if exposure_breach_event == ExposureEvent :: AtUpdateFeeOutbound {
96659670 route. paths [ 0 ] . hops . last_mut ( ) . unwrap ( ) . fee_msat = 2_500_000 ;
9666- nodes[ 0 ] . node . send_payment_with_route ( & route, payment_hash,
9667- RecipientOnionFields :: secret_only ( payment_secret) , PaymentId ( payment_hash. 0 ) ) . unwrap ( ) ;
9671+ // For the multiplier dust exposure limit, since it scales with feerate,
9672+ // we need to add a lot of HTLCs that will become dust at the new feerate
9673+ // to cross the threshold.
9674+ for _ in 0 ..20 {
9675+ let ( _, payment_hash, payment_secret) = get_payment_preimage_hash ( & nodes[ 1 ] , Some ( 1_000 ) , None ) ;
9676+ nodes[ 0 ] . node . send_payment_with_route ( & route, payment_hash,
9677+ RecipientOnionFields :: secret_only ( payment_secret) , PaymentId ( payment_hash. 0 ) ) . unwrap ( ) ;
9678+ }
96689679 {
96699680 let mut feerate_lock = chanmon_cfgs[ 0 ] . fee_estimator . sat_per_kw . lock ( ) . unwrap ( ) ;
96709681 * feerate_lock = * feerate_lock * 10 ;
@@ -9679,20 +9690,25 @@ fn do_test_max_dust_htlc_exposure(dust_outbound_balance: bool, exposure_breach_e
96799690 added_monitors. clear ( ) ;
96809691}
96819692
9693+ fn do_test_max_dust_htlc_exposure_by_threshold_type ( multiplier_dust_limit : bool ) {
9694+ do_test_max_dust_htlc_exposure ( true , ExposureEvent :: AtHTLCForward , true , multiplier_dust_limit) ;
9695+ do_test_max_dust_htlc_exposure ( false , ExposureEvent :: AtHTLCForward , true , multiplier_dust_limit) ;
9696+ do_test_max_dust_htlc_exposure ( false , ExposureEvent :: AtHTLCReception , true , multiplier_dust_limit) ;
9697+ do_test_max_dust_htlc_exposure ( false , ExposureEvent :: AtHTLCReception , false , multiplier_dust_limit) ;
9698+ do_test_max_dust_htlc_exposure ( true , ExposureEvent :: AtHTLCForward , false , multiplier_dust_limit) ;
9699+ do_test_max_dust_htlc_exposure ( true , ExposureEvent :: AtHTLCReception , false , multiplier_dust_limit) ;
9700+ do_test_max_dust_htlc_exposure ( true , ExposureEvent :: AtHTLCReception , true , multiplier_dust_limit) ;
9701+ do_test_max_dust_htlc_exposure ( false , ExposureEvent :: AtHTLCForward , false , multiplier_dust_limit) ;
9702+ do_test_max_dust_htlc_exposure ( true , ExposureEvent :: AtUpdateFeeOutbound , true , multiplier_dust_limit) ;
9703+ do_test_max_dust_htlc_exposure ( true , ExposureEvent :: AtUpdateFeeOutbound , false , multiplier_dust_limit) ;
9704+ do_test_max_dust_htlc_exposure ( false , ExposureEvent :: AtUpdateFeeOutbound , false , multiplier_dust_limit) ;
9705+ do_test_max_dust_htlc_exposure ( false , ExposureEvent :: AtUpdateFeeOutbound , true , multiplier_dust_limit) ;
9706+ }
9707+
96829708#[ test]
96839709fn test_max_dust_htlc_exposure ( ) {
9684- do_test_max_dust_htlc_exposure ( true , ExposureEvent :: AtHTLCForward , true ) ;
9685- do_test_max_dust_htlc_exposure ( false , ExposureEvent :: AtHTLCForward , true ) ;
9686- do_test_max_dust_htlc_exposure ( false , ExposureEvent :: AtHTLCReception , true ) ;
9687- do_test_max_dust_htlc_exposure ( false , ExposureEvent :: AtHTLCReception , false ) ;
9688- do_test_max_dust_htlc_exposure ( true , ExposureEvent :: AtHTLCForward , false ) ;
9689- do_test_max_dust_htlc_exposure ( true , ExposureEvent :: AtHTLCReception , false ) ;
9690- do_test_max_dust_htlc_exposure ( true , ExposureEvent :: AtHTLCReception , true ) ;
9691- do_test_max_dust_htlc_exposure ( false , ExposureEvent :: AtHTLCForward , false ) ;
9692- do_test_max_dust_htlc_exposure ( true , ExposureEvent :: AtUpdateFeeOutbound , true ) ;
9693- do_test_max_dust_htlc_exposure ( true , ExposureEvent :: AtUpdateFeeOutbound , false ) ;
9694- do_test_max_dust_htlc_exposure ( false , ExposureEvent :: AtUpdateFeeOutbound , false ) ;
9695- do_test_max_dust_htlc_exposure ( false , ExposureEvent :: AtUpdateFeeOutbound , true ) ;
9710+ do_test_max_dust_htlc_exposure_by_threshold_type ( false ) ;
9711+ do_test_max_dust_htlc_exposure_by_threshold_type ( true ) ;
96969712}
96979713
96989714#[ test]
0 commit comments