Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow maintaining the blockfilterindex when using prune
Summary: PR description: > Maintaining the blockfilterindexes in prune mode is possible and may lead to efficient p2p based rescans of wallets (restore backups, import/sweep keys) beyond the prune height (rescans not part of that PR). > > This PR allows running the blockfilterindex(es) in conjunction with pruning. > > - Bitcoind/Qt will shutdown during startup when missing block data has been detected ([re]enable -blockfilterindex when we already have pruned) > - manual block pruning is disabled during blockfilterindex sync > - auto-pruning is delayed during blockfilterindex sync ---- > Allow blockfilter in conjunction with prune bitcoin/bitcoin@6abe9f5 ---- > index: Fix backwards search for bestblock bitcoin/bitcoin@698c524 ---- > Avoid accessing nullpointer in BaseIndex::GetSummary() bitcoin/bitcoin@00d57ff ---- > Avoid pruning below the blockfilterindex sync height bitcoin/bitcoin@5e11226 ---- > Add debug startup parameter -fastprune for more effective pruning tests bitcoin/bitcoin@00d57ff ---- > Add functional test for blockfilterindex in prune-mode bitcoin/bitcoin@ab3a0a2 ---- > Fix several bugs in feature_blockfilterindex_prune.py [[bitcoin/bitcoin#21230 | core#21230]] ---- > test: Intermittent issue in feature_blockfilterindex_prune [[bitcoin/bitcoin#21252 | core#21252]] ---- > test: improve assertions in feature_blockfilterindex_prune.py > test: remove unneeded node from feature_blockfilterindex_prune.py [[bitcoin/bitcoin#21297 | core#21297]] ---- > test: Add edge case of pruning up to index height bitcoin/bitcoin@9600ea0 This is a backport of [[bitcoin/bitcoin#15946 | core#15946]], [[bitcoin/bitcoin#21230 | core#21230]], [[bitcoin/bitcoin#21252 | core#21252]], [[bitcoin/bitcoin#21297 | core#21297]] and [[bitcoin/bitcoin#23365 | core#23365]] Backport notes: - the test was buggy and ugly code after the first commit, so I had to squash all these commits to reach an acceptable quality. - I had to use different numbers of blocks that are generated and pruned, because Bitcoin ABC can fit more blocks into each blk?????.dat file than core because in this test the witness data of the coinbase transaction makes core blocks larger. Comments were added to explain this where needed. - I used the shortcut `node = self.nodes[0]` to make the code a bit more readable (shorter lines) Test Plan: `ninja all check-all` Run IBD with pruning enabled ` src/bitcoind -prune=2000 -blockfilterindex=1` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Subscribers: Fabien Differential Revision: https://reviews.bitcoinabc.org/D11299
- Loading branch information
1 parent
8848294
commit eacbda7
Showing
8 changed files
with
191 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (c) 2020 The Bitcoin Core developers | ||
# Distributed under the MIT software license, see the accompanying | ||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
"""Test blockfilterindex in conjunction with prune.""" | ||
from test_framework.test_framework import BitcoinTestFramework | ||
from test_framework.util import ( | ||
assert_equal, | ||
assert_greater_than, | ||
assert_raises_rpc_error, | ||
) | ||
|
||
|
||
class FeatureBlockfilterindexPruneTest(BitcoinTestFramework): | ||
def set_test_params(self): | ||
self.num_nodes = 1 | ||
self.extra_args = [["-fastprune", "-prune=1", "-blockfilterindex=1"]] | ||
|
||
def sync_index(self, height): | ||
expected = { | ||
'basic block filter index': { | ||
'synced': True, | ||
'best_block_height': height | ||
} | ||
} | ||
self.wait_until(lambda: self.nodes[0].getindexinfo() == expected) | ||
|
||
def run_test(self): | ||
node = self.nodes[0] | ||
|
||
self.log.info("check if we can access a blockfilter when pruning is " | ||
"enabled but no blocks are actually pruned") | ||
self.sync_index(200) | ||
assert_greater_than( | ||
len(node.getblockfilter(node.getbestblockhash())['filter']), | ||
0) | ||
node.generate(500) | ||
self.sync_index(height=700) | ||
|
||
self.log.info("prune some blocks") | ||
pruneheight = node.pruneblockchain(400) | ||
# The difference in number of blocks per block file between Bitcoin ABC | ||
# and Bitcoin Core is caused by additional witness data in coinbase | ||
# transactions for core. | ||
assert_equal(pruneheight, 346) | ||
|
||
self.log.info("check if we can access the tips blockfilter when we have" | ||
" pruned some blocks") | ||
assert_greater_than( | ||
len(node.getblockfilter(node.getbestblockhash())['filter']), | ||
0) | ||
|
||
self.log.info("check if we can access the blockfilter of a pruned " | ||
"block") | ||
assert_greater_than( | ||
len(node.getblockfilter(node.getblockhash(2))['filter']), | ||
0) | ||
|
||
# mine and sync index up to a height that will later be the pruneheight | ||
node.generate(338) | ||
# Backport note: 3 blk?????.dat file with 346 blocks each makes 1038. | ||
self.sync_index(height=1038) | ||
|
||
self.log.info("start node without blockfilterindex") | ||
self.restart_node(0, extra_args=["-fastprune", "-prune=1"]) | ||
|
||
self.log.info("make sure accessing the blockfilters throws an error") | ||
assert_raises_rpc_error( | ||
-1, "Index is not enabled for filtertype basic", | ||
node.getblockfilter, node.getblockhash(2)) | ||
node.generate(462) | ||
|
||
self.log.info("prune exactly up to the blockfilterindexes best block " | ||
"while blockfilters are disabled") | ||
pruneheight_2 = self.nodes[0].pruneblockchain(1040) | ||
assert_equal(pruneheight_2, 1038) | ||
self.restart_node( | ||
0, extra_args=["-fastprune", "-prune=1", "-blockfilterindex=1"]) | ||
self.log.info("make sure that we can continue with the partially synced" | ||
" index after having pruned up to the index height") | ||
self.sync_index(height=1500) | ||
|
||
self.log.info("prune below the blockfilterindexes best block while " | ||
"blockfilters are disabled") | ||
self.restart_node( | ||
0, | ||
extra_args=["-fastprune", "-prune=1"]) | ||
node.generate(1000) | ||
pruneheight_3 = self.nodes[0].pruneblockchain(2000) | ||
assert_greater_than(pruneheight_3, pruneheight_2) | ||
self.stop_node(0) | ||
|
||
self.log.info("make sure we get an init error when starting the node " | ||
"again with block filters") | ||
with node.assert_debug_log( | ||
["basic block filter index best block of the index goes beyond " | ||
"pruned data. Please disable the index or reindex (which will " | ||
"download the whole blockchain again)"]): | ||
node.assert_start_raises_init_error( | ||
extra_args=["-fastprune", "-prune=1", "-blockfilterindex=1"]) | ||
self.log.info("make sure the node starts again with the -reindex arg") | ||
self.start_node( | ||
0, | ||
extra_args=["-fastprune", "-prune=1", "-blockfilterindex", | ||
"-reindex"]) | ||
|
||
|
||
if __name__ == '__main__': | ||
FeatureBlockfilterindexPruneTest().main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters