mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
merge bitcoin#23365: Fix backwards search for bestblock
This commit is contained in:
parent
2e22fd0ba9
commit
a681750798
@ -94,11 +94,12 @@ bool BaseIndex::Init()
|
|||||||
const CBlockIndex* block = active_chain.Tip();
|
const CBlockIndex* block = active_chain.Tip();
|
||||||
prune_violation = true;
|
prune_violation = true;
|
||||||
// check backwards from the tip if we have all block data until we reach the indexes bestblock
|
// check backwards from the tip if we have all block data until we reach the indexes bestblock
|
||||||
while (block_to_test && block->pprev && (block->pprev->nStatus & BLOCK_HAVE_DATA)) {
|
while (block_to_test && block && (block->nStatus & BLOCK_HAVE_DATA)) {
|
||||||
if (block_to_test == block) {
|
if (block_to_test == block) {
|
||||||
prune_violation = false;
|
prune_violation = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
assert(block->pprev);
|
||||||
block = block->pprev;
|
block = block->pprev;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ from test_framework.governance import EXPECTED_STDERR_NO_GOV_PRUNE
|
|||||||
class FeatureBlockfilterindexPruneTest(BitcoinTestFramework):
|
class FeatureBlockfilterindexPruneTest(BitcoinTestFramework):
|
||||||
def set_test_params(self):
|
def set_test_params(self):
|
||||||
self.num_nodes = 1
|
self.num_nodes = 1
|
||||||
self.extra_args = [["-fastprune", "-prune=1", "-blockfilterindex=1"]]
|
self.extra_args = [["-fastprune", "-prune=1", "-blockfilterindex=1", "-testactivationheight=v20@2000"]]
|
||||||
|
|
||||||
def sync_index(self, height):
|
def sync_index(self, height):
|
||||||
expected = {'basic block filter index': {'synced': True, 'best_block_height': height}}
|
expected = {'basic block filter index': {'synced': True, 'best_block_height': height}}
|
||||||
@ -25,9 +25,7 @@ class FeatureBlockfilterindexPruneTest(BitcoinTestFramework):
|
|||||||
self.log.info("check if we can access a blockfilter when pruning is enabled but no blocks are actually pruned")
|
self.log.info("check if we can access a blockfilter when pruning is enabled but no blocks are actually pruned")
|
||||||
self.sync_index(height=200)
|
self.sync_index(height=200)
|
||||||
assert_greater_than(len(self.nodes[0].getblockfilter(self.nodes[0].getbestblockhash())['filter']), 0)
|
assert_greater_than(len(self.nodes[0].getblockfilter(self.nodes[0].getbestblockhash())['filter']), 0)
|
||||||
# Mine two batches of blocks to avoid hitting NODE_NETWORK_LIMITED_MIN_BLOCKS disconnection
|
self.generate(self.nodes[0], 500)
|
||||||
self.generate(self.nodes[0], 250)
|
|
||||||
self.generate(self.nodes[0], 250)
|
|
||||||
self.sync_index(height=700)
|
self.sync_index(height=700)
|
||||||
|
|
||||||
self.log.info("prune some blocks")
|
self.log.info("prune some blocks")
|
||||||
@ -40,16 +38,29 @@ class FeatureBlockfilterindexPruneTest(BitcoinTestFramework):
|
|||||||
self.log.info("check if we can access the blockfilter of a pruned block")
|
self.log.info("check if we can access the blockfilter of a pruned block")
|
||||||
assert_greater_than(len(self.nodes[0].getblockfilter(self.nodes[0].getblockhash(2))['filter']), 0)
|
assert_greater_than(len(self.nodes[0].getblockfilter(self.nodes[0].getblockhash(2))['filter']), 0)
|
||||||
|
|
||||||
|
# mine and sync index up to a height that will later be the pruneheight
|
||||||
|
self.generate(self.nodes[0], 298)
|
||||||
|
self.sync_index(height=998)
|
||||||
|
|
||||||
self.log.info("start node without blockfilterindex")
|
self.log.info("start node without blockfilterindex")
|
||||||
self.restart_node(0, extra_args=["-fastprune", "-prune=1", '-testactivationheight=v20@2000'], expected_stderr=EXPECTED_STDERR_NO_GOV_PRUNE)
|
self.restart_node(0, extra_args=["-fastprune", "-prune=1", "-testactivationheight=v20@2000"], expected_stderr=EXPECTED_STDERR_NO_GOV_PRUNE)
|
||||||
|
|
||||||
self.log.info("make sure accessing the blockfilters throws an error")
|
self.log.info("make sure accessing the blockfilters throws an error")
|
||||||
assert_raises_rpc_error(-1, "Index is not enabled for filtertype basic", self.nodes[0].getblockfilter, self.nodes[0].getblockhash(2))
|
assert_raises_rpc_error(-1, "Index is not enabled for filtertype basic", self.nodes[0].getblockfilter, self.nodes[0].getblockhash(2))
|
||||||
self.generate(self.nodes[0], 1000)
|
self.generate(self.nodes[0], 502)
|
||||||
|
|
||||||
|
self.log.info("prune exactly up to the blockfilterindexes best block while blockfilters are disabled")
|
||||||
|
pruneheight_2 = self.nodes[0].pruneblockchain(1000)
|
||||||
|
assert_equal(pruneheight_2, 932)
|
||||||
|
self.restart_node(0, extra_args=["-fastprune", "-prune=1", "-blockfilterindex=1", "-testactivationheight=v20@2000"], expected_stderr=EXPECTED_STDERR_NO_GOV_PRUNE)
|
||||||
|
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.log.info("prune below the blockfilterindexes best block while blockfilters are disabled")
|
||||||
pruneheight_new = self.nodes[0].pruneblockchain(1000)
|
self.restart_node(0, extra_args=["-fastprune", "-prune=1", "-testactivationheight=v20@2000"], expected_stderr=EXPECTED_STDERR_NO_GOV_PRUNE)
|
||||||
assert_greater_than(pruneheight_new, pruneheight)
|
self.generate(self.nodes[0], 1000)
|
||||||
|
pruneheight_3 = self.nodes[0].pruneblockchain(2000)
|
||||||
|
assert_greater_than(pruneheight_3, pruneheight_2)
|
||||||
self.stop_node(0, expected_stderr=EXPECTED_STDERR_NO_GOV_PRUNE)
|
self.stop_node(0, expected_stderr=EXPECTED_STDERR_NO_GOV_PRUNE)
|
||||||
|
|
||||||
self.log.info("make sure we get an init error when starting the node again with block filters")
|
self.log.info("make sure we get an init error when starting the node again with block filters")
|
||||||
|
Loading…
Reference in New Issue
Block a user