@@ -278,6 +278,7 @@ fn retry_with_no_persist() {
278
278
// If we send a pending payment and `send_payment` returns success, we should always either
279
279
// return a payment failure event or a payment success event, and on failure the payment should
280
280
// be retryable.
281
+ //
281
282
// In order to do so when the ChannelManager isn't immediately persisted (which is normal - its
282
283
// always persisted asynchronously), the ChannelManager has to reload some payment data from
283
284
// ChannelMonitor(s) in some cases. This tests that reloading.
@@ -289,13 +290,16 @@ fn retry_with_no_persist() {
289
290
let nodes_0_deserialized: ChannelManager < EnforcingSigner , & test_utils:: TestChainMonitor , & test_utils:: TestBroadcaster , & test_utils:: TestKeysInterface , & test_utils:: TestFeeEstimator , & test_utils:: TestLogger > ;
290
291
let mut nodes = create_network ( 3 , & node_cfgs, & node_chanmgrs) ;
291
292
292
- let chan_id = create_announced_chan_between_nodes ( & nodes, 0 , 1 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) . 2 ;
293
+ let ( _ , _ , chan_id, funding_tx ) = create_announced_chan_between_nodes ( & nodes, 0 , 1 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
293
294
create_announced_chan_between_nodes ( & nodes, 1 , 2 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
294
295
295
- // Serialize the ChannelManager prior to sending the payment
296
+ // Serialize the ChannelManager prior to sending payments
296
297
let nodes_0_serialized = nodes[ 0 ] . node . encode ( ) ;
297
298
298
- let ( route, payment_hash, payment_preimage, payment_secret) = get_route_and_payment_hash ! ( nodes[ 0 ] , nodes[ 2 ] , 100_000 ) ;
299
+ // Send two payments - one which will get to nodes[2] and will be claimed, one which we'll time
300
+ // out and retry.
301
+ let payment_preimage_1 = route_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] , & nodes[ 2 ] ] , 1_000_000 ) . 0 ;
302
+ let ( route, payment_hash, payment_preimage, payment_secret) = get_route_and_payment_hash ! ( nodes[ 0 ] , nodes[ 2 ] , 1_000_000 ) ;
299
303
let payment_id = nodes[ 0 ] . node . send_payment ( & route, payment_hash, & Some ( payment_secret) ) . unwrap ( ) ;
300
304
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
301
305
@@ -315,7 +319,7 @@ fn retry_with_no_persist() {
315
319
// nodes[1] now immediately fails the HTLC as the next-hop channel is disconnected
316
320
let _ = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
317
321
318
- reconnect_nodes ( & nodes[ 1 ] , & nodes[ 2 ] , ( true , true ) , ( 0 , 0 ) , ( 0 , 0 ) , ( 0 , 0 ) , ( 0 , 0 ) , ( 0 , 0 ) , ( false , false ) ) ;
322
+ reconnect_nodes ( & nodes[ 1 ] , & nodes[ 2 ] , ( false , false ) , ( 0 , 0 ) , ( 0 , 0 ) , ( 0 , 0 ) , ( 0 , 0 ) , ( 0 , 0 ) , ( false , false ) ) ;
319
323
320
324
// The ChannelMonitor should always be the latest version, as we're required to persist it
321
325
// during the `commitment_signed_dance!()`.
@@ -383,29 +387,53 @@ fn retry_with_no_persist() {
383
387
}
384
388
check_closed_broadcast ! ( nodes[ 1 ] , false ) ;
385
389
390
+ // Now claim the first payment, which should allow nodes[1] to claim the payment on-chain when
391
+ // we close in a moment.
392
+ nodes[ 2 ] . node . claim_funds ( payment_preimage_1) ;
393
+ check_added_monitors ! ( nodes[ 2 ] , 1 ) ;
394
+ let htlc_fulfill_updates = get_htlc_update_msgs ! ( nodes[ 2 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
395
+ nodes[ 1 ] . node . handle_update_fulfill_htlc ( & nodes[ 2 ] . node . get_our_node_id ( ) , & htlc_fulfill_updates. update_fulfill_htlcs [ 0 ] ) ;
396
+ check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
397
+ commitment_signed_dance ! ( nodes[ 1 ] , nodes[ 2 ] , htlc_fulfill_updates. commitment_signed, false ) ;
398
+
386
399
// Create a new channel on which to retry the payment before we fail the payment via the
387
400
// HTLC-Timeout transaction. This avoids ChannelManager timing out the payment due to us
388
401
// connecting several blocks while creating the channel (implying time has passed).
389
402
create_announced_chan_between_nodes ( & nodes, 0 , 1 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
390
403
assert_eq ! ( nodes[ 0 ] . node. list_usable_channels( ) . len( ) , 1 ) ;
391
404
405
+ mine_transaction ( & nodes[ 1 ] , & as_commitment_tx[ 0 ] ) ;
406
+ let bs_htlc_claim_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . split_off ( 0 ) ;
407
+ assert_eq ! ( bs_htlc_claim_txn. len( ) , 1 ) ;
408
+ check_spends ! ( bs_htlc_claim_txn[ 0 ] , as_commitment_tx[ 0 ] ) ;
409
+ expect_payment_forwarded ! ( nodes[ 1 ] , None , false ) ;
410
+
392
411
mine_transaction ( & nodes[ 0 ] , & as_commitment_tx[ 0 ] ) ;
412
+ mine_transaction ( & nodes[ 0 ] , & bs_htlc_claim_txn[ 0 ] ) ;
413
+ expect_payment_sent ! ( nodes[ 0 ] , payment_preimage_1) ;
393
414
connect_blocks ( & nodes[ 0 ] , TEST_FINAL_CLTV * 4 + 20 ) ;
394
- let as_htlc_timeout_tx = nodes[ 0 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . split_off ( 0 ) ;
395
- assert_eq ! ( as_htlc_timeout_tx. len( ) , 1 ) ;
396
- confirm_transaction ( & nodes[ 0 ] , & as_htlc_timeout_tx[ 0 ] ) ;
415
+ let as_htlc_timeout_txn = nodes[ 0 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . split_off ( 0 ) ;
416
+ check_spends ! ( as_htlc_timeout_txn[ 2 ] , funding_tx) ;
417
+ check_spends ! ( as_htlc_timeout_txn[ 0 ] , as_commitment_tx[ 0 ] ) ;
418
+ check_spends ! ( as_htlc_timeout_txn[ 1 ] , as_commitment_tx[ 0 ] ) ;
419
+ assert_eq ! ( as_htlc_timeout_txn. len( ) , 3 ) ;
420
+ if as_htlc_timeout_txn[ 0 ] . input [ 0 ] . previous_output == bs_htlc_claim_txn[ 0 ] . input [ 0 ] . previous_output {
421
+ confirm_transaction ( & nodes[ 0 ] , & as_htlc_timeout_txn[ 1 ] ) ;
422
+ } else {
423
+ confirm_transaction ( & nodes[ 0 ] , & as_htlc_timeout_txn[ 0 ] ) ;
424
+ }
397
425
nodes[ 0 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clear ( ) ;
398
426
expect_payment_failed ! ( nodes[ 0 ] , payment_hash, false ) ;
399
427
400
428
// Finally, retry the payment (which was reloaded from the ChannelMonitor when nodes[0] was
401
429
// reloaded) via a route over the new channel, which work without issue and eventually be
402
430
// received and claimed at the recipient just like any other payment.
403
- let ( new_route, _, _, _) = get_route_and_payment_hash ! ( nodes[ 0 ] , nodes[ 2 ] , 100_000 ) ;
431
+ let ( new_route, _, _, _) = get_route_and_payment_hash ! ( nodes[ 0 ] , nodes[ 2 ] , 1_000_000 ) ;
404
432
405
433
nodes[ 0 ] . node . retry_payment ( & new_route, payment_id) . unwrap ( ) ;
406
434
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
407
435
let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
408
436
assert_eq ! ( events. len( ) , 1 ) ;
409
- pass_along_path ( & nodes[ 0 ] , & [ & nodes[ 1 ] , & nodes[ 2 ] ] , 100_000 , payment_hash, Some ( payment_secret) , events. pop ( ) . unwrap ( ) , true , None ) ;
437
+ pass_along_path ( & nodes[ 0 ] , & [ & nodes[ 1 ] , & nodes[ 2 ] ] , 1_000_000 , payment_hash, Some ( payment_secret) , events. pop ( ) . unwrap ( ) , true , None ) ;
410
438
claim_payment_along_route ( & nodes[ 0 ] , & [ & [ & nodes[ 1 ] , & nodes[ 2 ] ] ] , false , payment_preimage) ;
411
439
}
0 commit comments