Skip to content

Commit 783cb73

Browse files
committed
validation: call RecalculateBestHeader in InvalidChainFound
This means that it is being called in two situations: 1.) As part of the invalidateblock rpc 2.) When we receive a block for which we have a valid header in our block index, but the block turns out to be invalid
1 parent 9275e96 commit 783cb73

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/validation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2046,7 +2046,7 @@ void Chainstate::InvalidChainFound(CBlockIndex* pindexNew)
20462046
m_chainman.m_best_invalid = pindexNew;
20472047
}
20482048
if (m_chainman.m_best_header != nullptr && m_chainman.m_best_header->GetAncestor(pindexNew->nHeight) == pindexNew) {
2049-
m_chainman.m_best_header = m_chain.Tip();
2049+
m_chainman.RecalculateBestHeader();
20502050
}
20512051

20522052
LogPrintf("%s: invalid block=%s height=%d log2_work=%f date=%s\n", __func__,

test/functional/rpc_invalidateblock.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ def run_test(self):
4141
self.nodes[0].invalidateblock(badhash)
4242
assert_equal(self.nodes[0].getblockcount(), 4)
4343
assert_equal(self.nodes[0].getbestblockhash(), besthash_n0)
44+
# Should report consistent blockchain info
45+
assert_equal(self.nodes[0].getblockchaininfo()["headers"], self.nodes[0].getblockchaininfo()["blocks"])
4446

4547
self.log.info("Make sure we won't reorg to a lower work chain:")
4648
self.connect_nodes(1, 2)

0 commit comments

Comments
 (0)