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
This commit is contained in:
Martin Zumsande 2024-08-14 17:28:55 -04:00
parent 9275e9689a
commit 783cb7337f
2 changed files with 3 additions and 1 deletions

View File

@ -2046,7 +2046,7 @@ void Chainstate::InvalidChainFound(CBlockIndex* pindexNew)
m_chainman.m_best_invalid = pindexNew;
}
if (m_chainman.m_best_header != nullptr && m_chainman.m_best_header->GetAncestor(pindexNew->nHeight) == pindexNew) {
m_chainman.m_best_header = m_chain.Tip();
m_chainman.RecalculateBestHeader();
}
LogPrintf("%s: invalid block=%s height=%d log2_work=%f date=%s\n", __func__,

View File

@ -41,6 +41,8 @@ class InvalidateTest(BitcoinTestFramework):
self.nodes[0].invalidateblock(badhash)
assert_equal(self.nodes[0].getblockcount(), 4)
assert_equal(self.nodes[0].getbestblockhash(), besthash_n0)
# Should report consistent blockchain info
assert_equal(self.nodes[0].getblockchaininfo()["headers"], self.nodes[0].getblockchaininfo()["blocks"])
self.log.info("Make sure we won't reorg to a lower work chain:")
self.connect_nodes(1, 2)