From cd73d118b591ed15a27536191bcf7124b5bbfb4f Mon Sep 17 00:00:00 2001 From: Alec Chen Date: Tue, 2 Jul 2024 16:43:15 -0700 Subject: [PATCH] f - test enabling signer before monitor update completes, no double send --- lightning/src/ln/async_signer_tests.rs | 55 +++++++++++++++++++------- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/lightning/src/ln/async_signer_tests.rs b/lightning/src/ln/async_signer_tests.rs index a21f2fd3978..fab1a3cab8e 100644 --- a/lightning/src/ln/async_signer_tests.rs +++ b/lightning/src/ln/async_signer_tests.rs @@ -332,15 +332,20 @@ fn test_async_commitment_signature_for_peer_disconnect() { #[test] fn test_async_commitment_signature_ordering_reestablish() { - do_test_async_commitment_signature_ordering(false); + do_test_async_commitment_signature_ordering(false, false); } #[test] fn test_async_commitment_signature_ordering_monitor_restored() { - do_test_async_commitment_signature_ordering(true); + do_test_async_commitment_signature_ordering(true, false); } -fn do_test_async_commitment_signature_ordering(monitor_update_failure: bool) { +#[test] +fn test_async_commitment_signature_ordering_monitor_restored_signer_restored_early() { + do_test_async_commitment_signature_ordering(true, true); +} + +fn do_test_async_commitment_signature_ordering(monitor_update_failure: bool, enable_signer_before_monitor_completion: bool) { // Across disconnects we may end up in a situation where we need to send a // commitment_signed and then revoke_and_ack. We need to make sure that if // 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) { assert!(as_resp.1.is_none()); assert!(as_resp.2.is_none()); - if monitor_update_failure { + let as_resp = if monitor_update_failure && enable_signer_before_monitor_completion { + nodes[0].enable_channel_signer_op(&nodes[1].node.get_our_node_id(), &chan_id, SignerOp::SignCounterpartyCommitment); + chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::Completed); let (outpoint, latest_update, _) = nodes[0].chain_monitor.latest_monitor_update_id.lock().unwrap().get(&chan_id).unwrap().clone(); nodes[0].chain_monitor.chain_monitor.force_channel_monitor_updated(outpoint, latest_update); check_added_monitors!(nodes[0], 0); - } - // Make sure that on signer_unblocked we have the same behavior (even though RAA is ready, - // we don't send CS yet). - nodes[0].node.signer_unblocked(Some((nodes[1].node.get_our_node_id(), chan_id))); - let as_resp = handle_chan_reestablish_msgs!(nodes[0], nodes[1]); - assert!(as_resp.0.is_none()); - assert!(as_resp.1.is_none()); - assert!(as_resp.2.is_none()); + // We should send the CS now, and not send it again on `signer_unblocked`. + let as_resp = handle_chan_reestablish_msgs!(nodes[0], nodes[1]); - nodes[0].enable_channel_signer_op(&nodes[1].node.get_our_node_id(), &chan_id, SignerOp::SignCounterpartyCommitment); - nodes[0].node.signer_unblocked(Some((nodes[1].node.get_our_node_id(), chan_id))); + nodes[0].node.signer_unblocked(Some((nodes[1].node.get_our_node_id(), chan_id))); + let as_resp_empty = handle_chan_reestablish_msgs!(nodes[0], nodes[1]); + assert!(as_resp_empty.0.is_none()); + assert!(as_resp_empty.1.is_none()); + assert!(as_resp_empty.2.is_none()); + as_resp + } else { + if monitor_update_failure { + chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::Completed); + let (outpoint, latest_update, _) = nodes[0].chain_monitor.latest_monitor_update_id.lock().unwrap().get(&chan_id).unwrap().clone(); + nodes[0].chain_monitor.chain_monitor.force_channel_monitor_updated(outpoint, latest_update); + check_added_monitors!(nodes[0], 0); + } + + // Make sure that on signer_unblocked we have the same behavior (even though RAA is ready, + // we don't send CS yet). + nodes[0].node.signer_unblocked(Some((nodes[1].node.get_our_node_id(), chan_id))); + let as_resp_empty = handle_chan_reestablish_msgs!(nodes[0], nodes[1]); + assert!(as_resp_empty.0.is_none()); + assert!(as_resp_empty.1.is_none()); + assert!(as_resp_empty.2.is_none()); + + nodes[0].enable_channel_signer_op(&nodes[1].node.get_our_node_id(), &chan_id, SignerOp::SignCounterpartyCommitment); + nodes[0].node.signer_unblocked(Some((nodes[1].node.get_our_node_id(), chan_id))); + let as_resp = handle_chan_reestablish_msgs!(nodes[0], nodes[1]); + as_resp + }; - let as_resp = handle_chan_reestablish_msgs!(nodes[0], nodes[1]); nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &reestablish_1[0]); let bs_resp = handle_chan_reestablish_msgs!(nodes[1], nodes[0]);