@@ -4124,3 +4124,57 @@ def test_anchorspend_using_to_remote(node_factory, bitcoind, anchors):
41244124 'hsmd: Unilateral close output, deriving secrets' ])
41254125
41264126 bitcoind .generate_block (1 , wait_for_mempool = 2 )
4127+
4128+
4129+ @pytest .mark .xfail (strict = True )
4130+ def test_onchain_reestablish_reply (node_factory , bitcoind , executor ):
4131+ l1 , l2 , l3 = node_factory .line_graph (3 , opts = {'may_reconnect' : True ,
4132+ 'dev-no-reconnect' : None })
4133+
4134+ # Make l1 close unilaterally.
4135+ l1 .rpc .disconnect (l2 .info ['id' ], force = True )
4136+ l1 .rpc .close (l2 .info ['id' ], unilateraltimeout = 1 )
4137+
4138+ # l2 doesn't know, reconnection should get REESTABLISH *then* error.
4139+ l2 .rpc .connect (l1 .info ['id' ], 'localhost' , l1 .port )
4140+
4141+ # We should exchange messages
4142+ l2 .daemon .wait_for_logs (["peer_out WIRE_CHANNEL_REESTABLISH" ,
4143+ "peer_in WIRE_CHANNEL_REESTABLISH" ])
4144+ # It should be OK
4145+ l2 .daemon .wait_for_log ("Reconnected, and reestablished." )
4146+
4147+ # Then we get the error, close.
4148+ l2 .daemon .wait_for_log ("peer_in WIRE_ERROR" )
4149+ assert only_one (l2 .rpc .listpeerchannels (l1 .info ['id' ])['channels' ])['state' ] == 'AWAITING_UNILATERAL'
4150+ # Mine it now so we don't confuse the code below.
4151+ bitcoind .generate_block (1 , wait_for_mempool = 1 )
4152+
4153+ # For l2->l2, try:
4154+ # 1. are not in the initial state, and
4155+ # 2. actually onchain.
4156+ l2 .rpc .pay (l3 .rpc .invoice (200000000 , 'test' , 'test' )['bolt11' ])
4157+
4158+ # We block l3 from seeing close, so it will try to reestablish.
4159+ def no_new_blocks (req ):
4160+ return {"error" : "go away" }
4161+ l3 .daemon .rpcproxy .mock_rpc ('getblockhash' , no_new_blocks )
4162+
4163+ l2 .rpc .disconnect (l3 .info ['id' ], force = True )
4164+ l2 .rpc .close (l3 .info ['id' ], unilateraltimeout = 1 )
4165+ bitcoind .generate_block (1 , wait_for_mempool = 1 )
4166+
4167+ wait_for (lambda : only_one (l2 .rpc .listpeerchannels (l3 .info ['id' ])['channels' ])['state' ] == 'ONCHAIN' )
4168+
4169+ # l3 doesn't know, reconnection should get REESTABLISH *then* error.
4170+ l3 .rpc .connect (l2 .info ['id' ], 'localhost' , l2 .port )
4171+
4172+ # We should exchange messages
4173+ l3 .daemon .wait_for_logs (["peer_out WIRE_CHANNEL_REESTABLISH" ,
4174+ "peer_in WIRE_CHANNEL_REESTABLISH" ])
4175+ # It should be OK
4176+ l3 .daemon .wait_for_log ("Reconnected, and reestablished." )
4177+
4178+ # Then we get the error, close.
4179+ l3 .daemon .wait_for_log ("peer_in WIRE_ERROR" )
4180+ assert only_one (l3 .rpc .listpeerchannels (l2 .info ['id' ])['channels' ])['state' ] == 'AWAITING_UNILATERAL'
0 commit comments