Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
251self.nodes[0].waitforblockheight(110)252res = self.nodes[0].gettxoutsetinfo('muhash')253option_res = self.nodes[1].gettxoutsetinfo(hash_type='muhash', hash_or_height=None, use_index=False)254del res['disk_size'], option_res['disk_size']255assert_equal(res, option_res)257def _test_reorg_index(self):258self.log.info("Test that index can handle reorgs")260# Generate two block, let the index catch up, then invalidate the blocks261index_node = self.nodes[1]262reorg_blocks = self.generatetoaddress(index_node, 2, getnewdestination()[2])263reorg_block = reorg_blocks[1]264self.sync_index_node()265res_invalid = index_node.gettxoutsetinfo('muhash')266index_node.invalidateblock(reorg_blocks[0])267assert_equal(index_node.gettxoutsetinfo('muhash')['height'], 110)269# Add two new blocks270block = self.generate(index_node, 2, sync_fun=self.no_op)[1]271res = index_node.gettxoutsetinfo(hash_type='muhash', hash_or_height=None, use_index=False)273# Test that the result of the reorged block is not returned for its old block height274res2 = index_node.gettxoutsetinfo(hash_type='muhash', hash_or_height=112)275assert_equal(res["bestblock"], block)276assert_equal(res["muhash"], res2["muhash"])277assert_not_equal(res["muhash"], res_invalid["muhash"])279# Test that requesting reorged out block by hash is still returning correct results280res_invalid2 = index_node.gettxoutsetinfo(hash_type='muhash', hash_or_height=reorg_block)281assert_equal(res_invalid2["muhash"], res_invalid["muhash"])282assert_not_equal(res["muhash"], res_invalid2["muhash"])284# Add another block, so we don't depend on reconsiderblock remembering which285# blocks were touched by invalidateblock286self.generate(index_node, 1)288# Ensure that removing and re-adding blocks yields consistent results289block = index_node.getblockhash(99)290index_node.invalidateblock(block)291index_node.reconsiderblock(block)292res3 = index_node.gettxoutsetinfo(hash_type='muhash', hash_or_height=112)293assert_equal(res2, res3)295def _test_index_rejects_hash_serialized(self):296self.log.info("Test that the rpc raises if the legacy hash is passed with the index")298msg = "hash_serialized_3 hash type cannot be queried for a specific block"299assert_raises_rpc_error(-8, msg, self.nodes[1].gettxoutsetinfo, hash_type='hash_serialized_3', hash_or_height=111)301for use_index in {True, False, None}:302assert_raises_rpc_error(-8, msg, self.nodes[1].gettxoutsetinfo, hash_type='hash_serialized_3', hash_or_height=111, use_index=use_index)304def _test_init_index_after_reorg(self):305self.log.info("Test a reorg while the index is deactivated")306index_node = self.nodes[1]307block = self.nodes[0].getbestblockhash()308self.generate(index_node, 2, sync_fun=self.no_op)309self.sync_index_node()311# Restart without index312self.restart_node(1, extra_args=[])313self.connect_nodes(0, 1)314index_node.invalidateblock(block)315self.generatetoaddress(index_node, 5, getnewdestination()[2])316res = index_node.gettxoutsetinfo(hash_type='muhash', hash_or_height=None, use_index=False)318# Restart with index that still has its best block on the old chain319self.restart_node(1, extra_args=self.extra_args[1])320self.sync_index_node()321res1 = index_node.gettxoutsetinfo(hash_type='muhash', hash_or_height=None, use_index=True)322assert_equal(res["muhash"], res1["muhash"])324self.log.info("Test index with an unclean restart after a reorg")325self.restart_node(1, extra_args=self.extra_args[1])326committed_height = index_node.getblockcount()327self.generate(index_node, 2, sync_fun=self.no_op)328self.sync_index_node()329block2 = index_node.getbestblockhash()330index_node.invalidateblock(block2)331self.generatetoaddress(index_node, 1, getnewdestination()[2], sync_fun=self.no_op)332self.sync_index_node()333index_node.kill_process()334self.start_node(1, extra_args=self.extra_args[1])335self.sync_index_node()336# Because of the unclean shutdown above, indexes reset to the point we last committed them to disk.337assert_equal(index_node.getindexinfo()['coinstatsindex']['best_block_height'], committed_height)340if __name__ == '__main__':341CoinStatsIndexTest(__file__).main()
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.