aboutsummaryrefslogtreecommitdiff
path: root/test/functional
diff options
context:
space:
mode:
authorMartin Zumsande <mzumsande@gmail.com>2022-05-22 20:29:45 +0200
committerMartin Zumsande <mzumsande@gmail.com>2023-05-17 11:14:10 -0400
commit60bec3c82d09ec208bf0028ad32499e251ad205e (patch)
tree6751884ffbb11d5d4a68b7d3805a6440fbc01a60 /test/functional
parent594f05db19fa2eaf6705f13bb0e147bce6ac21e5 (diff)
downloadbitcoin-60bec3c82d09ec208bf0028ad32499e251ad205e.tar.xz
index: Use first block from locator instead of looking for fork point
The index sync code has logic to go back the chain to the forking point, while also updating index-specific state, which is necessary to prevent possible corruption of the coinstatsindex. Also add a test for this (a reorg happens while the index is deactivated) that would not pass before this change.
Diffstat (limited to 'test/functional')
-rwxr-xr-xtest/functional/feature_coinstatsindex.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/test/functional/feature_coinstatsindex.py b/test/functional/feature_coinstatsindex.py
index 4f8541a5d7..73f4d83e43 100755
--- a/test/functional/feature_coinstatsindex.py
+++ b/test/functional/feature_coinstatsindex.py
@@ -52,6 +52,7 @@ class CoinStatsIndexTest(BitcoinTestFramework):
self._test_use_index_option()
self._test_reorg_index()
self._test_index_rejects_hash_serialized()
+ self._test_init_index_after_reorg()
def block_sanity_check(self, block_info):
block_subsidy = 50
@@ -60,6 +61,9 @@ class CoinStatsIndexTest(BitcoinTestFramework):
block_info['new_outputs_ex_coinbase'] + block_info['coinbase'] + block_info['unspendable']
)
+ def sync_index_node(self):
+ self.wait_until(lambda: self.nodes[1].getindexinfo()['coinstatsindex']['synced'] is True)
+
def _test_coin_stats_index(self):
node = self.nodes[0]
index_node = self.nodes[1]
@@ -296,6 +300,26 @@ class CoinStatsIndexTest(BitcoinTestFramework):
for use_index in {True, False, None}:
assert_raises_rpc_error(-8, msg, self.nodes[1].gettxoutsetinfo, hash_type='hash_serialized_2', hash_or_height=111, use_index=use_index)
+ def _test_init_index_after_reorg(self):
+ self.log.info("Test a reorg while the index is deactivated")
+ index_node = self.nodes[1]
+ block = self.nodes[0].getbestblockhash()
+ self.generate(index_node, 2, sync_fun=self.no_op)
+ self.sync_index_node()
+
+ # Restart without index
+ self.restart_node(1, extra_args=[])
+ self.connect_nodes(0, 1)
+ index_node.invalidateblock(block)
+ self.generatetoaddress(index_node, 5, getnewdestination()[2])
+ res = index_node.gettxoutsetinfo(hash_type='muhash', hash_or_height=None, use_index=False)
+
+ # Restart with index that still has its best block on the old chain
+ self.restart_node(1, extra_args=self.extra_args[1])
+ self.sync_index_node()
+ res1 = index_node.gettxoutsetinfo(hash_type='muhash', hash_or_height=None, use_index=True)
+ assert_equal(res["muhash"], res1["muhash"])
+
if __name__ == '__main__':
CoinStatsIndexTest().main()