Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show All 39 Lines | |||||
#include <ui_interface.h> | #include <ui_interface.h> | ||||
#include <undo.h> | #include <undo.h> | ||||
#include <util.h> | #include <util.h> | ||||
#include <utilmoneystr.h> | #include <utilmoneystr.h> | ||||
#include <utilstrencodings.h> | #include <utilstrencodings.h> | ||||
#include <validationinterface.h> | #include <validationinterface.h> | ||||
#include <warnings.h> | #include <warnings.h> | ||||
#include <boost/algorithm/string/join.hpp> | |||||
#include <boost/algorithm/string/replace.hpp> | #include <boost/algorithm/string/replace.hpp> | ||||
#include <boost/thread.hpp> // boost::this_thread::interruption_point() (mingw) | #include <boost/thread.hpp> // boost::this_thread::interruption_point() (mingw) | ||||
#include <atomic> | #include <atomic> | ||||
#include <future> | #include <future> | ||||
#include <sstream> | #include <sstream> | ||||
#include <thread> | #include <thread> | ||||
▲ Show 20 Lines • Show All 2,047 Lines • ▼ Show 20 Lines | |||||
void PruneAndFlush() { | void PruneAndFlush() { | ||||
CValidationState state; | CValidationState state; | ||||
fCheckForPruning = true; | fCheckForPruning = true; | ||||
const CChainParams &chainparams = Params(); | const CChainParams &chainparams = Params(); | ||||
FlushStateToDisk(chainparams, state, FlushStateMode::NONE); | FlushStateToDisk(chainparams, state, FlushStateMode::NONE); | ||||
} | } | ||||
/** Private helper function that concatenates warning messages. */ | |||||
static void AppendWarning(std::string &res, const std::string &warn) { | |||||
if (!res.empty()) { | |||||
res += ", "; | |||||
} | |||||
res += warn; | |||||
} | |||||
/** | /** | ||||
* 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 = | const Consensus::Params &consensusParams = | ||||
config.GetChainParams().GetConsensus(); | 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(); | ||||
} | } | ||||
std::vector<std::string> warningMessages; | std::string warningMessages; | ||||
if (!IsInitialBlockDownload()) { | if (!IsInitialBlockDownload()) { | ||||
int nUpgraded = 0; | int nUpgraded = 0; | ||||
const CBlockIndex *pindex = chainActive.Tip(); | const CBlockIndex *pindex = chainActive.Tip(); | ||||
// Check the version of the last 100 blocks to see if we need to | // Check the version of the last 100 blocks to see if we need to | ||||
// upgrade: | // upgrade: | ||||
for (int i = 0; i < 100 && pindex != nullptr; i++) { | for (int i = 0; i < 100 && pindex != nullptr; i++) { | ||||
int32_t nExpectedVersion = | int32_t nExpectedVersion = | ||||
ComputeBlockVersion(pindex->pprev, consensusParams); | ComputeBlockVersion(pindex->pprev, consensusParams); | ||||
if (pindex->nVersion > VERSIONBITS_LAST_OLD_BLOCK_VERSION && | if (pindex->nVersion > VERSIONBITS_LAST_OLD_BLOCK_VERSION && | ||||
(pindex->nVersion & ~nExpectedVersion) != 0) { | (pindex->nVersion & ~nExpectedVersion) != 0) { | ||||
++nUpgraded; | ++nUpgraded; | ||||
} | } | ||||
pindex = pindex->pprev; | pindex = pindex->pprev; | ||||
} | } | ||||
if (nUpgraded > 0) { | if (nUpgraded > 0) { | ||||
warningMessages.push_back(strprintf( | AppendWarning( | ||||
_("%d of last 100 blocks have unexpected version"), nUpgraded)); | warningMessages, | ||||
strprintf(_("%d of last 100 blocks have unexpected version"), | |||||
nUpgraded)); | |||||
} | } | ||||
} | } | ||||
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)", | ||||
__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()) { | if (!warningMessages.empty()) { | ||||
LogPrintf(" warning='%s'", | LogPrintf(" warning='%s'", warningMessages); | ||||
boost::algorithm::join(warningMessages, ", ")); | |||||
} | } | ||||
LogPrintf("\n"); | 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 | ||||
▲ Show 20 Lines • Show All 3,453 Lines • Show Last 20 Lines |