mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-18 13:17:55 +02:00
Merge 85bcfeea23 into merged_master (Bitcoin PR bitcoin/bitcoin#30666)
This commit is contained in:
commit
27489a7346
5 changed files with 113 additions and 21 deletions
|
|
@ -2291,8 +2291,9 @@ void Chainstate::InvalidChainFound(CBlockIndex* pindexNew)
|
|||
if (!m_chainman.m_best_invalid || pindexNew->nChainWork > m_chainman.m_best_invalid->nChainWork) {
|
||||
m_chainman.m_best_invalid = pindexNew;
|
||||
}
|
||||
SetBlockFailureFlags(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 date=%s\n", __func__,
|
||||
|
|
@ -4266,6 +4267,17 @@ bool Chainstate::InvalidateBlock(BlockValidationState& state, CBlockIndex* pinde
|
|||
return true;
|
||||
}
|
||||
|
||||
void Chainstate::SetBlockFailureFlags(CBlockIndex* invalid_block)
|
||||
{
|
||||
AssertLockHeld(cs_main);
|
||||
|
||||
for (auto& [_, block_index] : m_blockman.m_block_index) {
|
||||
if (block_index.GetAncestor(invalid_block->nHeight) == invalid_block && !(block_index.nStatus & BLOCK_FAILED_MASK)) {
|
||||
block_index.nStatus |= BLOCK_FAILED_CHILD;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Chainstate::ResetBlockFailureFlags(CBlockIndex *pindex) {
|
||||
AssertLockHeld(cs_main);
|
||||
|
||||
|
|
@ -7011,6 +7023,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