@@ -332,15 +332,20 @@ 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 ) ;
335
+ do_test_async_commitment_signature_ordering ( 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 ) ;
340
+ do_test_async_commitment_signature_ordering ( true , false ) ;
341
341
}
342
342
343
- fn do_test_async_commitment_signature_ordering ( monitor_update_failure : bool ) {
343
+ #[ test]
344
+ fn test_async_commitment_signature_ordering_monitor_restored_signer_restored_early ( ) {
345
+ do_test_async_commitment_signature_ordering ( true , true ) ;
346
+ }
347
+
348
+ fn do_test_async_commitment_signature_ordering ( monitor_update_failure : bool , enable_signer_before_monitor_completion : bool ) {
344
349
// Across disconnects we may end up in a situation where we need to send a
345
350
// commitment_signed and then revoke_and_ack. We need to make sure that if
346
351
// the signer is pending for commitment_signed but not revoke_and_ack, we don't
@@ -423,25 +428,45 @@ fn do_test_async_commitment_signature_ordering(monitor_update_failure: bool) {
423
428
assert ! ( as_resp. 1 . is_none( ) ) ;
424
429
assert ! ( as_resp. 2 . is_none( ) ) ;
425
430
426
- if monitor_update_failure {
431
+ let as_resp = if monitor_update_failure && enable_signer_before_monitor_completion {
432
+ nodes[ 0 ] . enable_channel_signer_op ( & nodes[ 1 ] . node . get_our_node_id ( ) , & chan_id, SignerOp :: SignCounterpartyCommitment ) ;
433
+
427
434
chanmon_cfgs[ 0 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: Completed ) ;
428
435
let ( outpoint, latest_update, _) = nodes[ 0 ] . chain_monitor . latest_monitor_update_id . lock ( ) . unwrap ( ) . get ( & chan_id) . unwrap ( ) . clone ( ) ;
429
436
nodes[ 0 ] . chain_monitor . chain_monitor . force_channel_monitor_updated ( outpoint, latest_update) ;
430
437
check_added_monitors ! ( nodes[ 0 ] , 0 ) ;
431
- }
432
438
433
- // Make sure that on signer_unblocked we have the same behavior (even though RAA is ready,
434
- // we don't send CS yet).
435
- nodes[ 0 ] . node . signer_unblocked ( Some ( ( nodes[ 1 ] . node . get_our_node_id ( ) , chan_id) ) ) ;
436
- let as_resp = handle_chan_reestablish_msgs ! ( nodes[ 0 ] , nodes[ 1 ] ) ;
437
- assert ! ( as_resp. 0 . is_none( ) ) ;
438
- assert ! ( as_resp. 1 . is_none( ) ) ;
439
- assert ! ( as_resp. 2 . is_none( ) ) ;
439
+ // We should send the CS now, and not send it again on `signer_unblocked`.
440
+ let as_resp = handle_chan_reestablish_msgs ! ( nodes[ 0 ] , nodes[ 1 ] ) ;
440
441
441
- nodes[ 0 ] . enable_channel_signer_op ( & nodes[ 1 ] . node . get_our_node_id ( ) , & chan_id, SignerOp :: SignCounterpartyCommitment ) ;
442
- nodes[ 0 ] . node . signer_unblocked ( Some ( ( nodes[ 1 ] . node . get_our_node_id ( ) , chan_id) ) ) ;
442
+ nodes[ 0 ] . node . signer_unblocked ( Some ( ( nodes[ 1 ] . node . get_our_node_id ( ) , chan_id) ) ) ;
443
+ let as_resp_empty = handle_chan_reestablish_msgs ! ( nodes[ 0 ] , nodes[ 1 ] ) ;
444
+ assert ! ( as_resp_empty. 0 . is_none( ) ) ;
445
+ assert ! ( as_resp_empty. 1 . is_none( ) ) ;
446
+ assert ! ( as_resp_empty. 2 . is_none( ) ) ;
447
+ as_resp
448
+ } else {
449
+ if monitor_update_failure {
450
+ chanmon_cfgs[ 0 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: Completed ) ;
451
+ let ( outpoint, latest_update, _) = nodes[ 0 ] . chain_monitor . latest_monitor_update_id . lock ( ) . unwrap ( ) . get ( & chan_id) . unwrap ( ) . clone ( ) ;
452
+ nodes[ 0 ] . chain_monitor . chain_monitor . force_channel_monitor_updated ( outpoint, latest_update) ;
453
+ check_added_monitors ! ( nodes[ 0 ] , 0 ) ;
454
+ }
455
+
456
+ // Make sure that on signer_unblocked we have the same behavior (even though RAA is ready,
457
+ // we don't send CS yet).
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
+ nodes[ 0 ] . enable_channel_signer_op ( & nodes[ 1 ] . node . get_our_node_id ( ) , & chan_id, SignerOp :: SignCounterpartyCommitment ) ;
465
+ nodes[ 0 ] . node . signer_unblocked ( Some ( ( nodes[ 1 ] . node . get_our_node_id ( ) , chan_id) ) ) ;
466
+ let as_resp = handle_chan_reestablish_msgs ! ( nodes[ 0 ] , nodes[ 1 ] ) ;
467
+ as_resp
468
+ } ;
443
469
444
- let as_resp = handle_chan_reestablish_msgs ! ( nodes[ 0 ] , nodes[ 1 ] ) ;
445
470
nodes[ 1 ] . node . handle_channel_reestablish ( & nodes[ 0 ] . node . get_our_node_id ( ) , & reestablish_1[ 0 ] ) ;
446
471
let bs_resp = handle_chan_reestablish_msgs ! ( nodes[ 1 ] , nodes[ 0 ] ) ;
447
472
0 commit comments