Skip to content

Commit 45675ed

Browse files
committed
Allow async sigs during channel setup
Creates and manages an explicit `HolderCommitment` type to deal with managing the current and next commitment points.
1 parent 9943fb1 commit 45675ed

5 files changed

Lines changed: 420 additions & 226 deletions

File tree

lightning/src/ln/async_signer_tests.rs

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::ln::msgs;
1818
use crate::ln::msgs::ChannelMessageHandler;
1919
use crate::ln::channelmanager::{PaymentId, RAACommitmentOrder, RecipientOnionFields};
2020
use crate::util::ser::Writeable;
21-
use crate::util::test_channel_signer::ops;
21+
use crate::util::test_channel_signer::{EnforcementState, ops};
2222
use crate::util::test_utils;
2323

2424
/// Helper to run operations with a simulated asynchronous signer.
@@ -49,6 +49,55 @@ pub fn with_async_signer<'a, DoFn, T>(node: &Node, peer_id: &PublicKey, channel_
4949
res
5050
}
5151

52+
#[test]
53+
fn test_open_channel() {
54+
// Simulate acquiring the signature for `funding_created` asynchronously.
55+
let chanmon_cfgs = create_chanmon_cfgs(2);
56+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
57+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
58+
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
59+
60+
// Open an outbound channel simulating an async signer.
61+
let channel_id_0 = EnforcementState::with_default_unavailable(
62+
ops::GET_PER_COMMITMENT_POINT,
63+
|| nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100000, 10001, 42, None, None)
64+
).expect("Failed to create channel");
65+
66+
{
67+
let msgs = nodes[0].node.get_and_clear_pending_msg_events();
68+
assert!(msgs.is_empty(), "Expected no message events; got {:?}", msgs);
69+
}
70+
71+
nodes[0].set_channel_signer_ops_available(&nodes[1].node.get_our_node_id(), &channel_id_0, ops::GET_PER_COMMITMENT_POINT, true);
72+
nodes[0].node.signer_unblocked(None);
73+
74+
// nodes[0] --- open_channel --> nodes[1]
75+
let mut open_chan_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id());
76+
77+
// Handle an inbound channel simulating an async signer.
78+
EnforcementState::with_default_unavailable(
79+
ops::GET_PER_COMMITMENT_POINT,
80+
|| nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_chan_msg)
81+
);
82+
83+
{
84+
let msgs = nodes[1].node.get_and_clear_pending_msg_events();
85+
assert!(msgs.is_empty(), "Expected no message events; got {:?}", msgs);
86+
}
87+
88+
let channel_id_1 = {
89+
let channels = nodes[1].node.list_channels();
90+
assert_eq!(channels.len(), 1, "expected one channel, not {}", channels.len());
91+
channels[0].channel_id
92+
};
93+
94+
nodes[1].set_channel_signer_ops_available(&nodes[0].node.get_our_node_id(), &channel_id_1, ops::GET_PER_COMMITMENT_POINT, true);
95+
nodes[1].node.signer_unblocked(None);
96+
97+
// nodes[0] <-- accept_channel --- nodes[1]
98+
get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id());
99+
}
100+
52101
#[cfg(test)]
53102
fn do_test_funding_created(masks: &Vec<u32>) {
54103
// Simulate acquiring the signature for `funding_created` asynchronously.

0 commit comments

Comments
 (0)