aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAurèle Oulès <aurele@oules.com>2022-10-17 15:49:29 +0200
committerAurèle Oulès <aurele@oules.com>2023-01-06 12:01:22 +0100
commit5ca7a7be76f2521dca895daa70949fd11df0844c (patch)
treee744b66906f837e275180ce5d32d28e2f23a7633 /test
parent911a40ead256b8849166cff1b745b9c9898e2da8 (diff)
downloadbitcoin-5ca7a7be76f2521dca895daa70949fd11df0844c.tar.xz
rpc: Return accurate results for scanblocks
This makes use of undo data to accurately verify results from blockfilters.
Diffstat (limited to 'test')
-rwxr-xr-xtest/functional/feature_pruning.py17
-rwxr-xr-xtest/functional/rpc_scanblocks.py13
2 files changed, 26 insertions, 4 deletions
diff --git a/test/functional/feature_pruning.py b/test/functional/feature_pruning.py
index f68416dc03..664ed779db 100755
--- a/test/functional/feature_pruning.py
+++ b/test/functional/feature_pruning.py
@@ -84,7 +84,7 @@ class PruneTest(BitcoinTestFramework):
["-maxreceivebuffer=20000", "-prune=550"],
["-maxreceivebuffer=20000"],
["-maxreceivebuffer=20000"],
- ["-prune=550"],
+ ["-prune=550", "-blockfilterindex=1"],
]
self.rpc_timeout = 120
@@ -356,7 +356,7 @@ class PruneTest(BitcoinTestFramework):
self.connect_nodes(0, 5)
nds = [self.nodes[0], self.nodes[5]]
self.sync_blocks(nds, wait=5, timeout=300)
- self.restart_node(5, extra_args=["-prune=550"]) # restart to trigger rescan
+ self.restart_node(5, extra_args=["-prune=550", "-blockfilterindex=1"]) # restart to trigger rescan
self.log.info("Success")
def run_test(self):
@@ -472,7 +472,20 @@ class PruneTest(BitcoinTestFramework):
self.log.info("Test invalid pruning command line options")
self.test_invalid_command_line_options()
+ self.test_scanblocks_pruned()
+
self.log.info("Done")
+ def test_scanblocks_pruned(self):
+ node = self.nodes[5]
+ genesis_blockhash = node.getblockhash(0)
+ false_positive_spk = bytes.fromhex("001400000000000000000000000000000000000cadcb")
+
+ assert genesis_blockhash in node.scanblocks(
+ "start", [{"desc": f"raw({false_positive_spk.hex()})"}], 0, 0)['relevant_blocks']
+
+ assert_raises_rpc_error(-1, "Block not available (pruned data)", node.scanblocks,
+ "start", [{"desc": f"raw({false_positive_spk.hex()})"}], 0, 0, "basic", {"filter_false_positives": True})
+
if __name__ == '__main__':
PruneTest().main()
diff --git a/test/functional/rpc_scanblocks.py b/test/functional/rpc_scanblocks.py
index 9a00518150..fe48033b95 100755
--- a/test/functional/rpc_scanblocks.py
+++ b/test/functional/rpc_scanblocks.py
@@ -62,6 +62,12 @@ class ScanblocksTest(BitcoinTestFramework):
# make sure the blockhash is present when using the first mined block as start_height
assert blockhash in node.scanblocks(
"start", [f"addr({addr_1})"], height)['relevant_blocks']
+ for v in [False, True]:
+ assert blockhash in node.scanblocks(
+ action="start",
+ scanobjects=[f"addr({addr_1})"],
+ start_height=height,
+ options={"filter_false_positives": v})['relevant_blocks']
# also test the stop height
assert blockhash in node.scanblocks(
@@ -94,8 +100,11 @@ class ScanblocksTest(BitcoinTestFramework):
assert genesis_blockhash in node.scanblocks(
"start", [{"desc": f"raw({false_positive_spk.hex()})"}], 0, 0)['relevant_blocks']
- # TODO: after an "accurate" mode for scanblocks is implemented (e.g. PR #26325)
- # check here that it filters out the false-positive
+ # check that the filter_false_positives option works
+ assert genesis_blockhash in node.scanblocks(
+ "start", [{"desc": f"raw({genesis_coinbase_spk.hex()})"}], 0, 0, "basic", {"filter_false_positives": True})['relevant_blocks']
+ assert genesis_blockhash not in node.scanblocks(
+ "start", [{"desc": f"raw({false_positive_spk.hex()})"}], 0, 0, "basic", {"filter_false_positives": True})['relevant_blocks']
# test node with disabled blockfilterindex
assert_raises_rpc_error(-1, "Index is not enabled for filtertype basic",