Could use batch queries to speed things up. On my machine, fetching individually takes ~12s (2 x ~6s), fetching in batch just ~3s (2 x ~1.5s). Is there a reason we need to wait_until
check_for_block
? Batch approach seems to work fine without it?
0diff --git a/test/functional/feature_index_prune.py b/test/functional/feature_index_prune.py
1index af6ef4c14c..e15ca7ac76 100755
2--- a/test/functional/feature_index_prune.py
3+++ b/test/functional/feature_index_prune.py
4@@ -5,13 +5,25 @@
5 """Test indices in conjunction with prune."""
6 import os
7 from test_framework.authproxy import JSONRPCException
8-from test_framework.test_framework import BitcoinTestFramework
9+from test_framework.test_framework import BitcoinTestFramework, TestNode
10 from test_framework.util import (
11 assert_equal,
12 assert_greater_than,
13 assert_raises_rpc_error,
14 )
15
16+from typing import Dict, List, Any
17+
18+def send_batch_request(node: TestNode, method: str, params: List[Any]) -> List[Any]:
19+ """Send batch request and parse all results"""
20+ data = [{"method": method, "params": p} for p in params]
21+ response = node.batch(data)
22+ result = []
23+ for item in response:
24+ assert item["error"] is None, item["error"]
25+ result.append(item["result"])
26+
27+ return result
28
29 class FeatureIndexPruneTest(BitcoinTestFramework):
30 def set_test_params(self):
31@@ -159,12 +171,9 @@ class FeatureIndexPruneTest(BitcoinTestFramework):
32 assert_equal(len(peers), 1)
33 peer_id = peers[0]["id"]
34
35- # 1500 is the height to where the indices were able to sync
36- # previously
37- for b in range(1500, prune_height):
38- bh = node.getblockhash(b)
39- node.getblockfrompeer(bh, peer_id)
40- self.wait_until(lambda: check_for_block(node=i, hash=bh), timeout=10)
41+ # 1500 is the height to where the indices were able to sync previously
42+ hashes = send_batch_request(node, "getblockhash", [[a] for a in range(1500, prune_height)])
43+ send_batch_request(node, "getblockfrompeer", [[bh, peer_id] for bh in hashes])
44
45 # Upon restart we expect the same errors as previously although all
46 # necessary blocks have been fetched. Both indices need the undo