@@ -57,7 +57,7 @@ fn test_async_commitment_signature_for_funding_created() {
57
57
assert_eq ! ( n, 1 , "expected one channel, not {}" , n) ;
58
58
* chan_ids[ 0 ]
59
59
} ;
60
-
60
+
61
61
nodes[ 0 ] . set_channel_signer_available ( & nodes[ 1 ] . node . get_our_node_id ( ) , & chan_id, true ) ;
62
62
nodes[ 0 ] . node . signer_unblocked ( Some ( ( nodes[ 1 ] . node . get_our_node_id ( ) , chan_id) ) ) ;
63
63
@@ -82,7 +82,7 @@ fn test_async_commitment_signature_for_funding_signed() {
82
82
let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
83
83
84
84
nodes[ 0 ] . node . create_channel ( nodes[ 1 ] . node . get_our_node_id ( ) , 100000 , 10001 , 42 , None ) . unwrap ( ) ;
85
-
85
+
86
86
// nodes[0] --- open_channel --> nodes[1]
87
87
let mut open_chan_msg = get_event_msg ! ( nodes[ 0 ] , MessageSendEvent :: SendOpenChannel , nodes[ 1 ] . node. get_our_node_id( ) ) ;
88
88
nodes[ 1 ] . node . handle_open_channel ( & nodes[ 0 ] . node . get_our_node_id ( ) , & open_chan_msg) ;
@@ -121,7 +121,7 @@ fn test_async_commitment_signature_for_funding_signed() {
121
121
} ;
122
122
nodes[ 1 ] . set_channel_signer_available ( & nodes[ 0 ] . node . get_our_node_id ( ) , & chan_id, true ) ;
123
123
nodes[ 1 ] . node . signer_unblocked ( Some ( ( nodes[ 0 ] . node . get_our_node_id ( ) , chan_id) ) ) ;
124
-
124
+
125
125
expect_channel_pending_event ( & nodes[ 1 ] , & nodes[ 0 ] . node . get_our_node_id ( ) ) ;
126
126
127
127
// nodes[0] <-- funding_signed --- nodes[1]
@@ -147,7 +147,7 @@ fn test_async_commitment_signature_for_commitment_signed() {
147
147
assert_eq ! ( n, 1 , "expected one channel, not {}" , n) ;
148
148
* chan_ids[ 0 ]
149
149
} ;
150
-
150
+
151
151
// Send a payment.
152
152
let src = & nodes[ 0 ] ;
153
153
let dst = & nodes[ 1 ] ;
@@ -174,7 +174,7 @@ fn test_async_commitment_signature_for_commitment_signed() {
174
174
check_added_monitors ( dst, 1 ) ;
175
175
176
176
get_event_msg ! ( dst, MessageSendEvent :: SendRevokeAndACK , src. node. get_our_node_id( ) ) ;
177
-
177
+
178
178
// Mark dst's signer as available and retry: we now expect to see dst's `commitment_signed`.
179
179
dst. set_channel_signer_available ( & src. node . get_our_node_id ( ) , & chan_id, true ) ;
180
180
dst. node . signer_unblocked ( Some ( ( src. node . get_our_node_id ( ) , chan_id) ) ) ;
@@ -189,3 +189,70 @@ fn test_async_commitment_signature_for_commitment_signed() {
189
189
} ;
190
190
}
191
191
192
+ #[ test]
193
+ fn test_async_commitment_signature_for_peer_disconnect ( ) {
194
+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
195
+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
196
+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
197
+ let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
198
+ create_announced_chan_between_nodes ( & nodes, 0 , 1 ) ;
199
+
200
+ let chan_id = {
201
+ let per_peer_state = nodes[ 0 ] . node . per_peer_state . read ( ) . unwrap ( ) ;
202
+ let chan_lock = per_peer_state. get ( & nodes[ 1 ] . node . get_our_node_id ( ) ) . unwrap ( ) . lock ( ) . unwrap ( ) ;
203
+ let chan_ids = chan_lock. channel_by_id . keys ( ) . collect :: < Vec < _ > > ( ) ;
204
+ let n = chan_ids. len ( ) ;
205
+ assert_eq ! ( n, 1 , "expected one channel, not {}" , n) ;
206
+ * chan_ids[ 0 ]
207
+ } ;
208
+
209
+ // Send a payment.
210
+ let src = & nodes[ 0 ] ;
211
+ let dst = & nodes[ 1 ] ;
212
+ let ( route, our_payment_hash, _our_payment_preimage, our_payment_secret) = get_route_and_payment_hash ! ( src, dst, 8000000 ) ;
213
+ src. node . send_payment_with_route ( & route, our_payment_hash,
214
+ RecipientOnionFields :: secret_only ( our_payment_secret) , PaymentId ( our_payment_hash. 0 ) ) . unwrap ( ) ;
215
+ check_added_monitors ! ( src, 1 ) ;
216
+
217
+ // Pass the payment along the route.
218
+ let payment_event = {
219
+ let mut events = src. node . get_and_clear_pending_msg_events ( ) ;
220
+ assert_eq ! ( events. len( ) , 1 ) ;
221
+ SendEvent :: from_event ( events. remove ( 0 ) )
222
+ } ;
223
+ assert_eq ! ( payment_event. node_id, dst. node. get_our_node_id( ) ) ;
224
+ assert_eq ! ( payment_event. msgs. len( ) , 1 ) ;
225
+
226
+ dst. node . handle_update_add_htlc ( & src. node . get_our_node_id ( ) , & payment_event. msgs [ 0 ] ) ;
227
+
228
+ // Mark dst's signer as unavailable and handle src's commitment_signed: while dst won't yet have a
229
+ // `commitment_signed` of its own to offer, it should publish a `revoke_and_ack`.
230
+ dst. set_channel_signer_available ( & src. node . get_our_node_id ( ) , & chan_id, false ) ;
231
+ dst. node . handle_commitment_signed ( & src. node . get_our_node_id ( ) , & payment_event. commitment_msg ) ;
232
+ check_added_monitors ( dst, 1 ) ;
233
+
234
+ get_event_msg ! ( dst, MessageSendEvent :: SendRevokeAndACK , src. node. get_our_node_id( ) ) ;
235
+
236
+ // Now disconnect and reconnect the peers.
237
+ src. node . peer_disconnected ( & dst. node . get_our_node_id ( ) ) ;
238
+ dst. node . peer_disconnected ( & src. node . get_our_node_id ( ) ) ;
239
+ let mut reconnect_args = ReconnectArgs :: new ( & nodes[ 0 ] , & nodes[ 1 ] ) ;
240
+ reconnect_args. send_channel_ready = ( false , false ) ;
241
+ reconnect_args. pending_raa = ( true , false ) ;
242
+ reconnect_nodes ( reconnect_args) ;
243
+
244
+ // Mark dst's signer as available and retry: we now expect to see dst's `commitment_signed`.
245
+ dst. set_channel_signer_available ( & src. node . get_our_node_id ( ) , & chan_id, true ) ;
246
+ dst. node . signer_unblocked ( Some ( ( src. node . get_our_node_id ( ) , chan_id) ) ) ;
247
+
248
+ {
249
+ let events = dst. node . get_and_clear_pending_msg_events ( ) ;
250
+ let n = events. len ( ) ;
251
+ assert_eq ! ( n, 1 , "expected one message, got {}" , n) ;
252
+ if let MessageSendEvent :: UpdateHTLCs { ref node_id, ref updates } = events[ 0 ] {
253
+ assert_eq ! ( node_id, & src. node. get_our_node_id( ) ) ;
254
+ } else {
255
+ panic ! ( "expected UpdateHTLCs message, not {:?}" , events[ 0 ] ) ;
256
+ } ;
257
+ }
258
+ }
0 commit comments