mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-19 13:27:35 +02: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:
parent
1d5b2406bb
commit
a51e91783a
2 changed files with 16 additions and 0 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue