Skip to content

Commit 28416f3

Browse files
committed
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.
1 parent 7566b40 commit 28416f3

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

test/functional/rpc_invalidateblock.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ def run_test(self):
102102
assert_equal(self.nodes[0].getblockchaininfo()['blocks'], 3)
103103
assert_equal(self.nodes[0].getblockchaininfo()['headers'], 3)
104104

105+
# Reconsider the header
106+
self.nodes[0].reconsiderblock(block.hash)
107+
# Since header doesn't have block data, it can't be chain tip
108+
# Check if it's possible for an ancestor (with block data) to be the chain tip
109+
assert_equal(self.nodes[0].getbestblockhash(), blockhash_6)
110+
assert_equal(self.nodes[0].getblockchaininfo()['blocks'], 6)
111+
assert_equal(self.nodes[0].getblockchaininfo()['headers'], 7)
112+
105113
self.log.info("Verify that we reconsider all ancestors as well")
106114
blocks = self.generatetodescriptor(self.nodes[1], 10, ADDRESS_BCRT1_UNSPENDABLE_DESCRIPTOR, sync_fun=self.no_op)
107115
assert_equal(self.nodes[1].getbestblockhash(), blocks[-1])
@@ -128,14 +136,6 @@ def run_test(self):
128136
# Should report consistent blockchain info
129137
assert_equal(self.nodes[1].getblockchaininfo()["headers"], self.nodes[1].getblockchaininfo()["blocks"])
130138

131-
# Reconsider the header
132-
self.nodes[0].reconsiderblock(block.hash)
133-
# Since header doesn't have block data, it can't be chain tip
134-
# Check if it's possible for an ancestor (with block data) to be the chain tip
135-
assert_equal(self.nodes[0].getbestblockhash(), blockhash_6)
136-
assert_equal(self.nodes[0].getblockchaininfo()['blocks'], 6)
137-
assert_equal(self.nodes[0].getblockchaininfo()['headers'], 7)
138-
139139
self.log.info("Verify that invalidating an unknown block throws an error")
140140
assert_raises_rpc_error(-5, "Block not found", self.nodes[1].invalidateblock, "00" * 32)
141141
assert_equal(self.nodes[1].getbestblockhash(), blocks[-1])

0 commit comments

Comments
 (0)