@@ -9069,116 +9069,3 @@ fn test_keysend_payments_to_private_node() {
9069
9069
pass_along_path ( & nodes[ 0 ] , & path, 10000 , payment_hash, None , event, true , Some ( test_preimage) ) ;
9070
9070
claim_payment ( & nodes[ 0 ] , & path, test_preimage) ;
9071
9071
}
9072
-
9073
- fn do_test_max_dust_htlc_exposure ( dust_outbound_balance : bool , at_forward : bool , on_holder_tx : bool ) {
9074
- // Test that we properly reject dust HTLC violating our `max_dust_htlc_exposure_msat` policy.
9075
- //
9076
- // At HTLC forward (`send_payment()`), if the sum of the trimmed-to-dust HTLC inbound and
9077
- // trimmed-to-dust HTLC outbound balance and this new payment as included on next counterparty
9078
- // commitment are above our `max_dust_htlc_exposure_msat`, we'll reject the update.
9079
- // At HTLC reception (`update_add_htlc()`), if the sum of the trimmed-to-dust HTLC inbound
9080
- // and trimmed-to-dust HTLC outbound balance and this new received HTLC as included on next
9081
- // counterparty commitment are above our `max_dust_htlc_exposure_msat`, we'll fail the update.
9082
- // Note, we return a `temporary_channel_failure` (0x1000 | 7), as the channel might be
9083
- // available again for HTLC processing once the dust bandwidth has cleared up.
9084
-
9085
- let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
9086
- let mut config = test_default_channel_config ( ) ;
9087
- config. channel_options . max_dust_htlc_exposure_msat = 5_000_000 ; // default setting value
9088
- let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
9089
- let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , Some ( config) ] ) ;
9090
- let mut nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
9091
-
9092
- nodes[ 0 ] . node . create_channel ( nodes[ 1 ] . node . get_our_node_id ( ) , 1_000_000 , 500_000_000 , 42 , None ) . unwrap ( ) ;
9093
- let mut open_channel = get_event_msg ! ( nodes[ 0 ] , MessageSendEvent :: SendOpenChannel , nodes[ 1 ] . node. get_our_node_id( ) ) ;
9094
- open_channel. max_htlc_value_in_flight_msat = 50_000_000 ;
9095
- open_channel. max_accepted_htlcs = 60 ;
9096
- nodes[ 1 ] . node . handle_open_channel ( & nodes[ 0 ] . node . get_our_node_id ( ) , InitFeatures :: known ( ) , & open_channel) ;
9097
- let mut accept_channel = get_event_msg ! ( nodes[ 1 ] , MessageSendEvent :: SendAcceptChannel , nodes[ 0 ] . node. get_our_node_id( ) ) ;
9098
- if on_holder_tx {
9099
- accept_channel. dust_limit_satoshis = 660 ;
9100
- }
9101
- nodes[ 0 ] . node . handle_accept_channel ( & nodes[ 1 ] . node . get_our_node_id ( ) , InitFeatures :: known ( ) , & accept_channel) ;
9102
-
9103
- let ( temporary_channel_id, tx, _) = create_funding_transaction ( & nodes[ 0 ] , 1_000_000 , 42 ) ;
9104
-
9105
- if on_holder_tx {
9106
- if let Some ( mut chan) = nodes[ 1 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get_mut ( & temporary_channel_id) {
9107
- chan. holder_dust_limit_satoshis = 660 ;
9108
- }
9109
- }
9110
-
9111
- nodes[ 0 ] . node . funding_transaction_generated ( & temporary_channel_id, tx. clone ( ) ) . unwrap ( ) ;
9112
- nodes[ 1 ] . node . handle_funding_created ( & nodes[ 0 ] . node . get_our_node_id ( ) , & get_event_msg ! ( nodes[ 0 ] , MessageSendEvent :: SendFundingCreated , nodes[ 1 ] . node. get_our_node_id( ) ) ) ;
9113
- check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
9114
-
9115
- nodes[ 0 ] . node . handle_funding_signed ( & nodes[ 1 ] . node . get_our_node_id ( ) , & get_event_msg ! ( nodes[ 1 ] , MessageSendEvent :: SendFundingSigned , nodes[ 0 ] . node. get_our_node_id( ) ) ) ;
9116
- check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
9117
-
9118
- let ( funding_locked, _) = create_chan_between_nodes_with_value_confirm ( & nodes[ 0 ] , & nodes[ 1 ] , & tx) ;
9119
- let ( announcement, as_update, bs_update) = create_chan_between_nodes_with_value_b ( & nodes[ 0 ] , & nodes[ 1 ] , & funding_locked) ;
9120
- update_nodes_with_chan_announce ( & nodes, 0 , 1 , & announcement, & as_update, & bs_update) ;
9121
-
9122
- if on_holder_tx {
9123
- if dust_outbound_balance {
9124
- for i in 0 ..2 {
9125
- let ( route, payment_hash, _, payment_secret) = get_route_and_payment_hash ! ( nodes[ 1 ] , nodes[ 0 ] , 2_300_000 ) ;
9126
- if let Err ( _) = nodes[ 1 ] . node . send_payment ( & route, payment_hash, & Some ( payment_secret) ) { panic ! ( "Unexpected event at dust HTLC {}" , i) ; }
9127
- }
9128
- } else {
9129
- for _ in 0 ..2 {
9130
- route_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , 2_300_000 ) ;
9131
- }
9132
- }
9133
- } else {
9134
- if dust_outbound_balance {
9135
- for i in 0 ..25 {
9136
- let ( route, payment_hash, _, payment_secret) = get_route_and_payment_hash ! ( nodes[ 1 ] , nodes[ 0 ] , 200_000 ) ; // + 177_000 msat of HTLC-success tx at 253 sats/kWU
9137
- if let Err ( _) = nodes[ 1 ] . node . send_payment ( & route, payment_hash, & Some ( payment_secret) ) { panic ! ( "Unexpected event at dust HTLC {}" , i) ; }
9138
- }
9139
- } else {
9140
- for _ in 0 ..25 {
9141
- route_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , 200_000 ) ; // + 167_000 msat of HTLC-timeout tx at 253 sats/kWU
9142
- }
9143
- }
9144
- }
9145
-
9146
- if at_forward {
9147
- let ( route, payment_hash, _, payment_secret) = get_route_and_payment_hash ! ( nodes[ 1 ] , nodes[ 0 ] , if on_holder_tx { 2_300_000 } else { 200_000 } ) ;
9148
- let mut config = UserConfig :: default ( ) ;
9149
- if on_holder_tx {
9150
- unwrap_send_err ! ( nodes[ 1 ] . node. send_payment( & route, payment_hash, & Some ( payment_secret) ) , true , APIError :: ChannelUnavailable { ref err } , assert_eq!( err, & format!( "Cannot send value that would put our exposure to dust HTLCs at {} over the limit {} on holder commitment tx" , 6_900_000 , config. channel_options. max_dust_htlc_exposure_msat) ) ) ;
9151
- } else {
9152
- unwrap_send_err ! ( nodes[ 1 ] . node. send_payment( & route, payment_hash, & Some ( payment_secret) ) , true , APIError :: ChannelUnavailable { ref err } , assert_eq!( err, & format!( "Cannot send value that would put our exposure to dust HTLCs at {} over the limit {} on counterparty commitment tx" , 5_200_000 , config. channel_options. max_dust_htlc_exposure_msat) ) ) ;
9153
- }
9154
- } else {
9155
- let ( route, payment_hash, _, payment_secret) = get_route_and_payment_hash ! ( nodes[ 0 ] , nodes[ 1 ] , if on_holder_tx { 2_300_000 } else { 200_000 } ) ;
9156
- nodes[ 0 ] . node . send_payment ( & route, payment_hash, & Some ( payment_secret) ) . unwrap ( ) ;
9157
- check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
9158
- let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
9159
- assert_eq ! ( events. len( ) , 1 ) ;
9160
- let payment_event = SendEvent :: from_event ( events. remove ( 0 ) ) ;
9161
- nodes[ 1 ] . node . handle_update_add_htlc ( & nodes[ 0 ] . node . get_our_node_id ( ) , & payment_event. msgs [ 0 ] ) ;
9162
- if on_holder_tx {
9163
- nodes[ 1 ] . logger . assert_log ( "lightning::ln::channel" . to_string ( ) , format ! ( "Cannot accept value that would put our exposure to dust HTLCs at {} over the limit {} on holder commitment tx" , 6_900_000 , config. channel_options. max_dust_htlc_exposure_msat) , 1 ) ;
9164
- } else {
9165
- nodes[ 1 ] . logger . assert_log ( "lightning::ln::channel" . to_string ( ) , format ! ( "Cannot accept value that would put our exposure to dust HTLCs at {} over the limit {} on counterparty commitment tx" , 5_200_000 , config. channel_options. max_dust_htlc_exposure_msat) , 1 ) ;
9166
- }
9167
- }
9168
-
9169
- let _ = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
9170
- let mut added_monitors = nodes[ 1 ] . chain_monitor . added_monitors . lock ( ) . unwrap ( ) ;
9171
- added_monitors. clear ( ) ;
9172
- }
9173
-
9174
- #[ test]
9175
- fn test_max_dust_htlc_exposure ( ) {
9176
- do_test_max_dust_htlc_exposure ( true , true , true ) ;
9177
- do_test_max_dust_htlc_exposure ( false , true , true ) ;
9178
- do_test_max_dust_htlc_exposure ( false , false , true ) ;
9179
- do_test_max_dust_htlc_exposure ( false , false , false ) ;
9180
- do_test_max_dust_htlc_exposure ( true , true , false ) ;
9181
- do_test_max_dust_htlc_exposure ( true , false , false ) ;
9182
- do_test_max_dust_htlc_exposure ( true , false , true ) ;
9183
- do_test_max_dust_htlc_exposure ( false , true , false ) ;
9184
- }
0 commit comments