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

Function test_lightningd_still_loading

tests/test_misc.py:144–225  ·  view source on GitHub ↗

Test that we recognize we haven't got all blocks from bitcoind

(node_factory, bitcoind, executor)

Source from the content-addressed store, hash-verified

142@pytest.mark.openchannel('v1')
143@pytest.mark.openchannel('v2')
144def test_lightningd_still_loading(node_factory, bitcoind, executor):
145 """Test that we recognize we haven't got all blocks from bitcoind"""
146
147 mock_release = Event()
148
149 # This is slow enough that we're going to notice.
150 def mock_getblock(r):
151 conf_file = os.path.join(bitcoind.bitcoin_dir, 'bitcoin.conf')
152 brpc = RawProxy(btc_conf_file=conf_file)
153 if r['params'][0] == slow_blockid:
154 mock_release.wait(TIMEOUT)
155 return {
156 "result": brpc._call(r['method'], *r['params']),
157 "error": None,
158 "id": r['id']
159 }
160
161 # Start it, establish channel, get extra funds.
162 l1, l2, l3 = node_factory.get_nodes(3, opts=[{'may_reconnect': True,
163 'wait_for_bitcoind_sync': False},
164 {'may_reconnect': True,
165 'wait_for_bitcoind_sync': False},
166 {}])
167 node_factory.join_nodes([l1, l2])
168
169 # Balance l1<->l2 channel
170 l1.pay(l2, 10**9 // 2)
171
172 l1.stop()
173
174 # Now make sure l2 is behind.
175 bitcoind.generate_block(2)
176 # Make sure l2/l3 are synced
177 sync_blockheight(bitcoind, [l2, l3])
178
179 # Make it slow grabbing the final block.
180 slow_blockid = bitcoind.rpc.getblockhash(bitcoind.rpc.getblockcount())
181 l1.daemon.rpcproxy.mock_rpc('getblock', mock_getblock)
182
183 l1.start(wait_for_bitcoind_sync=False)
184
185 # It will warn about being out-of-sync.
186 assert 'warning_bitcoind_sync' not in l1.rpc.getinfo()
187 assert 'warning_lightningd_sync' in l1.rpc.getinfo()
188
189 # Make sure it's connected to l2 (otherwise we get TEMPORARY_CHANNEL_FAILURE)
190 wait_for(lambda: only_one(l1.rpc.listpeers(l2.info['id'])['peers'])['connected'])
191
192 # Payments will fail. FIXME: More informative msg?
193 with pytest.raises(RpcError, match=r'TEMPORARY_NODE_FAILURE'):
194 l1.pay(l2, 1000)
195
196 # Can't fund a new channel.
197 l1.rpc.connect(l3.info['id'], 'localhost', l3.port)
198 with pytest.raises(RpcError, match=r'304'):
199 if l1.config('experimental-dual-fund'):
200 psbt = l1.rpc.fundpsbt('10000sat', '253perkw', 250)['psbt']
201 l1.rpc.openchannel_init(l3.info['id'], '10000sat', psbt)

Callers

nothing calls this directly

Calls 15

sync_blockheightFunction · 0.90
wait_forFunction · 0.90
only_oneFunction · 0.90
get_nodesMethod · 0.80
join_nodesMethod · 0.80
generate_blockMethod · 0.80
mock_rpcMethod · 0.80
configMethod · 0.80
fundpsbtMethod · 0.80
openchannel_initMethod · 0.80
fundchannel_startMethod · 0.80
txprepareMethod · 0.80

Tested by

no test coverage detected