Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 2,145 Lines • ▼ Show 20 Lines | if (pindexDelete->pprev != nullptr && | ||||
"Disconnecting mempool due to rewind of upgrade block\n"); | "Disconnecting mempool due to rewind of upgrade block\n"); | ||||
if (disconnectpool) { | if (disconnectpool) { | ||||
disconnectpool->importMempool(g_mempool); | disconnectpool->importMempool(g_mempool); | ||||
} | } | ||||
g_mempool.clear(); | g_mempool.clear(); | ||||
} | } | ||||
if (disconnectpool) { | if (disconnectpool) { | ||||
disconnectpool->addForBlock(block.vtx); | disconnectpool->addForBlock(block.vtx, g_mempool); | ||||
} | } | ||||
// If the tip is finalized, then undo it. | // If the tip is finalized, then undo it. | ||||
if (pindexFinalized == pindexDelete) { | if (pindexFinalized == pindexDelete) { | ||||
pindexFinalized = pindexDelete->pprev; | pindexFinalized = pindexDelete->pprev; | ||||
} | } | ||||
m_chain.SetTip(pindexDelete->pprev); | m_chain.SetTip(pindexDelete->pprev); | ||||
▲ Show 20 Lines • Show All 485 Lines • ▼ Show 20 Lines | bool CChainState::ActivateBestChainStep( | ||||
// Disconnect active blocks which are no longer in the best chain. | // Disconnect active blocks which are no longer in the best chain. | ||||
bool fBlocksDisconnected = false; | bool fBlocksDisconnected = false; | ||||
DisconnectedBlockTransactions disconnectpool; | DisconnectedBlockTransactions disconnectpool; | ||||
while (m_chain.Tip() && m_chain.Tip() != pindexFork) { | while (m_chain.Tip() && m_chain.Tip() != pindexFork) { | ||||
if (!DisconnectTip(config.GetChainParams(), state, &disconnectpool)) { | if (!DisconnectTip(config.GetChainParams(), state, &disconnectpool)) { | ||||
// This is likely a fatal error, but keep the mempool consistent, | // This is likely a fatal error, but keep the mempool consistent, | ||||
// just in case. Only remove from the mempool in this case. | // just in case. Only remove from the mempool in this case. | ||||
disconnectpool.updateMempoolForReorg(config, false); | disconnectpool.updateMempoolForReorg(config, false, g_mempool); | ||||
// If we're unable to disconnect a block during normal operation, | // If we're unable to disconnect a block during normal operation, | ||||
// then that is a failure of our local system -- we should abort | // then that is a failure of our local system -- we should abort | ||||
// rather than stay on a less work chain. | // rather than stay on a less work chain. | ||||
AbortNode(state, | AbortNode(state, | ||||
"Failed to disconnect block; see debug.log for details"); | "Failed to disconnect block; see debug.log for details"); | ||||
return false; | return false; | ||||
} | } | ||||
Show All 36 Lines | while (fContinue && nHeight != pindexMostWork->nHeight) { | ||||
fInvalidFound = true; | fInvalidFound = true; | ||||
fContinue = false; | fContinue = false; | ||||
break; | break; | ||||
} | } | ||||
// A system error occurred (disk space, database error, ...). | // A system error occurred (disk space, database error, ...). | ||||
// Make the mempool consistent with the current tip, just in | // Make the mempool consistent with the current tip, just in | ||||
// case any observers try to use it before shutdown. | // case any observers try to use it before shutdown. | ||||
disconnectpool.updateMempoolForReorg(config, false); | disconnectpool.updateMempoolForReorg(config, false, g_mempool); | ||||
return false; | return false; | ||||
} else { | } else { | ||||
PruneBlockIndexCandidates(); | PruneBlockIndexCandidates(); | ||||
if (!pindexOldTip || | if (!pindexOldTip || | ||||
m_chain.Tip()->nChainWork > pindexOldTip->nChainWork) { | m_chain.Tip()->nChainWork > pindexOldTip->nChainWork) { | ||||
// We're in a better position than we were. Return | // We're in a better position than we were. Return | ||||
// temporarily to release the lock. | // temporarily to release the lock. | ||||
fContinue = false; | fContinue = false; | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if (fBlocksDisconnected || !disconnectpool.isEmpty()) { | if (fBlocksDisconnected || !disconnectpool.isEmpty()) { | ||||
// If any blocks were disconnected, we need to update the mempool even | // If any blocks were disconnected, we need to update the mempool even | ||||
// if disconnectpool is empty. The disconnectpool may also be non-empty | // if disconnectpool is empty. The disconnectpool may also be non-empty | ||||
// if the mempool was imported due to new validation rules being in | // if the mempool was imported due to new validation rules being in | ||||
// effect. | // effect. | ||||
LogPrint(BCLog::MEMPOOL, "Updating mempool due to reorganization or " | LogPrint(BCLog::MEMPOOL, "Updating mempool due to reorganization or " | ||||
"rules upgrade/downgrade\n"); | "rules upgrade/downgrade\n"); | ||||
disconnectpool.updateMempoolForReorg(config, true); | disconnectpool.updateMempoolForReorg(config, true, g_mempool); | ||||
} | } | ||||
g_mempool.check(pcoinsTip.get()); | g_mempool.check(pcoinsTip.get()); | ||||
// Callbacks/notifications for a new best chain. | // Callbacks/notifications for a new best chain. | ||||
if (fInvalidFound) { | if (fInvalidFound) { | ||||
CheckForkWarningConditionsOnNewFork(pindexMostWork); | CheckForkWarningConditionsOnNewFork(pindexMostWork); | ||||
} else { | } else { | ||||
▲ Show 20 Lines • Show All 296 Lines • ▼ Show 20 Lines | while (true) { | ||||
bool ret = DisconnectTip(chainparams, state, &disconnectpool); | bool ret = DisconnectTip(chainparams, 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 | // and we're not doing a very deep invalidation (in which case | ||||
// keeping the mempool up to date is probably futile anyway). | // keeping the mempool up to date is probably futile anyway). | ||||
disconnectpool.updateMempoolForReorg( | disconnectpool.updateMempoolForReorg( | ||||
config, /* fAddToMempool = */ (++disconnected <= 10) && ret); | config, /* fAddToMempool = */ (++disconnected <= 10) && ret, | ||||
g_mempool); | |||||
if (!ret) { | if (!ret) { | ||||
return false; | return false; | ||||
} | } | ||||
assert(invalid_walk_tip->pprev == m_chain.Tip()); | assert(invalid_walk_tip->pprev == m_chain.Tip()); | ||||
// We immediately mark the disconnected blocks as invalid. | // We immediately mark the disconnected blocks as invalid. | ||||
▲ Show 20 Lines • Show All 2,714 Lines • Show Last 20 Lines |