77// You may not use this file except in accordance with one or both of these
88// licenses.
99
10- //! Tests that test standing up a network of ChannelManagers, creating channels, sending
11- //! payments/messages between them, and often checking the resulting ChannelMonitors are able to
12- //! claim outputs on-chain.
13-
14- use crate :: events:: { Event , MessageSendEvent , MessageSendEventsProvider } ;
10+ use crate :: events:: { MessageSendEvent , MessageSendEventsProvider } ;
1511use crate :: ln:: functional_test_utils:: * ;
1612use crate :: ln:: msgs:: ChannelMessageHandler ;
17- use crate :: util:: config:: { ChannelHandshakeConfig , UserConfig } ;
1813
1914/// Splicing test, simple splice-in flow. Starts with opening a V1 channel first.
2015/// Builds on test_channel_open_simple()
2116#[ test]
2217fn test_v1_splice_in ( ) {
23- // Set up a network of 2 nodes
24- let cfg = UserConfig {
25- channel_handshake_config : ChannelHandshakeConfig { ..Default :: default ( ) } ,
26- ..Default :: default ( )
27- } ;
2818 let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
2919 let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
30- let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ Some ( cfg ) , None ] ) ;
20+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
3121 let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
3222
3323 // Initiator and Acceptor nodes
@@ -41,193 +31,31 @@ fn test_v1_splice_in() {
4131 let push_msat = 0 ;
4232 let channel_reserve_amnt_sat = 1_000 ;
4333
34+ let ( _, _, channel_id, _) = create_announced_chan_between_nodes_with_value (
35+ & nodes,
36+ initiator_node_index,
37+ acceptor_node_index,
38+ channel_value_sat,
39+ push_msat,
40+ ) ;
41+
4442 let expected_funded_channel_id =
4543 "ae3367da2c13bc1ceb86bf56418f62828f7ce9d6bfb15a46af5ba1f1ed8b124f" ;
44+ assert_eq ! ( channel_id. to_string( ) , expected_funded_channel_id) ;
4645
47- // Have initiator_node initiate a channel to acceptor_node with aforementioned parameters
48- let channel_id_temp1 = initiator_node
49- . node
50- . create_channel (
51- acceptor_node. node . get_our_node_id ( ) ,
52- channel_value_sat,
53- push_msat,
54- 42 ,
55- None ,
56- None ,
57- )
58- . unwrap ( ) ;
59-
60- // Extract the channel open message from initiator_node to acceptor_node
61- let open_channel_message = get_event_msg ! (
62- initiator_node,
63- MessageSendEvent :: SendOpenChannel ,
64- acceptor_node. node. get_our_node_id( )
65- ) ;
6646 let expected_initiator_funding_key =
6747 "03c21e841cbc0b48197d060c71e116c185fa0ac281b7d0aa5924f535154437ca3b" ;
68- assert_eq ! (
69- open_channel_message. common_fields. funding_pubkey. to_string( ) ,
70- expected_initiator_funding_key
71- ) ;
72-
73- let _res = acceptor_node
74- . node
75- . handle_open_channel ( initiator_node. node . get_our_node_id ( ) , & open_channel_message. clone ( ) ) ;
76- // Extract the accept channel message from acceptor_node to initiator_node
77- let accept_channel_message = get_event_msg ! (
78- acceptor_node,
79- MessageSendEvent :: SendAcceptChannel ,
80- initiator_node. node. get_our_node_id( )
81- ) ;
8248 let expected_acceptor_funding_key =
8349 "039481c28b904cbe12681e79937373fc76245c1b29871028ae60ba3152162c319b" ;
84- assert_eq ! (
85- accept_channel_message. common_fields. funding_pubkey. to_string( ) ,
86- expected_acceptor_funding_key
87- ) ;
88-
89- let _res = initiator_node. node . handle_accept_channel (
90- acceptor_node. node . get_our_node_id ( ) ,
91- & accept_channel_message. clone ( ) ,
92- ) ;
93- // Note: FundingGenerationReady emitted, checked and used below
94- let ( _channel_id_temp2, funding_tx, _funding_output) = create_funding_transaction (
95- & initiator_node,
96- & acceptor_node. node . get_our_node_id ( ) ,
97- channel_value_sat,
98- 42 ,
99- ) ;
100-
101- // Funding transation created, provide it
102- let _res = initiator_node
103- . node
104- . funding_transaction_generated (
105- channel_id_temp1,
106- acceptor_node. node . get_our_node_id ( ) ,
107- funding_tx. clone ( ) ,
108- )
109- . unwrap ( ) ;
110-
111- let funding_created_message = get_event_msg ! (
112- initiator_node,
113- MessageSendEvent :: SendFundingCreated ,
114- acceptor_node. node. get_our_node_id( )
115- ) ;
116-
117- let _res = acceptor_node
118- . node
119- . handle_funding_created ( initiator_node. node . get_our_node_id ( ) , & funding_created_message) ;
120-
121- assert_eq ! ( initiator_node. node. list_channels( ) . len( ) , 1 ) ;
122- {
123- let channel = & initiator_node. node . list_channels ( ) [ 0 ] ;
124- assert ! ( !channel. is_channel_ready) ;
125- }
126- // do checks on the acceptor node as well (capacity, etc.)
127- assert_eq ! ( acceptor_node. node. list_channels( ) . len( ) , 1 ) ;
128- {
129- let channel = & acceptor_node. node . list_channels ( ) [ 0 ] ;
130- assert ! ( !channel. is_channel_ready) ;
131- }
132-
133- let funding_signed_message = get_event_msg ! (
134- acceptor_node,
135- MessageSendEvent :: SendFundingSigned ,
136- initiator_node. node. get_our_node_id( )
137- ) ;
138- let _res = initiator_node
139- . node
140- . handle_funding_signed ( acceptor_node. node . get_our_node_id ( ) , & funding_signed_message) ;
141- // Take new channel ID
142- let channel_id2 = funding_signed_message. channel_id ;
143- assert_eq ! ( channel_id2. to_string( ) , expected_funded_channel_id) ;
144-
145- // Check that funding transaction has been broadcasted
146- assert_eq ! (
147- chanmon_cfgs[ initiator_node_index] . tx_broadcaster. txn_broadcasted. lock( ) . unwrap( ) . len( ) ,
148- 1
149- ) ;
150- let broadcasted_funding_tx =
151- chanmon_cfgs[ initiator_node_index] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) [ 0 ]
152- . clone ( ) ;
153-
154- check_added_monitors ! ( initiator_node, 1 ) ;
155- let _ev = get_event ! ( initiator_node, Event :: ChannelPending ) ;
156- check_added_monitors ! ( acceptor_node, 1 ) ;
157- let _ev = get_event ! ( acceptor_node, Event :: ChannelPending ) ;
158-
159- // Simulate confirmation of the funding tx
160- confirm_transaction ( & initiator_node, & broadcasted_funding_tx) ;
161- let channel_ready_message = get_event_msg ! (
162- initiator_node,
163- MessageSendEvent :: SendChannelReady ,
164- acceptor_node. node. get_our_node_id( )
165- ) ;
166-
167- confirm_transaction ( & acceptor_node, & broadcasted_funding_tx) ;
168- let channel_ready_message2 = get_event_msg ! (
169- acceptor_node,
170- MessageSendEvent :: SendChannelReady ,
171- initiator_node. node. get_our_node_id( )
172- ) ;
173-
174- let _res = acceptor_node
175- . node
176- . handle_channel_ready ( initiator_node. node . get_our_node_id ( ) , & channel_ready_message) ;
177- let _ev = get_event ! ( acceptor_node, Event :: ChannelReady ) ;
178- let _channel_update = get_event_msg ! (
179- acceptor_node,
180- MessageSendEvent :: SendChannelUpdate ,
181- initiator_node. node. get_our_node_id( )
182- ) ;
183-
184- let _res = initiator_node
185- . node
186- . handle_channel_ready ( acceptor_node. node . get_our_node_id ( ) , & channel_ready_message2) ;
187- let _ev = get_event ! ( initiator_node, Event :: ChannelReady ) ;
188- let _channel_update = get_event_msg ! (
189- initiator_node,
190- MessageSendEvent :: SendChannelUpdate ,
191- acceptor_node. node. get_our_node_id( )
192- ) ;
193-
194- // check channel capacity and other parameters
195- assert_eq ! ( initiator_node. node. list_channels( ) . len( ) , 1 ) ;
196- {
197- let channel = & initiator_node. node . list_channels ( ) [ 0 ] ;
198- assert_eq ! ( channel. channel_id. to_string( ) , expected_funded_channel_id) ;
199- assert ! ( channel. is_usable) ;
200- assert ! ( channel. is_channel_ready) ;
201- assert_eq ! ( channel. channel_value_satoshis, channel_value_sat) ;
202- assert_eq ! (
203- channel. outbound_capacity_msat,
204- 1000 * ( channel_value_sat - channel_reserve_amnt_sat)
205- ) ;
206- assert_eq ! ( channel. funding_txo. unwrap( ) . txid, funding_tx. compute_txid( ) ) ;
207- assert_eq ! ( channel. confirmations. unwrap( ) , 10 ) ;
208- }
209- // do checks on the acceptor node as well (capacity, etc.)
210- assert_eq ! ( acceptor_node. node. list_channels( ) . len( ) , 1 ) ;
211- {
212- let channel = & acceptor_node. node . list_channels ( ) [ 0 ] ;
213- assert_eq ! ( channel. channel_id. to_string( ) , expected_funded_channel_id) ;
214- assert ! ( channel. is_usable) ;
215- assert ! ( channel. is_channel_ready) ;
216- assert_eq ! ( channel. channel_value_satoshis, channel_value_sat) ;
217- assert_eq ! ( channel. outbound_capacity_msat, 0 ) ;
218- assert_eq ! ( channel. funding_txo. unwrap( ) . txid, funding_tx. compute_txid( ) ) ;
219- assert_eq ! ( channel. confirmations. unwrap( ) , 10 ) ;
220- }
22150
22251 // ==== Channel is now ready for normal operation
22352
22453 // === Start of Splicing
225- println ! ( "Start of Splicing ..., channel_id {}" , channel_id2 ) ;
54+ println ! ( "Start of Splicing ..., channel_id {}" , channel_id ) ;
22655
22756 // Amount being added to the channel through the splice-in
22857 let splice_in_sats: u64 = 20000 ;
229- let funding_feerate_perkw = 1024 ; // TODO
230- let locktime = 0 ; // TODO
58+ let funding_feerate_per_kw = 1024 ; // TODO
23159
23260 // Create additional inputs
23361 let extra_splice_funding_input_sats = 35_000 ;
@@ -239,12 +67,12 @@ fn test_v1_splice_in() {
23967 let _res = initiator_node
24068 . node
24169 . splice_channel (
242- & channel_id2 ,
70+ & channel_id ,
24371 & acceptor_node. node . get_our_node_id ( ) ,
24472 splice_in_sats as i64 ,
24573 funding_inputs,
246- funding_feerate_perkw ,
247- locktime ,
74+ funding_feerate_per_kw ,
75+ 0 , // locktime
24876 )
24977 . unwrap ( ) ;
25078 // Extract the splice message from node0 to node1
@@ -254,7 +82,7 @@ fn test_v1_splice_in() {
25482 acceptor_node. node. get_our_node_id( )
25583 ) ;
25684 assert_eq ! ( splice_init_msg. funding_contribution_satoshis, splice_in_sats as i64 ) ;
257- assert_eq ! ( splice_init_msg. funding_feerate_perkw, funding_feerate_perkw ) ;
85+ assert_eq ! ( splice_init_msg. funding_feerate_perkw, funding_feerate_per_kw ) ;
25886 assert_eq ! ( splice_init_msg. funding_pubkey. to_string( ) , expected_initiator_funding_key) ;
25987 assert ! ( splice_init_msg. require_confirmed_inputs. is_none( ) ) ;
26088
@@ -309,7 +137,7 @@ fn test_v1_splice_in() {
309137 // TODO(splicing): continue with splice transaction negotiation
310138
311139 // === Close channel, cooperatively
312- initiator_node. node . close_channel ( & channel_id2 , & acceptor_node. node . get_our_node_id ( ) ) . unwrap ( ) ;
140+ initiator_node. node . close_channel ( & channel_id , & acceptor_node. node . get_our_node_id ( ) ) . unwrap ( ) ;
313141 let node0_shutdown_message = get_event_msg ! (
314142 initiator_node,
315143 MessageSendEvent :: SendShutdown ,
0 commit comments