Skip to content

Commit 57959f9

Browse files
committed
test: verify that ancestors can become chaintip
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.
1 parent 79d78d0 commit 57959f9

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

test/functional/rpc_invalidateblock.py

+26
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def run_test(self):
4747
block = create_block(int(tip, 16), create_coinbase(self.nodes[0].getblockcount()), block_time, version=4)
4848
block.solve()
4949
self.nodes[0].submitheader(block.serialize().hex())
50+
header_hash = format(block.sha256, '064x')
5051
assert_equal(self.nodes[0].getblockchaininfo()["headers"], self.nodes[0].getblockchaininfo()["blocks"] + 1)
5152

5253
self.log.info("Invalidate block 2 on node 0 and verify we reorg to node 0's original chain")
@@ -111,6 +112,31 @@ def run_test(self):
111112
# Should report consistent blockchain info
112113
assert_equal(self.nodes[1].getblockchaininfo()["headers"], self.nodes[1].getblockchaininfo()["blocks"])
113114

115+
self.log.info("Verify that ancestors can become chain tip candidates when we reconsider blocks")
116+
# Invalidate node0's current chain (1' -> 2' -> 3' -> 4') so that we don't reorg back to it in this test
117+
badhash = self.nodes[0].getblockhash(1)
118+
self.nodes[0].invalidateblock(badhash)
119+
# Reconsider the tip so that node0's chain becomes this chain again : 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> header 7
120+
self.nodes[0].reconsiderblock(tip)
121+
blockhash_3 = self.nodes[0].getblockhash(3)
122+
blockhash_4 = self.nodes[0].getblockhash(4)
123+
blockhash_6 = self.nodes[0].getblockhash(6)
124+
assert_equal(self.nodes[0].getbestblockhash(), blockhash_6)
125+
126+
# Invalidate block 4 so that chain becomes : 1 -> 2 -> 3
127+
self.nodes[0].invalidateblock(blockhash_4)
128+
assert_equal(self.nodes[0].getbestblockhash(), blockhash_3)
129+
assert_equal(self.nodes[0].getblockchaininfo()['blocks'], 3)
130+
assert_equal(self.nodes[0].getblockchaininfo()['headers'], 3)
131+
132+
# Reconsider the header
133+
self.nodes[0].reconsiderblock(header_hash)
134+
# Since header doesn't have block data, it can't be chain tip
135+
# Check if it's possible for an ancestor (with block data) to be the chain tip
136+
assert_equal(self.nodes[0].getbestblockhash(), blockhash_6)
137+
assert_equal(self.nodes[0].getblockchaininfo()['blocks'], 6)
138+
assert_equal(self.nodes[0].getblockchaininfo()['headers'], 7)
139+
114140
self.log.info("Verify that invalidating an unknown block throws an error")
115141
assert_raises_rpc_error(-5, "Block not found", self.nodes[1].invalidateblock, "00" * 32)
116142
assert_equal(self.nodes[1].getbestblockhash(), blocks[-1])

0 commit comments

Comments
 (0)