Skip to content

Commit 86d98b9

Browse files
test: verify that ancestors of a reconsidered block can become the chain tip
when we reconsiderblock, previously only block and it's descendants were considered as chain tip candidates/inserted into setBlockIndexCandidates ex: on this chain, with block 4 invalidated 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> header 7 blocks 4, 5, 6, header 7 have BLOCK_FAILED_* flags set previously: - if we reconsiderblock header 7, the chain would have all the BLOCK_FAILED_* flags cleared but would report chain tip as block 3. - after restart, it reports correct chain tip block 6. now: - if we reconsiderblock header 7, the correct chain tip block 6 is reported since ancestors are also considered as chain tip candidates/inserted into setBlockIndexCandidates. Co-authored-by: Martin Zumsande <[email protected]>
1 parent 3c39a55 commit 86d98b9

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

test/functional/rpc_invalidateblock.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,23 @@ def run_test(self):
8585
self.wait_until(lambda: self.nodes[0].getblockcount() == 4, timeout=5)
8686
self.wait_until(lambda: self.nodes[1].getblockcount() == 4, timeout=5)
8787

88+
self.log.info("Verify that ancestors can become chain tip candidates when we reconsider blocks")
89+
# Invalidate node0's current chain (1' -> 2' -> 3' -> 4') so that we don't reorg back to it in this test
90+
badhash = self.nodes[0].getblockhash(1)
91+
self.nodes[0].invalidateblock(badhash)
92+
# Reconsider the tip so that node0's chain becomes this chain again : 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> header 7
93+
self.nodes[0].reconsiderblock(tip)
94+
blockhash_3 = self.nodes[0].getblockhash(3)
95+
blockhash_4 = self.nodes[0].getblockhash(4)
96+
blockhash_6 = self.nodes[0].getblockhash(6)
97+
assert_equal(self.nodes[0].getbestblockhash(), blockhash_6)
98+
99+
# Invalidate block 4 so that chain becomes : 1 -> 2 -> 3
100+
self.nodes[0].invalidateblock(blockhash_4)
101+
assert_equal(self.nodes[0].getbestblockhash(), blockhash_3)
102+
assert_equal(self.nodes[0].getblockchaininfo()['blocks'], 3)
103+
assert_equal(self.nodes[0].getblockchaininfo()['headers'], 3)
104+
88105
self.log.info("Verify that we reconsider all ancestors as well")
89106
blocks = self.generatetodescriptor(self.nodes[1], 10, ADDRESS_BCRT1_UNSPENDABLE_DESCRIPTOR, sync_fun=self.no_op)
90107
assert_equal(self.nodes[1].getbestblockhash(), blocks[-1])
@@ -111,6 +128,14 @@ def run_test(self):
111128
# Should report consistent blockchain info
112129
assert_equal(self.nodes[1].getblockchaininfo()["headers"], self.nodes[1].getblockchaininfo()["blocks"])
113130

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+
114139
self.log.info("Verify that invalidating an unknown block throws an error")
115140
assert_raises_rpc_error(-5, "Block not found", self.nodes[1].invalidateblock, "00" * 32)
116141
assert_equal(self.nodes[1].getbestblockhash(), blocks[-1])

0 commit comments

Comments
 (0)