Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 2,122 Lines • ▼ Show 20 Lines | void PruneAndFlush() { | ||||
FlushStateToDisk(chainparams, state, FlushStateMode::NONE); | FlushStateToDisk(chainparams, state, FlushStateMode::NONE); | ||||
} | } | ||||
/** | /** | ||||
* Update chainActive and related internal data structures when adding a new | * Update chainActive and related internal data structures when adding a new | ||||
* block to the chain tip. | * block to the chain tip. | ||||
*/ | */ | ||||
static void UpdateTip(const Config &config, CBlockIndex *pindexNew) { | static void UpdateTip(const Config &config, CBlockIndex *pindexNew) { | ||||
const Consensus::Params &consensusParams = | |||||
config.GetChainParams().GetConsensus(); | |||||
chainActive.SetTip(pindexNew); | chainActive.SetTip(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(); | ||||
} | } | ||||
static bool fWarned = false; | |||||
std::vector<std::string> warningMessages; | |||||
if (!IsInitialBlockDownload()) { | |||||
int nUpgraded = 0; | |||||
const CBlockIndex *pindex = chainActive.Tip(); | |||||
// Check the version of the last 100 blocks to see if we need to | |||||
// upgrade: | |||||
for (int i = 0; i < 100 && pindex != nullptr; i++) { | |||||
int32_t nExpectedVersion = | |||||
ComputeBlockVersion(pindex->pprev, consensusParams); | |||||
if (pindex->nVersion > VERSIONBITS_LAST_OLD_BLOCK_VERSION && | |||||
(pindex->nVersion & ~nExpectedVersion) != 0) { | |||||
++nUpgraded; | |||||
} | |||||
pindex = pindex->pprev; | |||||
} | |||||
if (nUpgraded > 0) { | |||||
warningMessages.push_back(strprintf( | |||||
"%d of last 100 blocks have unexpected version", nUpgraded)); | |||||
} | |||||
if (nUpgraded > 100 / 2) { | |||||
std::string strWarning = | |||||
_("Warning: Unknown block versions being mined! It's possible " | |||||
"unknown rules are in effect"); | |||||
// notify GetWarnings(), called by Qt and the JSON-RPC code to warn | |||||
// the user: | |||||
SetMiscWarning(strWarning); | |||||
if (!fWarned) { | |||||
AlertNotify(strWarning); | |||||
fWarned = true; | |||||
} | |||||
} | |||||
} | |||||
LogPrintf("%s: new best=%s height=%d version=0x%08x log2_work=%.8g tx=%lu " | LogPrintf("%s: new best=%s height=%d version=0x%08x log2_work=%.8g tx=%lu " | ||||
"date='%s' progress=%f cache=%.1fMiB(%utxo)", | "date='%s' progress=%f cache=%.1fMiB(%utxo)\n", | ||||
__func__, chainActive.Tip()->GetBlockHash().ToString(), | __func__, chainActive.Tip()->GetBlockHash().ToString(), | ||||
chainActive.Height(), chainActive.Tip()->nVersion, | chainActive.Height(), chainActive.Tip()->nVersion, | ||||
log(chainActive.Tip()->nChainWork.getdouble()) / log(2.0), | log(chainActive.Tip()->nChainWork.getdouble()) / log(2.0), | ||||
(unsigned long)chainActive.Tip()->nChainTx, | (unsigned long)chainActive.Tip()->nChainTx, | ||||
FormatISO8601DateTime(chainActive.Tip()->GetBlockTime()), | FormatISO8601DateTime(chainActive.Tip()->GetBlockTime()), | ||||
GuessVerificationProgress(config.GetChainParams().TxData(), | GuessVerificationProgress(config.GetChainParams().TxData(), | ||||
chainActive.Tip()), | chainActive.Tip()), | ||||
pcoinsTip->DynamicMemoryUsage() * (1.0 / (1 << 20)), | pcoinsTip->DynamicMemoryUsage() * (1.0 / (1 << 20)), | ||||
pcoinsTip->GetCacheSize()); | pcoinsTip->GetCacheSize()); | ||||
if (!warningMessages.empty()) { | |||||
LogPrintf(" warning='%s'", | |||||
boost::algorithm::join(warningMessages, ", ")); | |||||
} | |||||
LogPrintf("\n"); | |||||
} | } | ||||
/** | /** | ||||
* Disconnect chainActive's tip. | * Disconnect chainActive'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. | ||||
▲ Show 20 Lines • Show All 3,376 Lines • Show Last 20 Lines |