Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 3,027 Lines • ▼ Show 20 Lines | bool PreciousBlock(const Config &config, CValidationState &state, | ||||
CBlockIndex *pindex) { | CBlockIndex *pindex) { | ||||
return g_chainstate.PreciousBlock(config, state, pindex); | return g_chainstate.PreciousBlock(config, state, pindex); | ||||
} | } | ||||
bool CChainState::UnwindBlock(const Config &config, CValidationState &state, | bool CChainState::UnwindBlock(const Config &config, CValidationState &state, | ||||
CBlockIndex *pindex, bool invalidate) { | CBlockIndex *pindex, bool invalidate) { | ||||
CBlockIndex *to_mark_failed_or_parked = pindex; | CBlockIndex *to_mark_failed_or_parked = pindex; | ||||
bool pindex_was_in_chain = false; | bool pindex_was_in_chain = false; | ||||
int disconnected = 0; | |||||
// Disconnect (descendants of) pindex, and mark them invalid. | // Disconnect (descendants of) pindex, and mark them invalid. | ||||
while (true) { | while (true) { | ||||
if (ShutdownRequested()) { | if (ShutdownRequested()) { | ||||
break; | break; | ||||
} | } | ||||
// Make sure the queue of validation callbacks doesn't grow unboundedly. | // Make sure the queue of validation callbacks doesn't grow unboundedly. | ||||
Show All 12 Lines | while (true) { | ||||
// unconditionally valid already, so force disconnect away from it. | // unconditionally valid already, so force disconnect away from it. | ||||
DisconnectedBlockTransactions disconnectpool; | DisconnectedBlockTransactions disconnectpool; | ||||
bool ret = DisconnectTip(config, state, &disconnectpool); | bool ret = DisconnectTip(config, state, &disconnectpool); | ||||
// DisconnectTip will add transactions to disconnectpool. | // DisconnectTip will add transactions to disconnectpool. | ||||
// Adjust the mempool to be consistent with the new tip, adding | // Adjust the mempool to be consistent with the new tip, adding | ||||
// transactions back to the mempool if disconnecting was successful. | // transactions back to the mempool if disconnecting was successful, | ||||
// and we're not doing a very deep invalidation (in which case | |||||
disconnectpool.updateMempoolForReorg(config, /* fAddToMempool = */ ret); | // keeping the mempool up to date is probably futile anyway). | ||||
disconnectpool.updateMempoolForReorg( | |||||
config, /* fAddToMempool = */ (++disconnected <= 10) && ret); | |||||
if (!ret) { | if (!ret) { | ||||
return false; | return false; | ||||
} | } | ||||
assert(invalid_walk_tip->pprev == chainActive.Tip()); | assert(invalid_walk_tip->pprev == chainActive.Tip()); | ||||
// We immediately mark the disconnected blocks as invalid. | // We immediately mark the disconnected blocks as invalid. | ||||
▲ Show 20 Lines • Show All 2,623 Lines • Show Last 20 Lines |