@@ -15,7 +15,7 @@ use chain::{ChannelMonitorUpdateErr, Confirm, Listen, Watch};
15
15
use chain:: channelmonitor:: { ANTI_REORG_DELAY , ChannelMonitor , LATENCY_GRACE_PERIOD_BLOCKS } ;
16
16
use chain:: transaction:: OutPoint ;
17
17
use chain:: keysinterface:: KeysInterface ;
18
- use ln:: channelmanager:: { BREAKDOWN_TIMEOUT , ChannelManager , ChannelManagerReadArgs , PaymentId , PaymentSendFailure } ;
18
+ use ln:: channelmanager:: { BREAKDOWN_TIMEOUT , ChannelManager , ChannelManagerReadArgs , MPP_TIMEOUT_TICKS , PaymentId , PaymentSendFailure } ;
19
19
use ln:: features:: { InitFeatures , InvoiceFeatures } ;
20
20
use ln:: msgs;
21
21
use ln:: msgs:: ChannelMessageHandler ;
@@ -199,6 +199,78 @@ fn mpp_retry() {
199
199
claim_payment_along_route ( & nodes[ 0 ] , & [ & [ & nodes[ 1 ] , & nodes[ 3 ] ] , & [ & nodes[ 2 ] , & nodes[ 3 ] ] ] , false , payment_preimage) ;
200
200
}
201
201
202
+ fn do_mpp_receive_timeout ( send_partial_mpp : bool ) {
203
+ let chanmon_cfgs = create_chanmon_cfgs ( 4 ) ;
204
+ let node_cfgs = create_node_cfgs ( 4 , & chanmon_cfgs) ;
205
+ let node_chanmgrs = create_node_chanmgrs ( 4 , & node_cfgs, & [ None , None , None , None ] ) ;
206
+ let nodes = create_network ( 4 , & node_cfgs, & node_chanmgrs) ;
207
+
208
+ let chan_1_id = create_announced_chan_between_nodes ( & nodes, 0 , 1 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) . 0 . contents . short_channel_id ;
209
+ let chan_2_id = create_announced_chan_between_nodes ( & nodes, 0 , 2 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) . 0 . contents . short_channel_id ;
210
+ let chan_3_id = create_announced_chan_between_nodes ( & nodes, 1 , 3 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) . 0 . contents . short_channel_id ;
211
+ let chan_4_id = create_announced_chan_between_nodes ( & nodes, 2 , 3 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) . 0 . contents . short_channel_id ;
212
+
213
+ let ( mut route, payment_hash, payment_preimage, payment_secret) = get_route_and_payment_hash ! ( nodes[ 0 ] , nodes[ 3 ] , 100_000 ) ;
214
+ let path = route. paths [ 0 ] . clone ( ) ;
215
+ route. paths . push ( path) ;
216
+ route. paths [ 0 ] [ 0 ] . pubkey = nodes[ 1 ] . node . get_our_node_id ( ) ;
217
+ route. paths [ 0 ] [ 0 ] . short_channel_id = chan_1_id;
218
+ route. paths [ 0 ] [ 1 ] . short_channel_id = chan_3_id;
219
+ route. paths [ 1 ] [ 0 ] . pubkey = nodes[ 2 ] . node . get_our_node_id ( ) ;
220
+ route. paths [ 1 ] [ 0 ] . short_channel_id = chan_2_id;
221
+ route. paths [ 1 ] [ 1 ] . short_channel_id = chan_4_id;
222
+
223
+ // Initiate the MPP payment.
224
+ let _ = nodes[ 0 ] . node . send_payment ( & route, payment_hash, & Some ( payment_secret) ) . unwrap ( ) ;
225
+ check_added_monitors ! ( nodes[ 0 ] , 2 ) ; // one monitor per path
226
+ let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
227
+ assert_eq ! ( events. len( ) , 2 ) ;
228
+
229
+ // Pass half of the payment along the first path.
230
+ pass_along_path ( & nodes[ 0 ] , & [ & nodes[ 1 ] , & nodes[ 3 ] ] , 200_000 , payment_hash, Some ( payment_secret) , events. remove ( 0 ) , false , None ) ;
231
+
232
+ if send_partial_mpp {
233
+ // Time out the partial MPP
234
+ for _ in 0 ..MPP_TIMEOUT_TICKS {
235
+ nodes[ 3 ] . node . timer_tick_occurred ( ) ;
236
+ }
237
+
238
+ // Failed HTLC from node 3 -> 1
239
+ expect_pending_htlcs_forwardable ! ( nodes[ 3 ] ) ;
240
+ let htlc_fail_updates_3_1 = get_htlc_update_msgs ! ( nodes[ 3 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
241
+ assert_eq ! ( htlc_fail_updates_3_1. update_fail_htlcs. len( ) , 1 ) ;
242
+ nodes[ 1 ] . node . handle_update_fail_htlc ( & nodes[ 3 ] . node . get_our_node_id ( ) , & htlc_fail_updates_3_1. update_fail_htlcs [ 0 ] ) ;
243
+ check_added_monitors ! ( nodes[ 3 ] , 1 ) ;
244
+ commitment_signed_dance ! ( nodes[ 1 ] , nodes[ 3 ] , htlc_fail_updates_3_1. commitment_signed, false ) ;
245
+
246
+ // Failed HTLC from node 1 -> 0
247
+ expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
248
+ let htlc_fail_updates_1_0 = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
249
+ assert_eq ! ( htlc_fail_updates_1_0. update_fail_htlcs. len( ) , 1 ) ;
250
+ nodes[ 0 ] . node . handle_update_fail_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & htlc_fail_updates_1_0. update_fail_htlcs [ 0 ] ) ;
251
+ check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
252
+ commitment_signed_dance ! ( nodes[ 0 ] , nodes[ 1 ] , htlc_fail_updates_1_0. commitment_signed, false ) ;
253
+
254
+ expect_payment_failed_conditions ! ( nodes[ 0 ] , payment_hash, false , PaymentFailedConditions :: new( ) . mpp_parts_remain( ) . expected_htlc_error_data( 23 , & [ ] [ ..] ) ) ;
255
+ } else {
256
+ // Pass half of the payment along the second path.
257
+ pass_along_path ( & nodes[ 0 ] , & [ & nodes[ 2 ] , & nodes[ 3 ] ] , 200_000 , payment_hash, Some ( payment_secret) , events. remove ( 0 ) , true , None ) ;
258
+
259
+ // Even after MPP_TIMEOUT_TICKS we should not timeout the MPP if we have all the parts
260
+ for _ in 0 ..MPP_TIMEOUT_TICKS {
261
+ nodes[ 3 ] . node . timer_tick_occurred ( ) ;
262
+ }
263
+
264
+ claim_payment_along_route ( & nodes[ 0 ] , & [ & [ & nodes[ 1 ] , & nodes[ 3 ] ] , & [ & nodes[ 2 ] , & nodes[ 3 ] ] ] , false , payment_preimage) ;
265
+ }
266
+ }
267
+
268
+ #[ test]
269
+ fn mpp_receive_timeout ( ) {
270
+ do_mpp_receive_timeout ( true ) ;
271
+ do_mpp_receive_timeout ( false ) ;
272
+ }
273
+
202
274
#[ test]
203
275
fn retry_expired_payment ( ) {
204
276
let chanmon_cfgs = create_chanmon_cfgs ( 3 ) ;
0 commit comments