From 783cb7337f72a3c7b2e74efd677a8ff0c375fe10 Mon Sep 17 00:00:00 2001 From: Martin Zumsande Date: Wed, 14 Aug 2024 17:28:55 -0400 Subject: [PATCH] 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 --- src/validation.cpp | 2 +- test/functional/rpc_invalidateblock.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) 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)