@@ -54,7 +54,7 @@ fn test_async_commitment_signature_for_funding_created() {
54
54
assert_eq ! ( channels. len( ) , 1 , "expected one channel, not {}" , channels. len( ) ) ;
55
55
channels[ 0 ] . channel_id
56
56
} ;
57
-
57
+
58
58
nodes[ 0 ] . set_channel_signer_available ( & nodes[ 1 ] . node . get_our_node_id ( ) , & chan_id, true ) ;
59
59
nodes[ 0 ] . node . signer_unblocked ( Some ( ( nodes[ 1 ] . node . get_our_node_id ( ) , chan_id) ) ) ;
60
60
@@ -79,7 +79,7 @@ fn test_async_commitment_signature_for_funding_signed() {
79
79
let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
80
80
81
81
nodes[ 0 ] . node . create_channel ( nodes[ 1 ] . node . get_our_node_id ( ) , 100000 , 10001 , 42 , None ) . unwrap ( ) ;
82
-
82
+
83
83
// nodes[0] --- open_channel --> nodes[1]
84
84
let mut open_chan_msg = get_event_msg ! ( nodes[ 0 ] , MessageSendEvent :: SendOpenChannel , nodes[ 1 ] . node. get_our_node_id( ) ) ;
85
85
nodes[ 1 ] . node . handle_open_channel ( & nodes[ 0 ] . node . get_our_node_id ( ) , & open_chan_msg) ;
@@ -115,7 +115,7 @@ fn test_async_commitment_signature_for_funding_signed() {
115
115
} ;
116
116
nodes[ 1 ] . set_channel_signer_available ( & nodes[ 0 ] . node . get_our_node_id ( ) , & chan_id, true ) ;
117
117
nodes[ 1 ] . node . signer_unblocked ( Some ( ( nodes[ 0 ] . node . get_our_node_id ( ) , chan_id) ) ) ;
118
-
118
+
119
119
expect_channel_pending_event ( & nodes[ 1 ] , & nodes[ 0 ] . node . get_our_node_id ( ) ) ;
120
120
121
121
// nodes[0] <-- funding_signed --- nodes[1]
@@ -141,7 +141,7 @@ fn test_async_commitment_signature_for_commitment_signed() {
141
141
assert_eq ! ( n, 1 , "expected one channel, not {}" , n) ;
142
142
* chan_ids[ 0 ]
143
143
} ;
144
-
144
+
145
145
// Send a payment.
146
146
let src = & nodes[ 0 ] ;
147
147
let dst = & nodes[ 1 ] ;
@@ -168,7 +168,7 @@ fn test_async_commitment_signature_for_commitment_signed() {
168
168
check_added_monitors ( dst, 1 ) ;
169
169
170
170
get_event_msg ! ( dst, MessageSendEvent :: SendRevokeAndACK , src. node. get_our_node_id( ) ) ;
171
-
171
+
172
172
// Mark dst's signer as available and retry: we now expect to see dst's `commitment_signed`.
173
173
dst. set_channel_signer_available ( & src. node . get_our_node_id ( ) , & chan_id, true ) ;
174
174
dst. node . signer_unblocked ( Some ( ( src. node . get_our_node_id ( ) , chan_id) ) ) ;
@@ -183,3 +183,70 @@ fn test_async_commitment_signature_for_commitment_signed() {
183
183
} ;
184
184
}
185
185
186
+ #[ test]
187
+ fn test_async_commitment_signature_for_peer_disconnect ( ) {
188
+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
189
+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
190
+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
191
+ let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
192
+ create_announced_chan_between_nodes ( & nodes, 0 , 1 ) ;
193
+
194
+ let chan_id = {
195
+ let per_peer_state = nodes[ 0 ] . node . per_peer_state . read ( ) . unwrap ( ) ;
196
+ let chan_lock = per_peer_state. get ( & nodes[ 1 ] . node . get_our_node_id ( ) ) . unwrap ( ) . lock ( ) . unwrap ( ) ;
197
+ let chan_ids = chan_lock. channel_by_id . keys ( ) . collect :: < Vec < _ > > ( ) ;
198
+ let n = chan_ids. len ( ) ;
199
+ assert_eq ! ( n, 1 , "expected one channel, not {}" , n) ;
200
+ * chan_ids[ 0 ]
201
+ } ;
202
+
203
+ // Send a payment.
204
+ let src = & nodes[ 0 ] ;
205
+ let dst = & nodes[ 1 ] ;
206
+ let ( route, our_payment_hash, _our_payment_preimage, our_payment_secret) = get_route_and_payment_hash ! ( src, dst, 8000000 ) ;
207
+ src. node . send_payment_with_route ( & route, our_payment_hash,
208
+ RecipientOnionFields :: secret_only ( our_payment_secret) , PaymentId ( our_payment_hash. 0 ) ) . unwrap ( ) ;
209
+ check_added_monitors ! ( src, 1 ) ;
210
+
211
+ // Pass the payment along the route.
212
+ let payment_event = {
213
+ let mut events = src. node . get_and_clear_pending_msg_events ( ) ;
214
+ assert_eq ! ( events. len( ) , 1 ) ;
215
+ SendEvent :: from_event ( events. remove ( 0 ) )
216
+ } ;
217
+ assert_eq ! ( payment_event. node_id, dst. node. get_our_node_id( ) ) ;
218
+ assert_eq ! ( payment_event. msgs. len( ) , 1 ) ;
219
+
220
+ dst. node . handle_update_add_htlc ( & src. node . get_our_node_id ( ) , & payment_event. msgs [ 0 ] ) ;
221
+
222
+ // Mark dst's signer as unavailable and handle src's commitment_signed: while dst won't yet have a
223
+ // `commitment_signed` of its own to offer, it should publish a `revoke_and_ack`.
224
+ dst. set_channel_signer_available ( & src. node . get_our_node_id ( ) , & chan_id, false ) ;
225
+ dst. node . handle_commitment_signed ( & src. node . get_our_node_id ( ) , & payment_event. commitment_msg ) ;
226
+ check_added_monitors ( dst, 1 ) ;
227
+
228
+ get_event_msg ! ( dst, MessageSendEvent :: SendRevokeAndACK , src. node. get_our_node_id( ) ) ;
229
+
230
+ // Now disconnect and reconnect the peers.
231
+ src. node . peer_disconnected ( & dst. node . get_our_node_id ( ) ) ;
232
+ dst. node . peer_disconnected ( & src. node . get_our_node_id ( ) ) ;
233
+ let mut reconnect_args = ReconnectArgs :: new ( & nodes[ 0 ] , & nodes[ 1 ] ) ;
234
+ reconnect_args. send_channel_ready = ( false , false ) ;
235
+ reconnect_args. pending_raa = ( true , false ) ;
236
+ reconnect_nodes ( reconnect_args) ;
237
+
238
+ // Mark dst's signer as available and retry: we now expect to see dst's `commitment_signed`.
239
+ dst. set_channel_signer_available ( & src. node . get_our_node_id ( ) , & chan_id, true ) ;
240
+ dst. node . signer_unblocked ( Some ( ( src. node . get_our_node_id ( ) , chan_id) ) ) ;
241
+
242
+ {
243
+ let events = dst. node . get_and_clear_pending_msg_events ( ) ;
244
+ let n = events. len ( ) ;
245
+ assert_eq ! ( n, 1 , "expected one message, got {}" , n) ;
246
+ if let MessageSendEvent :: UpdateHTLCs { ref node_id, .. } = events[ 0 ] {
247
+ assert_eq ! ( node_id, & src. node. get_our_node_id( ) ) ;
248
+ } else {
249
+ panic ! ( "expected UpdateHTLCs message, not {:?}" , events[ 0 ] ) ;
250
+ } ;
251
+ }
252
+ }
0 commit comments