@@ -24,7 +24,59 @@ use crate::ln::channelmanager::{PaymentId, RAACommitmentOrder, RecipientOnionFie
2424use crate :: util:: test_channel_signer:: SignerOp ;
2525
2626#[ 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 > ) {
2880 // Simulate acquiring the signature for `funding_created` asynchronously.
2981 let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
3082 let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
@@ -45,7 +97,9 @@ fn test_async_commitment_signature_for_funding_created() {
4597 // But! Let's make node[0]'s signer be unavailable: we should *not* broadcast a funding_created
4698 // message...
4799 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+ }
49103 nodes[ 0 ] . node . funding_transaction_generated ( & temporary_channel_id, & nodes[ 1 ] . node . get_our_node_id ( ) , tx. clone ( ) ) . unwrap ( ) ;
50104 check_added_monitors ( & nodes[ 0 ] , 0 ) ;
51105
@@ -59,8 +113,10 @@ fn test_async_commitment_signature_for_funding_created() {
59113 channels[ 0 ] . channel_id
60114 } ;
61115
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+ }
64120
65121 let mut funding_created_msg = get_event_msg ! ( nodes[ 0 ] , MessageSendEvent :: SendFundingCreated , nodes[ 1 ] . node. get_our_node_id( ) ) ;
66122 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() {
75131}
76132
77133#[ 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 > ) {
79140 // Simulate acquiring the signature for `funding_signed` asynchronously.
80141 let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
81142 let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
@@ -100,7 +161,9 @@ fn test_async_commitment_signature_for_funding_signed() {
100161
101162 // Now let's make node[1]'s signer be unavailable while handling the `funding_created`. It should
102163 // *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+ }
104167 nodes[ 1 ] . node . handle_funding_created ( & nodes[ 0 ] . node . get_our_node_id ( ) , & funding_created_msg) ;
105168 check_added_monitors ( & nodes[ 1 ] , 1 ) ;
106169
@@ -113,8 +176,10 @@ fn test_async_commitment_signature_for_funding_signed() {
113176 assert_eq ! ( channels. len( ) , 1 , "expected one channel, not {}" , channels. len( ) ) ;
114177 channels[ 0 ] . channel_id
115178 } ;
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+ }
118183
119184 expect_channel_pending_event ( & nodes[ 1 ] , & nodes[ 0 ] . node . get_our_node_id ( ) ) ;
120185
@@ -189,7 +254,12 @@ fn do_test_async_commitment_signature_for_commitment_signed_revoke_and_ack(test_
189254}
190255
191256#[ 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 > ) {
193263 // Simulate acquiring the signature for `funding_signed` asynchronously for a zero-conf channel.
194264 let mut manually_accept_config = test_default_channel_config ( ) ;
195265 manually_accept_config. manually_accept_inbound_channels = true ;
@@ -232,7 +302,9 @@ fn test_async_commitment_signature_for_funding_signed_0conf() {
232302
233303 // Now let's make node[1]'s signer be unavailable while handling the `funding_created`. It should
234304 // *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+ }
236308 nodes[ 1 ] . node . handle_funding_created ( & nodes[ 0 ] . node . get_our_node_id ( ) , & funding_created_msg) ;
237309 check_added_monitors ( & nodes[ 1 ] , 1 ) ;
238310
@@ -247,8 +319,10 @@ fn test_async_commitment_signature_for_funding_signed_0conf() {
247319 } ;
248320
249321 // 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+ }
252326
253327 let ( funding_signed, channel_ready_1) = {
254328 let events = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
0 commit comments