Skip to content

Commit

Permalink
f - test enabling signer before monitor update completes, no double send
Browse files Browse the repository at this point in the history
  • Loading branch information
alecchendev committed Jul 3, 2024
1 parent de98c84 commit cd73d11
Showing 1 changed file with 40 additions and 15 deletions.
55 changes: 40 additions & 15 deletions lightning/src/ln/async_signer_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]);

Expand Down

0 comments on commit cd73d11

Please sign in to comment.