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

Function test_bcli_concurrent

tests/test_plugin.py:2240–2302  ·  view source on GitHub ↗

Test bcli handles concurrent requests while `getblockfrompeer` retry is active. Simulates a pruned node scenario where getblock initially fails. The bcli plugin should use getblockfrompeer to fetch the block from peers, then retry `getblock` successfully. Meanwhile, other concurrent req

(node_factory, bitcoind, executor)

Source from the content-addressed store, hash-verified

2238
2239
2240def test_bcli_concurrent(node_factory, bitcoind, executor):
2241 """Test bcli handles concurrent requests while `getblockfrompeer` retry is active.
2242
2243 Simulates a pruned node scenario where getblock initially fails. The bcli
2244 plugin should use getblockfrompeer to fetch the block from peers, then
2245 retry `getblock` successfully. Meanwhile, other concurrent requests
2246 (`getchaininfo`, `estimatefees`) should complete normally.
2247 """
2248 retry_count = 5
2249 getblockfrompeer_count = 0
2250
2251 def mock_getblock(r):
2252 if getblockfrompeer_count >= retry_count:
2253 conf_file = os.path.join(bitcoind.bitcoin_dir, "bitcoin.conf")
2254 brpc = RawProxy(btc_conf_file=conf_file)
2255 return {
2256 "result": brpc._call(r["method"], *r["params"]),
2257 "error": None,
2258 "id": r["id"]
2259 }
2260 return {
2261 "id": r["id"],
2262 "result": None,
2263 "error": {"code": -1, "message": "Block not available (pruned data)"}
2264 }
2265
2266 def mock_getpeerinfo(r):
2267 return {"id": r["id"], "result": [{"id": 1, "services": "000000000000040d"}]}
2268
2269 def mock_getblockfrompeer(r):
2270 nonlocal getblockfrompeer_count
2271 getblockfrompeer_count += 1
2272 return {"id": r["id"], "result": {}}
2273
2274 l1 = node_factory.get_node(start=False)
2275 l1.daemon.rpcproxy.mock_rpc("getblock", mock_getblock)
2276 l1.daemon.rpcproxy.mock_rpc("getpeerinfo", mock_getpeerinfo)
2277 l1.daemon.rpcproxy.mock_rpc("getblockfrompeer", mock_getblockfrompeer)
2278 l1.start(wait_for_bitcoind_sync=False)
2279
2280 # Submit concurrent bcli requests, `getrawblockbyheight` hits a retry path.
2281 block_future = executor.submit(l1.rpc.call, "getrawblockbyheight", {"height": 1})
2282 chaininfo_futures = []
2283 fees_futures = []
2284 for _ in range(5):
2285 chaininfo_futures.append(executor.submit(l1.rpc.call, "getchaininfo", {"last_height": 0}))
2286 fees_futures.append(executor.submit(l1.rpc.call, "estimatefees"))
2287
2288 block_result = block_future.result(TIMEOUT)
2289 assert "blockhash" in block_result
2290 assert "block" in block_result
2291
2292 for fut in chaininfo_futures:
2293 result = fut.result(TIMEOUT)
2294 assert "chain" in result
2295 assert "blockcount" in result
2296
2297 for fut in fees_futures:

Callers

nothing calls this directly

Calls 3

mock_rpcMethod · 0.80
get_nodeMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected