Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 2,294 Lines • ▼ Show 20 Lines | void PruneAndFlush() { | ||||
const CChainParams &chainparams = Params(); | const CChainParams &chainparams = Params(); | ||||
if (!FlushStateToDisk(chainparams, state, FlushStateMode::NONE)) { | if (!FlushStateToDisk(chainparams, state, FlushStateMode::NONE)) { | ||||
LogPrintf("%s: failed to flush state (%s)\n", __func__, | LogPrintf("%s: failed to flush state (%s)\n", __func__, | ||||
FormatStateMessage(state)); | FormatStateMessage(state)); | ||||
} | } | ||||
} | } | ||||
/** Check warning conditions and do some notifications on new chain tip set. */ | /** Check warning conditions and do some notifications on new chain tip set. */ | ||||
static void UpdateTip(const Config &config, CBlockIndex *pindexNew) { | static void UpdateTip(const CChainParams ¶ms, CBlockIndex *pindexNew) { | ||||
// New best block | // New best block | ||||
g_mempool.AddTransactionsUpdated(1); | g_mempool.AddTransactionsUpdated(1); | ||||
{ | { | ||||
LOCK(g_best_block_mutex); | LOCK(g_best_block_mutex); | ||||
g_best_block = pindexNew->GetBlockHash(); | g_best_block = pindexNew->GetBlockHash(); | ||||
g_best_block_cv.notify_all(); | g_best_block_cv.notify_all(); | ||||
} | } | ||||
LogPrintf( | LogPrintf("%s: new best=%s height=%d version=0x%08x log2_work=%.8g tx=%lu " | ||||
"%s: new best=%s height=%d version=0x%08x log2_work=%.8g tx=%lu " | |||||
"date='%s' progress=%f cache=%.1fMiB(%utxo)\n", | "date='%s' progress=%f cache=%.1fMiB(%utxo)\n", | ||||
__func__, pindexNew->GetBlockHash().ToString(), pindexNew->nHeight, | __func__, pindexNew->GetBlockHash().ToString(), | ||||
pindexNew->nVersion, log(pindexNew->nChainWork.getdouble()) / log(2.0), | pindexNew->nHeight, pindexNew->nVersion, | ||||
log(pindexNew->nChainWork.getdouble()) / log(2.0), | |||||
(unsigned long)pindexNew->nChainTx, | (unsigned long)pindexNew->nChainTx, | ||||
FormatISO8601DateTime(pindexNew->GetBlockTime()), | FormatISO8601DateTime(pindexNew->GetBlockTime()), | ||||
GuessVerificationProgress(config.GetChainParams().TxData(), pindexNew), | GuessVerificationProgress(params.TxData(), pindexNew), | ||||
pcoinsTip->DynamicMemoryUsage() * (1.0 / (1 << 20)), | pcoinsTip->DynamicMemoryUsage() * (1.0 / (1 << 20)), | ||||
pcoinsTip->GetCacheSize()); | pcoinsTip->GetCacheSize()); | ||||
} | } | ||||
/** | /** | ||||
* Disconnect m_chain's tip. | * Disconnect m_chain's tip. | ||||
* After calling, the mempool will be in an inconsistent state, with | * After calling, the mempool will be in an inconsistent state, with | ||||
* transactions from disconnected blocks being added to disconnectpool. You | * transactions from disconnected blocks being added to disconnectpool. You | ||||
* should make the mempool consistent again by calling updateMempoolForReorg. | * should make the mempool consistent again by calling updateMempoolForReorg. | ||||
* with cs_main held. | * with cs_main held. | ||||
* | * | ||||
* If disconnectpool is nullptr, then no disconnected transactions are added to | * If disconnectpool is nullptr, then no disconnected transactions are added to | ||||
* disconnectpool (note that the caller is responsible for mempool consistency | * disconnectpool (note that the caller is responsible for mempool consistency | ||||
* in any case). | * in any case). | ||||
*/ | */ | ||||
bool CChainState::DisconnectTip(const Config &config, CValidationState &state, | bool CChainState::DisconnectTip(const Config &config, CValidationState &state, | ||||
DisconnectedBlockTransactions *disconnectpool) { | DisconnectedBlockTransactions *disconnectpool) { | ||||
AssertLockHeld(cs_main); | AssertLockHeld(cs_main); | ||||
CBlockIndex *pindexDelete = m_chain.Tip(); | CBlockIndex *pindexDelete = m_chain.Tip(); | ||||
const Consensus::Params &consensusParams = | const CChainParams ¶ms = config.GetChainParams(); | ||||
config.GetChainParams().GetConsensus(); | const Consensus::Params &consensusParams = params.GetConsensus(); | ||||
assert(pindexDelete); | assert(pindexDelete); | ||||
// Read block from disk. | // Read block from disk. | ||||
std::shared_ptr<CBlock> pblock = std::make_shared<CBlock>(); | std::shared_ptr<CBlock> pblock = std::make_shared<CBlock>(); | ||||
CBlock &block = *pblock; | CBlock &block = *pblock; | ||||
if (!ReadBlockFromDisk(block, pindexDelete, consensusParams)) { | if (!ReadBlockFromDisk(block, pindexDelete, consensusParams)) { | ||||
return AbortNode(state, "Failed to read block"); | return AbortNode(state, "Failed to read block"); | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | bool CChainState::DisconnectTip(const Config &config, CValidationState &state, | ||||
// 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); | ||||
// Update ::ChainActive() and related variables. | // Update ::ChainActive() and related variables. | ||||
UpdateTip(config, pindexDelete->pprev); | UpdateTip(params, pindexDelete->pprev); | ||||
// Let wallets know transactions went from 1-confirmed to | // Let wallets know transactions went from 1-confirmed to | ||||
// 0-confirmed or conflicted: | // 0-confirmed or conflicted: | ||||
GetMainSignals().BlockDisconnected(pblock); | GetMainSignals().BlockDisconnected(pblock); | ||||
return true; | return true; | ||||
} | } | ||||
static int64_t nTimeReadFromDisk = 0; | static int64_t nTimeReadFromDisk = 0; | ||||
static int64_t nTimeConnectTotal = 0; | static int64_t nTimeConnectTotal = 0; | ||||
▲ Show 20 Lines • Show All 257 Lines • ▼ Show 20 Lines | if (pindexNew->pprev != nullptr && | ||||
GetNextBlockScriptFlags(consensusParams, pindexNew->pprev)) { | GetNextBlockScriptFlags(consensusParams, pindexNew->pprev)) { | ||||
LogPrint(BCLog::MEMPOOL, | LogPrint(BCLog::MEMPOOL, | ||||
"Disconnecting mempool due to acceptance of upgrade block\n"); | "Disconnecting mempool due to acceptance of upgrade block\n"); | ||||
disconnectpool.importMempool(g_mempool); | disconnectpool.importMempool(g_mempool); | ||||
} | } | ||||
// Update m_chain & related variables. | // Update m_chain & related variables. | ||||
m_chain.SetTip(pindexNew); | m_chain.SetTip(pindexNew); | ||||
UpdateTip(config, pindexNew); | UpdateTip(params, pindexNew); | ||||
int64_t nTime6 = GetTimeMicros(); | int64_t nTime6 = GetTimeMicros(); | ||||
nTimePostConnect += nTime6 - nTime5; | nTimePostConnect += nTime6 - nTime5; | ||||
nTimeTotal += nTime6 - nTime1; | nTimeTotal += nTime6 - nTime1; | ||||
LogPrint(BCLog::BENCH, | LogPrint(BCLog::BENCH, | ||||
" - Connect postprocess: %.2fms [%.2fs (%.2fms/blk)]\n", | " - Connect postprocess: %.2fms [%.2fs (%.2fms/blk)]\n", | ||||
(nTime6 - nTime5) * MILLI, nTimePostConnect * MICRO, | (nTime6 - nTime5) * MILLI, nTimePostConnect * MICRO, | ||||
nTimePostConnect * MILLI / nBlocksTotal); | nTimePostConnect * MILLI / nBlocksTotal); | ||||
▲ Show 20 Lines • Show All 3,231 Lines • Show Last 20 Lines |