@@ -332,20 +332,33 @@ fn test_async_commitment_signature_for_peer_disconnect() {
332
332
333
333
#[ test]
334
334
fn test_async_commitment_signature_ordering_reestablish ( ) {
335
- do_test_async_commitment_signature_ordering ( false , false ) ;
335
+ do_test_async_commitment_signature_ordering ( false , false , false ) ;
336
336
}
337
337
338
338
#[ test]
339
339
fn test_async_commitment_signature_ordering_monitor_restored ( ) {
340
- do_test_async_commitment_signature_ordering ( true , false ) ;
340
+ do_test_async_commitment_signature_ordering ( true , false , false ) ;
341
341
}
342
342
343
343
#[ test]
344
- fn test_async_commitment_signature_ordering_monitor_restored_signer_restored_early ( ) {
345
- do_test_async_commitment_signature_ordering ( true , true ) ;
344
+ fn test_async_commitment_signature_ordering_monitor_restored_signer_restored_before_completion ( ) {
345
+ // This tests that if we were pending a monitor update completion across a restart,
346
+ // and needed to send a CS then RAA, that if our signer is unblocked before the monitor
347
+ // update completes, then we don't send duplicate messages upon calling `signer_unblocked`
348
+ // after the monitor update completes.
349
+ do_test_async_commitment_signature_ordering ( true , true , false ) ;
346
350
}
347
351
348
- fn do_test_async_commitment_signature_ordering ( monitor_update_failure : bool , enable_signer_before_monitor_completion : bool ) {
352
+ #[ test]
353
+ fn test_async_commitment_signature_ordering_signer_restored_before_reestablish ( ) {
354
+ // This tests that if we tried to send a commitment_signed, but our signer was blocked,
355
+ // if we disconnect, reconnect, unblock the signer, then handle channel_reestablish,
356
+ // that we don't send duplicate messages upon calling `signer_unblocked`.
357
+ do_test_async_commitment_signature_ordering ( false , false , true ) ;
358
+ }
359
+
360
+ fn do_test_async_commitment_signature_ordering ( monitor_update_failure : bool ,
361
+ enable_signer_before_monitor_completion : bool , enable_signer_before_reestablish : bool ) {
349
362
// Across disconnects we may end up in a situation where we need to send a
350
363
// commitment_signed and then revoke_and_ack. We need to make sure that if
351
364
// the signer is pending for commitment_signed but not revoke_and_ack, we don't
@@ -365,14 +378,24 @@ fn do_test_async_commitment_signature_ordering(monitor_update_failure: bool, ena
365
378
366
379
let ( payment_preimage_1, payment_hash_1, ..) = route_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , 1_000_000 ) ;
367
380
381
+ if enable_signer_before_reestablish {
382
+ // When the node goes to sign the second commitment update, it will set that
383
+ // it's pending a commitment update, which will still be set when the peer
384
+ // reconnects.
385
+ nodes[ 0 ] . disable_channel_signer_op ( & nodes[ 1 ] . node . get_our_node_id ( ) , & chan_id, SignerOp :: SignCounterpartyCommitment ) ;
386
+ }
368
387
// Start to send the second update_add_htlc + commitment_signed, but don't actually make it
369
388
// to the peer.
370
389
let ( route, payment_hash_2, payment_preimage_2, payment_secret_2) = get_route_and_payment_hash ! ( nodes[ 0 ] , nodes[ 1 ] , 1000000 ) ;
371
390
nodes[ 0 ] . node . send_payment_with_route ( & route, payment_hash_2,
372
391
RecipientOnionFields :: secret_only ( payment_secret_2) , PaymentId ( payment_hash_2. 0 ) ) . unwrap ( ) ;
373
392
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
374
393
375
- get_htlc_update_msgs ( & nodes[ 0 ] , & nodes[ 1 ] . node . get_our_node_id ( ) ) ;
394
+ if enable_signer_before_reestablish {
395
+ assert ! ( nodes[ 0 ] . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
396
+ } else {
397
+ get_htlc_update_msgs ( & nodes[ 0 ] , & nodes[ 1 ] . node . get_our_node_id ( ) ) ;
398
+ }
376
399
377
400
// Send back update_fulfill_htlc + commitment_signed for the first payment.
378
401
nodes[ 1 ] . node . claim_funds ( payment_preimage_1) ;
@@ -391,7 +414,7 @@ fn do_test_async_commitment_signature_ordering(monitor_update_failure: bool, ena
391
414
chanmon_cfgs[ 0 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: InProgress ) ;
392
415
}
393
416
nodes[ 0 ] . node . handle_commitment_signed ( & nodes[ 1 ] . node . get_our_node_id ( ) , commitment_signed) ;
394
- if monitor_update_failure {
417
+ if monitor_update_failure || enable_signer_before_reestablish {
395
418
assert ! ( nodes[ 0 ] . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
396
419
} else {
397
420
let _ = get_event_msg ! ( nodes[ 0 ] , MessageSendEvent :: SendRevokeAndACK , nodes[ 1 ] . node. get_our_node_id( ) ) ;
@@ -421,22 +444,38 @@ fn do_test_async_commitment_signature_ordering(monitor_update_failure: bool, ena
421
444
// With a fully working signer, here we would send a commitment_signed,
422
445
// and then revoke_and_ack. With commitment_signed disabled, since
423
446
// our ordering is CS then RAA, we should make sure we don't send the RAA.
424
- nodes[ 0 ] . disable_channel_signer_op ( & nodes[ 1 ] . node . get_our_node_id ( ) , & chan_id, SignerOp :: SignCounterpartyCommitment ) ;
447
+ if enable_signer_before_reestablish {
448
+ nodes[ 0 ] . enable_channel_signer_op ( & nodes[ 1 ] . node . get_our_node_id ( ) , & chan_id, SignerOp :: SignCounterpartyCommitment ) ;
449
+ } else {
450
+ nodes[ 0 ] . disable_channel_signer_op ( & nodes[ 1 ] . node . get_our_node_id ( ) , & chan_id, SignerOp :: SignCounterpartyCommitment ) ;
451
+ }
425
452
nodes[ 0 ] . node . handle_channel_reestablish ( & nodes[ 1 ] . node . get_our_node_id ( ) , & reestablish_2[ 0 ] ) ;
426
- let as_resp = handle_chan_reestablish_msgs ! ( nodes[ 0 ] , nodes[ 1 ] ) ;
427
- assert ! ( as_resp. 0 . is_none( ) ) ;
428
- assert ! ( as_resp. 1 . is_none( ) ) ;
429
- assert ! ( as_resp. 2 . is_none( ) ) ;
430
453
431
- let as_resp = if monitor_update_failure && enable_signer_before_monitor_completion {
454
+ let as_resp = if enable_signer_before_reestablish {
455
+ // We should send the CS + RAA now, and not again on `signer_unblocked`.
456
+ let as_resp = handle_chan_reestablish_msgs ! ( nodes[ 0 ] , nodes[ 1 ] ) ;
457
+
458
+ nodes[ 0 ] . node . signer_unblocked ( Some ( ( nodes[ 1 ] . node . get_our_node_id ( ) , chan_id) ) ) ;
459
+ let as_resp_empty = handle_chan_reestablish_msgs ! ( nodes[ 0 ] , nodes[ 1 ] ) ;
460
+ assert ! ( as_resp_empty. 0 . is_none( ) ) ;
461
+ assert ! ( as_resp_empty. 1 . is_none( ) ) ;
462
+ assert ! ( as_resp_empty. 2 . is_none( ) ) ;
463
+
464
+ as_resp
465
+ } else if monitor_update_failure && enable_signer_before_monitor_completion {
466
+ let as_resp = handle_chan_reestablish_msgs ! ( nodes[ 0 ] , nodes[ 1 ] ) ;
467
+ assert ! ( as_resp. 0 . is_none( ) ) ;
468
+ assert ! ( as_resp. 1 . is_none( ) ) ;
469
+ assert ! ( as_resp. 2 . is_none( ) ) ;
470
+
432
471
nodes[ 0 ] . enable_channel_signer_op ( & nodes[ 1 ] . node . get_our_node_id ( ) , & chan_id, SignerOp :: SignCounterpartyCommitment ) ;
433
472
434
473
chanmon_cfgs[ 0 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: Completed ) ;
435
474
let ( outpoint, latest_update, _) = nodes[ 0 ] . chain_monitor . latest_monitor_update_id . lock ( ) . unwrap ( ) . get ( & chan_id) . unwrap ( ) . clone ( ) ;
436
475
nodes[ 0 ] . chain_monitor . chain_monitor . force_channel_monitor_updated ( outpoint, latest_update) ;
437
476
check_added_monitors ! ( nodes[ 0 ] , 0 ) ;
438
477
439
- // We should send the CS now, and not send it again on `signer_unblocked`.
478
+ // We should send the CS + RAA now, and not again on `signer_unblocked`.
440
479
let as_resp = handle_chan_reestablish_msgs ! ( nodes[ 0 ] , nodes[ 1 ] ) ;
441
480
442
481
nodes[ 0 ] . node . signer_unblocked ( Some ( ( nodes[ 1 ] . node . get_our_node_id ( ) , chan_id) ) ) ;
@@ -446,6 +485,11 @@ fn do_test_async_commitment_signature_ordering(monitor_update_failure: bool, ena
446
485
assert ! ( as_resp_empty. 2 . is_none( ) ) ;
447
486
as_resp
448
487
} else {
488
+ let as_resp = handle_chan_reestablish_msgs ! ( nodes[ 0 ] , nodes[ 1 ] ) ;
489
+ assert ! ( as_resp. 0 . is_none( ) ) ;
490
+ assert ! ( as_resp. 1 . is_none( ) ) ;
491
+ assert ! ( as_resp. 2 . is_none( ) ) ;
492
+
449
493
if monitor_update_failure {
450
494
chanmon_cfgs[ 0 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: Completed ) ;
451
495
let ( outpoint, latest_update, _) = nodes[ 0 ] . chain_monitor . latest_monitor_update_id . lock ( ) . unwrap ( ) . get ( & chan_id) . unwrap ( ) . clone ( ) ;
0 commit comments