mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 23:03:45 +01:00
validation: add RecalculateBestHeader() function
It recalculates m_best_header by looping over the entire block index. Even though this is not very performant, it will only be used in rare situations that cannot be triggered by others without a cost: As part of to invalidateblock / reconsiderblock rpcs, or when a block with an accepted header with valid PoW turns out to be invalid later during full validation.
This commit is contained in:
@@ -6396,6 +6396,17 @@ std::optional<int> ChainstateManager::GetSnapshotBaseHeight() const
|
||||
return base ? std::make_optional(base->nHeight) : std::nullopt;
|
||||
}
|
||||
|
||||
void ChainstateManager::RecalculateBestHeader()
|
||||
{
|
||||
AssertLockHeld(cs_main);
|
||||
m_best_header = ActiveChain().Tip();
|
||||
for (auto& entry : m_blockman.m_block_index) {
|
||||
if (!(entry.second.nStatus & BLOCK_FAILED_MASK) && m_best_header->nChainWork < entry.second.nChainWork) {
|
||||
m_best_header = &entry.second;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool ChainstateManager::ValidatedSnapshotCleanup()
|
||||
{
|
||||
AssertLockHeld(::cs_main);
|
||||
|
||||
Reference in New Issue
Block a user