Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 2,902 Lines • ▼ Show 20 Lines | bool ActivateBestChain(const Config &config, BlockValidationState &state, | ||||
std::shared_ptr<const CBlock> pblock) { | std::shared_ptr<const CBlock> pblock) { | ||||
return ::ChainstateActive().ActivateBestChain(config, state, | return ::ChainstateActive().ActivateBestChain(config, state, | ||||
std::move(pblock)); | std::move(pblock)); | ||||
} | } | ||||
bool CChainState::FinalizeBlock(const Config &config, | bool CChainState::FinalizeBlock(const Config &config, | ||||
BlockValidationState &state, | BlockValidationState &state, | ||||
CBlockIndex *pindex) { | CBlockIndex *pindex) { | ||||
AssertLockHeld(cs_main); | CBlockIndex *pindexToInvalidate{nullptr}; | ||||
deadalnix: Use assignments for these. these curly bracket are ugly and don't serve any purpose here. | |||||
{ | |||||
LOCK(cs_main); | |||||
if (!MarkBlockAsFinal(config, state, pindex)) { | if (!MarkBlockAsFinal(config, state, pindex)) { | ||||
// state is set by MarkBlockAsFinal. | // state is set by MarkBlockAsFinal. | ||||
return false; | return false; | ||||
} | } | ||||
// We have a valid candidate, make sure it is not parked. | // We have a valid candidate, make sure it is not parked. | ||||
if (pindex->nStatus.isOnParkedChain()) { | if (pindex->nStatus.isOnParkedChain()) { | ||||
UnparkBlock(pindex); | UnparkBlock(pindex); | ||||
} | } | ||||
// If the finalized block is not on the active chain, we may need to rewind. | // If the finalized block is on the active chain, there is no need to | ||||
if (!::ChainActive().Contains(pindex)) { | // rewind. | ||||
const CBlockIndex *pindexFork = ::ChainActive().FindFork(pindex); | if (::ChainActive().Contains(pindex)) { | ||||
CBlockIndex *pindexToInvalidate = ::ChainActive().Next(pindexFork); | return true; | ||||
if (pindexToInvalidate) { | |||||
return InvalidateBlock(config, state, pindexToInvalidate); | |||||
} | } | ||||
// If the finalized block is not on the active chain, that chain is | |||||
// invalid | |||||
// ... | |||||
const CBlockIndex *pindexFork = ::ChainActive().FindFork(pindex); | |||||
pindexToInvalidate = ::ChainActive().Next(pindexFork); | |||||
if (!pindexToInvalidate) { | |||||
return false; | |||||
} | } | ||||
} // end of locked cs_main scope | |||||
deadalnixUnsubmitted Not Done Inline ActionsIt seems like changes here in between the finalization and the invalidation could lead to very nasty results. IIRC, core intrduced a new mutex for the chainstate. You need to be using it n lieu of cs_main. deadalnix: It seems like changes here in between the finalization and the invalidation could lead to very… | |||||
return true; | // ... therefore, we invalidate the block on the active chain that comes | ||||
// immediately after it | |||||
return InvalidateBlock(config, state, pindexToInvalidate); | |||||
} | } | ||||
bool CChainState::PreciousBlock(const Config &config, | bool CChainState::PreciousBlock(const Config &config, | ||||
BlockValidationState &state, | BlockValidationState &state, | ||||
CBlockIndex *pindex) { | CBlockIndex *pindex) { | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
if (pindex->nChainWork < m_chain.Tip()->nChainWork) { | if (pindex->nChainWork < m_chain.Tip()->nChainWork) { | ||||
▲ Show 20 Lines • Show All 2,722 Lines • Show Last 20 Lines |
Use assignments for these. these curly bracket are ugly and don't serve any purpose here.