diff --git a/src/validation.cpp b/src/validation.cpp index 7430ec60d11..1ccf5656fc6 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -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__, diff --git a/test/functional/rpc_invalidateblock.py b/test/functional/rpc_invalidateblock.py index c7c7d578bbb..f83bc901a2a 100755 --- a/test/functional/rpc_invalidateblock.py +++ b/test/functional/rpc_invalidateblock.py @@ -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)