@@ -189,3 +189,70 @@ fn test_async_commitment_signature_for_commitment_signed() {
189189 } ;
190190}
191191
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