@@ -24,7 +24,59 @@ use crate::ln::channelmanager::{PaymentId, RAACommitmentOrder, RecipientOnionFie
24
24
use crate :: util:: test_channel_signer:: SignerOp ;
25
25
26
26
#[ test]
27
- fn test_async_commitment_signature_for_funding_created ( ) {
27
+ fn test_open_channel ( ) {
28
+ // Simulate acquiring the signature for `funding_created` asynchronously.
29
+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
30
+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
31
+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
32
+ let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
33
+
34
+ // Open an outbound channel simulating an async signer.
35
+ let channel_value_satoshis = 100000 ;
36
+ let user_channel_id = 42 ;
37
+ nodes[ 0 ] . disable_next_channel_signer_op ( SignerOp :: GetPerCommitmentPoint ) ;
38
+ let channel_id_0 = nodes[ 0 ] . node . create_channel ( nodes[ 1 ] . node . get_our_node_id ( ) , channel_value_satoshis, 10001 , user_channel_id, None , None ) . unwrap ( ) ;
39
+
40
+ {
41
+ let msgs = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
42
+ assert ! ( msgs. is_empty( ) , "Expected no message events; got {:?}" , msgs) ;
43
+ }
44
+
45
+ nodes[ 0 ] . enable_channel_signer_op ( & nodes[ 1 ] . node . get_our_node_id ( ) , & channel_id_0, SignerOp :: GetPerCommitmentPoint ) ;
46
+ nodes[ 0 ] . node . signer_unblocked ( None ) ;
47
+
48
+ // nodes[0] --- open_channel --> nodes[1]
49
+ let mut open_chan_msg = get_event_msg ! ( nodes[ 0 ] , MessageSendEvent :: SendOpenChannel , nodes[ 1 ] . node. get_our_node_id( ) ) ;
50
+
51
+ // Handle an inbound channel simulating an async signer.
52
+ nodes[ 1 ] . disable_next_channel_signer_op ( SignerOp :: GetPerCommitmentPoint ) ;
53
+ nodes[ 1 ] . node . handle_open_channel ( & nodes[ 0 ] . node . get_our_node_id ( ) , & open_chan_msg) ;
54
+
55
+ {
56
+ let msgs = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
57
+ assert ! ( msgs. is_empty( ) , "Expected no message events; got {:?}" , msgs) ;
58
+ }
59
+
60
+ let channel_id_1 = {
61
+ let channels = nodes[ 1 ] . node . list_channels ( ) ;
62
+ assert_eq ! ( channels. len( ) , 1 , "expected one channel, not {}" , channels. len( ) ) ;
63
+ channels[ 0 ] . channel_id
64
+ } ;
65
+
66
+ nodes[ 1 ] . enable_channel_signer_op ( & nodes[ 0 ] . node . get_our_node_id ( ) , & channel_id_1, SignerOp :: GetPerCommitmentPoint ) ;
67
+ nodes[ 1 ] . node . signer_unblocked ( None ) ;
68
+
69
+ // nodes[0] <-- accept_channel --- nodes[1]
70
+ get_event_msg ! ( nodes[ 1 ] , MessageSendEvent :: SendAcceptChannel , nodes[ 0 ] . node. get_our_node_id( ) ) ;
71
+ }
72
+
73
+ #[ test]
74
+ fn test_funding_created ( ) {
75
+ do_test_funding_created ( vec ! [ SignerOp :: SignCounterpartyCommitment , SignerOp :: GetPerCommitmentPoint ] ) ;
76
+ do_test_funding_created ( vec ! [ SignerOp :: GetPerCommitmentPoint , SignerOp :: SignCounterpartyCommitment ] ) ;
77
+ }
78
+
79
+ fn do_test_funding_created ( signer_ops : Vec < SignerOp > ) {
28
80
// Simulate acquiring the signature for `funding_created` asynchronously.
29
81
let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
30
82
let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
@@ -45,7 +97,9 @@ fn test_async_commitment_signature_for_funding_created() {
45
97
// But! Let's make node[0]'s signer be unavailable: we should *not* broadcast a funding_created
46
98
// message...
47
99
let ( temporary_channel_id, tx, _) = create_funding_transaction ( & nodes[ 0 ] , & nodes[ 1 ] . node . get_our_node_id ( ) , 100000 , 42 ) ;
48
- nodes[ 0 ] . disable_channel_signer_op ( & nodes[ 1 ] . node . get_our_node_id ( ) , & temporary_channel_id, SignerOp :: SignCounterpartyCommitment ) ;
100
+ for op in signer_ops. iter ( ) {
101
+ nodes[ 0 ] . disable_channel_signer_op ( & nodes[ 1 ] . node . get_our_node_id ( ) , & temporary_channel_id, * op) ;
102
+ }
49
103
nodes[ 0 ] . node . funding_transaction_generated ( & temporary_channel_id, & nodes[ 1 ] . node . get_our_node_id ( ) , tx. clone ( ) ) . unwrap ( ) ;
50
104
check_added_monitors ( & nodes[ 0 ] , 0 ) ;
51
105
@@ -59,8 +113,10 @@ fn test_async_commitment_signature_for_funding_created() {
59
113
channels[ 0 ] . channel_id
60
114
} ;
61
115
62
- nodes[ 0 ] . enable_channel_signer_op ( & nodes[ 1 ] . node . get_our_node_id ( ) , & chan_id, SignerOp :: SignCounterpartyCommitment ) ;
63
- nodes[ 0 ] . node . signer_unblocked ( Some ( ( nodes[ 1 ] . node . get_our_node_id ( ) , chan_id) ) ) ;
116
+ for op in signer_ops. iter ( ) {
117
+ nodes[ 0 ] . enable_channel_signer_op ( & nodes[ 1 ] . node . get_our_node_id ( ) , & chan_id, * op) ;
118
+ nodes[ 0 ] . node . signer_unblocked ( Some ( ( nodes[ 1 ] . node . get_our_node_id ( ) , chan_id) ) ) ;
119
+ }
64
120
65
121
let mut funding_created_msg = get_event_msg ! ( nodes[ 0 ] , MessageSendEvent :: SendFundingCreated , nodes[ 1 ] . node. get_our_node_id( ) ) ;
66
122
nodes[ 1 ] . node . handle_funding_created ( & nodes[ 0 ] . node . get_our_node_id ( ) , & funding_created_msg) ;
@@ -75,7 +131,12 @@ fn test_async_commitment_signature_for_funding_created() {
75
131
}
76
132
77
133
#[ test]
78
- fn test_async_commitment_signature_for_funding_signed ( ) {
134
+ fn test_funding_signed ( ) {
135
+ do_test_funding_signed ( vec ! [ SignerOp :: SignCounterpartyCommitment , SignerOp :: GetPerCommitmentPoint ] ) ;
136
+ do_test_funding_signed ( vec ! [ SignerOp :: GetPerCommitmentPoint , SignerOp :: SignCounterpartyCommitment ] ) ;
137
+ }
138
+
139
+ fn do_test_funding_signed ( signer_ops : Vec < SignerOp > ) {
79
140
// Simulate acquiring the signature for `funding_signed` asynchronously.
80
141
let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
81
142
let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
@@ -100,7 +161,9 @@ fn test_async_commitment_signature_for_funding_signed() {
100
161
101
162
// Now let's make node[1]'s signer be unavailable while handling the `funding_created`. It should
102
163
// *not* broadcast a `funding_signed`...
103
- nodes[ 1 ] . disable_channel_signer_op ( & nodes[ 0 ] . node . get_our_node_id ( ) , & temporary_channel_id, SignerOp :: SignCounterpartyCommitment ) ;
164
+ for op in signer_ops. iter ( ) {
165
+ nodes[ 1 ] . disable_channel_signer_op ( & nodes[ 0 ] . node . get_our_node_id ( ) , & temporary_channel_id, * op) ;
166
+ }
104
167
nodes[ 1 ] . node . handle_funding_created ( & nodes[ 0 ] . node . get_our_node_id ( ) , & funding_created_msg) ;
105
168
check_added_monitors ( & nodes[ 1 ] , 1 ) ;
106
169
@@ -113,8 +176,10 @@ fn test_async_commitment_signature_for_funding_signed() {
113
176
assert_eq ! ( channels. len( ) , 1 , "expected one channel, not {}" , channels. len( ) ) ;
114
177
channels[ 0 ] . channel_id
115
178
} ;
116
- nodes[ 1 ] . enable_channel_signer_op ( & nodes[ 0 ] . node . get_our_node_id ( ) , & chan_id, SignerOp :: SignCounterpartyCommitment ) ;
117
- nodes[ 1 ] . node . signer_unblocked ( Some ( ( nodes[ 0 ] . node . get_our_node_id ( ) , chan_id) ) ) ;
179
+ for op in signer_ops. iter ( ) {
180
+ nodes[ 1 ] . enable_channel_signer_op ( & nodes[ 0 ] . node . get_our_node_id ( ) , & chan_id, * op) ;
181
+ nodes[ 1 ] . node . signer_unblocked ( Some ( ( nodes[ 0 ] . node . get_our_node_id ( ) , chan_id) ) ) ;
182
+ }
118
183
119
184
expect_channel_pending_event ( & nodes[ 1 ] , & nodes[ 0 ] . node . get_our_node_id ( ) ) ;
120
185
@@ -189,7 +254,12 @@ fn do_test_async_commitment_signature_for_commitment_signed_revoke_and_ack(test_
189
254
}
190
255
191
256
#[ test]
192
- fn test_async_commitment_signature_for_funding_signed_0conf ( ) {
257
+ fn test_funding_signed_0conf ( ) {
258
+ do_test_funding_signed_0conf ( vec ! [ SignerOp :: SignCounterpartyCommitment , SignerOp :: SignCounterpartyCommitment ] ) ;
259
+ do_test_funding_signed_0conf ( vec ! [ SignerOp :: SignCounterpartyCommitment , SignerOp :: GetPerCommitmentPoint ] ) ;
260
+ }
261
+
262
+ fn do_test_funding_signed_0conf ( signer_ops : Vec < SignerOp > ) {
193
263
// Simulate acquiring the signature for `funding_signed` asynchronously for a zero-conf channel.
194
264
let mut manually_accept_config = test_default_channel_config ( ) ;
195
265
manually_accept_config. manually_accept_inbound_channels = true ;
@@ -232,7 +302,9 @@ fn test_async_commitment_signature_for_funding_signed_0conf() {
232
302
233
303
// Now let's make node[1]'s signer be unavailable while handling the `funding_created`. It should
234
304
// *not* broadcast a `funding_signed`...
235
- nodes[ 1 ] . disable_channel_signer_op ( & nodes[ 0 ] . node . get_our_node_id ( ) , & temporary_channel_id, SignerOp :: SignCounterpartyCommitment ) ;
305
+ for op in signer_ops. iter ( ) {
306
+ nodes[ 1 ] . disable_channel_signer_op ( & nodes[ 0 ] . node . get_our_node_id ( ) , & temporary_channel_id, * op) ;
307
+ }
236
308
nodes[ 1 ] . node . handle_funding_created ( & nodes[ 0 ] . node . get_our_node_id ( ) , & funding_created_msg) ;
237
309
check_added_monitors ( & nodes[ 1 ] , 1 ) ;
238
310
@@ -247,8 +319,10 @@ fn test_async_commitment_signature_for_funding_signed_0conf() {
247
319
} ;
248
320
249
321
// At this point, we basically expect the channel to open like a normal zero-conf channel.
250
- nodes[ 1 ] . enable_channel_signer_op ( & nodes[ 0 ] . node . get_our_node_id ( ) , & chan_id, SignerOp :: SignCounterpartyCommitment ) ;
251
- nodes[ 1 ] . node . signer_unblocked ( Some ( ( nodes[ 0 ] . node . get_our_node_id ( ) , chan_id) ) ) ;
322
+ for op in signer_ops. iter ( ) {
323
+ nodes[ 1 ] . enable_channel_signer_op ( & nodes[ 0 ] . node . get_our_node_id ( ) , & chan_id, * op) ;
324
+ nodes[ 1 ] . node . signer_unblocked ( Some ( ( nodes[ 0 ] . node . get_our_node_id ( ) , chan_id) ) ) ;
325
+ }
252
326
253
327
let ( funding_signed, channel_ready_1) = {
254
328
let events = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
0 commit comments