Skip to content

Commit cd73d11

Browse files
committed
f - test enabling signer before monitor update completes, no double send
1 parent de98c84 commit cd73d11

File tree

1 file changed

+40
-15
lines changed

1 file changed

+40
-15
lines changed

lightning/src/ln/async_signer_tests.rs

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -332,15 +332,20 @@ fn test_async_commitment_signature_for_peer_disconnect() {
332332

333333
#[test]
334334
fn test_async_commitment_signature_ordering_reestablish() {
335-
do_test_async_commitment_signature_ordering(false);
335+
do_test_async_commitment_signature_ordering(false, false);
336336
}
337337

338338
#[test]
339339
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);
341341
}
342342

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) {
344349
// Across disconnects we may end up in a situation where we need to send a
345350
// commitment_signed and then revoke_and_ack. We need to make sure that if
346351
// 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) {
423428
assert!(as_resp.1.is_none());
424429
assert!(as_resp.2.is_none());
425430

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+
427434
chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::Completed);
428435
let (outpoint, latest_update, _) = nodes[0].chain_monitor.latest_monitor_update_id.lock().unwrap().get(&chan_id).unwrap().clone();
429436
nodes[0].chain_monitor.chain_monitor.force_channel_monitor_updated(outpoint, latest_update);
430437
check_added_monitors!(nodes[0], 0);
431-
}
432438

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]);
440441

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+
};
443469

444-
let as_resp = handle_chan_reestablish_msgs!(nodes[0], nodes[1]);
445470
nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &reestablish_1[0]);
446471
let bs_resp = handle_chan_reestablish_msgs!(nodes[1], nodes[0]);
447472

0 commit comments

Comments
 (0)