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

Function test_funding_reorg_private

tests/test_misc.py:1093–1136  ·  view source on GitHub ↗

Change funding tx height after lockin, between node restart.

(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

1091@pytest.mark.openchannel('v2')
1092@pytest.mark.openchannel('v1')
1093def test_funding_reorg_private(node_factory, bitcoind):
1094 """Change funding tx height after lockin, between node restart.
1095 """
1096 # Rescan to detect reorg at restart and may_reconnect so channeld
1097 # will restart. Reorg can cause bad gossip msg.
1098 opts = {'funding-confirms': 2, 'rescan': 10, 'may_reconnect': True,
1099 'allow_bad_gossip': True,
1100 # gossipd send lightning update for original channel.
1101 'allow_broken_log': True,
1102 'allow_warning': True,
1103 'dev-fast-reconnect': None}
1104 l1, l2 = node_factory.line_graph(2, fundchannel=False, opts=opts)
1105 l1.fundwallet(10000000)
1106 sync_blockheight(bitcoind, [l1]) # height 102
1107 bitcoind.generate_block(3) # heights 103-105
1108
1109 l1.rpc.fundchannel(l2.info['id'], "all", announce=False)
1110 bitcoind.generate_block(1) # height 106
1111
1112 daemon = 'DUALOPEND' if l1.config('experimental-dual-fund') else 'CHANNELD'
1113 wait_for(lambda: only_one(l1.rpc.listpeers()['peers'][0]['channels'])['status']
1114 == ['{}_AWAITING_LOCKIN:Funding needs 1 more confirmations to be ready.'.format(daemon)])
1115 bitcoind.generate_block(1) # height 107
1116 l1.wait_channel_active('106x1x0')
1117 l2.wait_channel_active('106x1x0')
1118 l1.stop()
1119
1120 # Create a fork that changes short_channel_id from 106x1x0 to 108x1x0
1121 bitcoind.simple_reorg(106, 2) # heights 106-108
1122 bitcoind.generate_block(1) # height 109 (to reach minimum_depth=2 again)
1123 l1.start()
1124
1125 # l2 was running, sees last stale block being removed
1126 l2.daemon.wait_for_logs([r'Removing stale block {}'.format(106),
1127 r'Got depth change .->{} for .* REORG'.format(0)])
1128
1129 # New one should replace old.
1130 wait_for(lambda: chan_active(l2, '108x1x0', True))
1131 assert l2.rpc.listchannels('106x1x0')['channels'] == []
1132
1133 l1.rpc.close(l2.info['id'])
1134 bitcoind.generate_block(1, True)
1135 l1.daemon.wait_for_log(r'Deleting channel')
1136 l2.daemon.wait_for_log(r'Deleting channel')
1137
1138
1139@pytest.mark.developer("needs DEVELOPER=1", "uses --dev-fast-reconnect")

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
configMethod · 0.80
wait_channel_activeMethod · 0.80
simple_reorgMethod · 0.80
wait_for_logsMethod · 0.80
wait_for_logMethod · 0.80

Tested by

no test coverage detected