11
11
//! serialization ordering between ChannelManager/ChannelMonitors and ensuring we can still retry
12
12
//! payments thereafter.
13
13
14
- use chain:: Watch ;
14
+ use chain:: { Confirm , Watch } ;
15
15
use chain:: channelmonitor:: ChannelMonitor ;
16
16
use ln:: { PaymentPreimage , PaymentHash } ;
17
17
use ln:: channelmanager:: { ChannelManager , ChannelManagerReadArgs , PaymentId , PaymentSendFailure } ;
@@ -273,8 +273,7 @@ fn no_pending_leak_on_initial_send_failure() {
273
273
assert ! ( !nodes[ 0 ] . node. has_pending_payments( ) ) ;
274
274
}
275
275
276
- #[ test]
277
- fn retry_with_no_persist ( ) {
276
+ fn do_retry_with_no_persist ( confirm_before_reload : bool ) {
278
277
// If we send a pending payment and `send_payment` returns success, we should always either
279
278
// return a payment failure event or a payment success event, and on failure the payment should
280
279
// be retryable.
@@ -321,6 +320,12 @@ fn retry_with_no_persist() {
321
320
322
321
reconnect_nodes ( & nodes[ 1 ] , & nodes[ 2 ] , ( false , false ) , ( 0 , 0 ) , ( 0 , 0 ) , ( 0 , 0 ) , ( 0 , 0 ) , ( 0 , 0 ) , ( false , false ) ) ;
323
322
323
+ let as_commitment_tx = get_local_commitment_txn ! ( nodes[ 0 ] , chan_id) [ 0 ] . clone ( ) ;
324
+ if confirm_before_reload {
325
+ mine_transaction ( & nodes[ 0 ] , & as_commitment_tx) ;
326
+ nodes[ 0 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clear ( ) ;
327
+ }
328
+
324
329
// The ChannelMonitor should always be the latest version, as we're required to persist it
325
330
// during the `commitment_signed_dance!()`.
326
331
let mut chan_0_monitor_serialized = test_utils:: TestVecWriter ( Vec :: new ( ) ) ;
@@ -361,8 +366,9 @@ fn retry_with_no_persist() {
361
366
check_closed_event ! ( nodes[ 0 ] , 1 , ClosureReason :: OutdatedChannelManager ) ;
362
367
assert ! ( nodes[ 0 ] . node. list_channels( ) . is_empty( ) ) ;
363
368
assert ! ( nodes[ 0 ] . node. has_pending_payments( ) ) ;
364
- let as_commitment_tx = nodes[ 0 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . split_off ( 0 ) ;
365
- assert_eq ! ( as_commitment_tx. len( ) , 1 ) ;
369
+ let as_broadcasted_txn = nodes[ 0 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . split_off ( 0 ) ;
370
+ assert_eq ! ( as_broadcasted_txn. len( ) , 1 ) ;
371
+ assert_eq ! ( as_broadcasted_txn[ 0 ] , as_commitment_tx) ;
366
372
367
373
nodes[ 1 ] . node . peer_disconnected ( & nodes[ 0 ] . node . get_our_node_id ( ) , false ) ;
368
374
nodes[ 0 ] . node . peer_connected ( & nodes[ 1 ] . node . get_our_node_id ( ) , & msgs:: Init { features : InitFeatures :: known ( ) } ) ;
@@ -396,26 +402,31 @@ fn retry_with_no_persist() {
396
402
check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
397
403
commitment_signed_dance ! ( nodes[ 1 ] , nodes[ 2 ] , htlc_fulfill_updates. commitment_signed, false ) ;
398
404
405
+ if confirm_before_reload {
406
+ let best_block = nodes[ 0 ] . blocks . lock ( ) . unwrap ( ) . last ( ) . unwrap ( ) . clone ( ) ;
407
+ nodes[ 0 ] . node . best_block_updated ( & best_block. 0 , best_block. 1 ) ;
408
+ }
409
+
399
410
// Create a new channel on which to retry the payment before we fail the payment via the
400
411
// HTLC-Timeout transaction. This avoids ChannelManager timing out the payment due to us
401
412
// connecting several blocks while creating the channel (implying time has passed).
402
413
create_announced_chan_between_nodes ( & nodes, 0 , 1 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
403
414
assert_eq ! ( nodes[ 0 ] . node. list_usable_channels( ) . len( ) , 1 ) ;
404
415
405
- mine_transaction ( & nodes[ 1 ] , & as_commitment_tx[ 0 ] ) ;
416
+ mine_transaction ( & nodes[ 1 ] , & as_commitment_tx) ;
406
417
let bs_htlc_claim_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . split_off ( 0 ) ;
407
418
assert_eq ! ( bs_htlc_claim_txn. len( ) , 1 ) ;
408
- check_spends ! ( bs_htlc_claim_txn[ 0 ] , as_commitment_tx[ 0 ] ) ;
419
+ check_spends ! ( bs_htlc_claim_txn[ 0 ] , as_commitment_tx) ;
409
420
expect_payment_forwarded ! ( nodes[ 1 ] , None , false ) ;
410
421
411
- mine_transaction ( & nodes[ 0 ] , & as_commitment_tx[ 0 ] ) ;
422
+ mine_transaction ( & nodes[ 0 ] , & as_commitment_tx) ;
412
423
mine_transaction ( & nodes[ 0 ] , & bs_htlc_claim_txn[ 0 ] ) ;
413
424
expect_payment_sent ! ( nodes[ 0 ] , payment_preimage_1) ;
414
425
connect_blocks ( & nodes[ 0 ] , TEST_FINAL_CLTV * 4 + 20 ) ;
415
426
let as_htlc_timeout_txn = nodes[ 0 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . split_off ( 0 ) ;
416
427
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 ] ) ;
428
+ check_spends ! ( as_htlc_timeout_txn[ 0 ] , as_commitment_tx) ;
429
+ check_spends ! ( as_htlc_timeout_txn[ 1 ] , as_commitment_tx) ;
419
430
assert_eq ! ( as_htlc_timeout_txn. len( ) , 3 ) ;
420
431
if as_htlc_timeout_txn[ 0 ] . input [ 0 ] . previous_output == bs_htlc_claim_txn[ 0 ] . input [ 0 ] . previous_output {
421
432
confirm_transaction ( & nodes[ 0 ] , & as_htlc_timeout_txn[ 1 ] ) ;
@@ -437,3 +448,9 @@ fn retry_with_no_persist() {
437
448
pass_along_path ( & nodes[ 0 ] , & [ & nodes[ 1 ] , & nodes[ 2 ] ] , 1_000_000 , payment_hash, Some ( payment_secret) , events. pop ( ) . unwrap ( ) , true , None ) ;
438
449
claim_payment_along_route ( & nodes[ 0 ] , & [ & [ & nodes[ 1 ] , & nodes[ 2 ] ] ] , false , payment_preimage) ;
439
450
}
451
+
452
+ #[ test]
453
+ fn retry_with_no_persist ( ) {
454
+ do_retry_with_no_persist ( true ) ;
455
+ do_retry_with_no_persist ( false ) ;
456
+ }
0 commit comments