Skip to content

Commit

Permalink
Allow async sigs during channel setup
Browse files Browse the repository at this point in the history
Creates and manages an explicit `HolderCommitment` type to deal with managing
the current and next commitment points.
  • Loading branch information
waterson committed Jan 27, 2024
1 parent 1bea55f commit 8db91d7
Show file tree
Hide file tree
Showing 5 changed files with 436 additions and 229 deletions.
52 changes: 51 additions & 1 deletion lightning/src/ln/async_signer_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::ln::msgs;
use crate::ln::msgs::ChannelMessageHandler;
use crate::ln::channelmanager::{PaymentId, RAACommitmentOrder, RecipientOnionFields};
use crate::util::ser::Writeable;
use crate::util::test_channel_signer::ops;
use crate::util::test_channel_signer::{EnforcementState, ops};
use crate::util::test_utils;

/// Helper to run operations with a simulated asynchronous signer.
Expand Down Expand Up @@ -49,6 +49,56 @@ pub fn with_async_signer<'a, DoFn, T>(node: &Node, peer_id: &PublicKey, channel_
res
}

#[cfg(feature = "std")]
#[test]
fn test_open_channel() {
// Simulate acquiring the signature for `funding_created` asynchronously.
let chanmon_cfgs = create_chanmon_cfgs(2);
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);

// Open an outbound channel simulating an async signer.
let channel_id_0 = EnforcementState::with_default_unavailable(
ops::GET_PER_COMMITMENT_POINT,
|| nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100000, 10001, 42, None, None)
).expect("Failed to create channel");

{
let msgs = nodes[0].node.get_and_clear_pending_msg_events();
assert!(msgs.is_empty(), "Expected no message events; got {:?}", msgs);
}

nodes[0].set_channel_signer_ops_available(&nodes[1].node.get_our_node_id(), &channel_id_0, ops::GET_PER_COMMITMENT_POINT, true);
nodes[0].node.signer_unblocked(None);

// nodes[0] --- open_channel --> nodes[1]
let mut open_chan_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id());

// Handle an inbound channel simulating an async signer.
EnforcementState::with_default_unavailable(
ops::GET_PER_COMMITMENT_POINT,
|| nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_chan_msg)
);

{
let msgs = nodes[1].node.get_and_clear_pending_msg_events();
assert!(msgs.is_empty(), "Expected no message events; got {:?}", msgs);
}

let channel_id_1 = {
let channels = nodes[1].node.list_channels();
assert_eq!(channels.len(), 1, "expected one channel, not {}", channels.len());
channels[0].channel_id
};

nodes[1].set_channel_signer_ops_available(&nodes[0].node.get_our_node_id(), &channel_id_1, ops::GET_PER_COMMITMENT_POINT, true);
nodes[1].node.signer_unblocked(None);

// nodes[0] <-- accept_channel --- nodes[1]
get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id());
}

#[cfg(test)]
fn do_test_funding_created(masks: &Vec<u32>) {
// Simulate acquiring the signature for `funding_created` asynchronously.
Expand Down
Loading

0 comments on commit 8db91d7

Please sign in to comment.