MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_funding_reorg_remote_lags

Function test_funding_reorg_remote_lags

tests/test_misc.py:1142–1187  ·  view source on GitHub ↗

Nodes may disagree about short_channel_id before channel announcement

(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

1140@pytest.mark.openchannel('v1')
1141@pytest.mark.openchannel('v2')
1142def test_funding_reorg_remote_lags(node_factory, bitcoind):
1143 """Nodes may disagree about short_channel_id before channel announcement
1144 """
1145 # may_reconnect so channeld will restart; bad gossip can happen due to reorg
1146 opts = {'funding-confirms': 1, 'may_reconnect': True, 'allow_bad_gossip': True,
1147 'allow_warning': True, 'dev-fast-reconnect': None}
1148 l1, l2 = node_factory.line_graph(2, fundchannel=False, opts=opts)
1149 l1.fundwallet(10000000)
1150 sync_blockheight(bitcoind, [l1]) # height 102
1151
1152 l1.rpc.fundchannel(l2.info['id'], "all")
1153 bitcoind.generate_block(5) # heights 103 - 107
1154 l1.wait_channel_active('103x1x0')
1155 l2.wait_channel_active('103x1x0')
1156
1157 # Make l2 temporary blind for blocks > 107
1158 def no_more_blocks(req):
1159 return {"result": None,
1160 "error": {"code": -8, "message": "Block height out of range"}, "id": req['id']}
1161
1162 l2.daemon.rpcproxy.mock_rpc('getblockhash', no_more_blocks)
1163
1164 # Reorg changes short_channel_id 103x1x0 to 104x1x0, l1 sees it, restarts channeld
1165 bitcoind.simple_reorg(103, 1) # heights 103 - 108
1166 # But now it's height 104, we need another block to make it announceable.
1167 bitcoind.generate_block(1)
1168 l1.daemon.wait_for_log(r'Peer transient failure .* short_channel_id changed to 104x1x0 \(was 103x1x0\)')
1169
1170 wait_for(lambda: only_one(l2.rpc.listpeers()['peers'][0]['channels'])['status'] == [
1171 'CHANNELD_NORMAL:Reconnected, and reestablished.',
1172 'CHANNELD_NORMAL:Channel ready for use. They need our announcement signatures.'])
1173
1174 # Unblinding l2 brings it back in sync, restarts channeld and sends its announce sig
1175 l2.daemon.rpcproxy.mock_rpc('getblockhash', None)
1176
1177 wait_for(lambda: chan_active(l2, '104x1x0', True))
1178 assert l2.rpc.listchannels('103x1x0')['channels'] == []
1179
1180 wait_for(lambda: only_one(l2.rpc.listpeers()['peers'][0]['channels'])['status'] == [
1181 'CHANNELD_NORMAL:Reconnected, and reestablished.',
1182 'CHANNELD_NORMAL:Channel ready for use. Channel announced.'])
1183
1184 l1.rpc.close(l2.info['id'])
1185 bitcoind.generate_block(1, True)
1186 l1.daemon.wait_for_log(r'Deleting channel')
1187 l2.daemon.wait_for_log(r'Deleting channel')
1188
1189
1190def test_rescan(node_factory, bitcoind):

Callers

nothing calls this directly

Calls 15

sync_blockheightFunction · 0.90
wait_forFunction · 0.90
only_oneFunction · 0.90
chan_activeFunction · 0.85
line_graphMethod · 0.80
fundwalletMethod · 0.80
generate_blockMethod · 0.80
wait_channel_activeMethod · 0.80
mock_rpcMethod · 0.80
simple_reorgMethod · 0.80
wait_for_logMethod · 0.80
fundchannelMethod · 0.45

Tested by

no test coverage detected