From 28416f367a5d720d89214aa8ef94013caa1d1a40 Mon Sep 17 00:00:00 2001 From: stratospher <44024636+stratospher@users.noreply.github.com> Date: Mon, 14 Jul 2025 14:46:07 +0530 Subject: [PATCH] test: fix intermittent failure in rpc_invalidateblock.py node1 (with 24 blocks) causes node0 (with 6 blocks) to silently reorg. so move the subtest to a point before the 20 blocks are generated so that node1's state doesn't cause node0 to silently reorg. --- test/functional/rpc_invalidateblock.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/functional/rpc_invalidateblock.py b/test/functional/rpc_invalidateblock.py index 031f1dd86ce..17086a649df 100755 --- a/test/functional/rpc_invalidateblock.py +++ b/test/functional/rpc_invalidateblock.py @@ -102,6 +102,14 @@ class InvalidateTest(BitcoinTestFramework): assert_equal(self.nodes[0].getblockchaininfo()['blocks'], 3) assert_equal(self.nodes[0].getblockchaininfo()['headers'], 3) + # Reconsider the header + self.nodes[0].reconsiderblock(block.hash) + # Since header doesn't have block data, it can't be chain tip + # Check if it's possible for an ancestor (with block data) to be the chain tip + assert_equal(self.nodes[0].getbestblockhash(), blockhash_6) + assert_equal(self.nodes[0].getblockchaininfo()['blocks'], 6) + assert_equal(self.nodes[0].getblockchaininfo()['headers'], 7) + self.log.info("Verify that we reconsider all ancestors as well") blocks = self.generatetodescriptor(self.nodes[1], 10, ADDRESS_BCRT1_UNSPENDABLE_DESCRIPTOR, sync_fun=self.no_op) assert_equal(self.nodes[1].getbestblockhash(), blocks[-1]) @@ -128,14 +136,6 @@ class InvalidateTest(BitcoinTestFramework): # Should report consistent blockchain info assert_equal(self.nodes[1].getblockchaininfo()["headers"], self.nodes[1].getblockchaininfo()["blocks"]) - # Reconsider the header - self.nodes[0].reconsiderblock(block.hash) - # Since header doesn't have block data, it can't be chain tip - # Check if it's possible for an ancestor (with block data) to be the chain tip - assert_equal(self.nodes[0].getbestblockhash(), blockhash_6) - assert_equal(self.nodes[0].getblockchaininfo()['blocks'], 6) - assert_equal(self.nodes[0].getblockchaininfo()['headers'], 7) - self.log.info("Verify that invalidating an unknown block throws an error") assert_raises_rpc_error(-5, "Block not found", self.nodes[1].invalidateblock, "00" * 32) assert_equal(self.nodes[1].getbestblockhash(), blocks[-1])