Test that lightningd crashes when getblock retries are exhausted. Currently, when bcli returns an error after retry timeout, lightningd's get_bitcoin_result() calls fatal(). This test documents that behavior.
(node_factory, bitcoind)
| 2303 | |
| 2304 | |
| 2305 | def test_bcli_retry_timeout(node_factory, bitcoind): |
| 2306 | """Test that lightningd crashes when getblock retries are exhausted. |
| 2307 | |
| 2308 | Currently, when bcli returns an error after retry timeout, lightningd's |
| 2309 | get_bitcoin_result() calls fatal(). This test documents that behavior. |
| 2310 | """ |
| 2311 | getblockfrompeer_count = 0 |
| 2312 | |
| 2313 | def mock_getblock(r): |
| 2314 | return { |
| 2315 | "id": r["id"], |
| 2316 | "result": None, |
| 2317 | "error": {"code": -1, "message": "Block not available (pruned data)"} |
| 2318 | } |
| 2319 | |
| 2320 | def mock_getpeerinfo(r): |
| 2321 | return {"id": r["id"], "result": [{"id": 1, "services": "000000000000040d"}]} |
| 2322 | |
| 2323 | def mock_getblockfrompeer(r): |
| 2324 | nonlocal getblockfrompeer_count |
| 2325 | getblockfrompeer_count += 1 |
| 2326 | return {"id": r["id"], "result": {}} |
| 2327 | |
| 2328 | l1 = node_factory.get_node(may_fail=True, |
| 2329 | broken_log=r'getrawblockbyheight|FATAL SIGNAL|backtrace', |
| 2330 | options={"bitcoin-retry-timeout": 3}) |
| 2331 | sync_blockheight(bitcoind, [l1]) |
| 2332 | |
| 2333 | l1.daemon.rpcproxy.mock_rpc("getblock", mock_getblock) |
| 2334 | l1.daemon.rpcproxy.mock_rpc("getpeerinfo", mock_getpeerinfo) |
| 2335 | l1.daemon.rpcproxy.mock_rpc("getblockfrompeer", mock_getblockfrompeer) |
| 2336 | |
| 2337 | # Mine a new block - lightningd will try to fetch it and crash. |
| 2338 | bitcoind.generate_block(1) |
| 2339 | |
| 2340 | l1.daemon.wait_for_log(r"timed out after 3 seconds") |
| 2341 | assert l1.daemon.wait() != 0 |
| 2342 | assert getblockfrompeer_count > 0 |
| 2343 | |
| 2344 | |
| 2345 | @unittest.skipIf(TEST_NETWORK != 'regtest', 'p2tr addresses not supported by elementsd') |
nothing calls this directly
no test coverage detected