MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / UpdateTip

Function UpdateTip

src/validation.cpp:2284–2337  ·  view source on GitHub ↗

Check warning conditions and do some notifications on new chain tip set. */

Source from the content-addressed store, hash-verified

2282
2283/** Check warning conditions and do some notifications on new chain tip set. */
2284void static UpdateTip(const CBlockIndex *pindexNew, const CChainParams& chainParams) {
2285 // New best block
2286 mempool.AddTransactionsUpdated(1);
2287
2288 {
2289 WaitableLock lock(g_best_block_mutex);
2290 g_best_block = pindexNew->GetBlockHash();
2291 g_best_block_cv.notify_all();
2292 }
2293
2294 std::string warningMessages;
2295 if (!IsInitialBlockDownload())
2296 {
2297 int nUpgraded = 0;
2298 const CBlockIndex* pindex = pindexNew;
2299 for (int bit = 0; bit < VERSIONBITS_NUM_BITS; bit++) {
2300 WarningBitsConditionChecker checker(bit);
2301 ThresholdState state = checker.GetStateFor(pindex, chainParams.GetConsensus(), warningcache[bit]);
2302 if (state == ThresholdState::ACTIVE || state == ThresholdState::LOCKED_IN) {
2303 const std::string strWarning = strprintf(_("Warning: unknown new rules activated (versionbit %i)"), bit);
2304 if (state == ThresholdState::ACTIVE) {
2305 DoWarning(strWarning);
2306 } else {
2307 AppendWarning(warningMessages, strWarning);
2308 }
2309 }
2310 }
2311 // Check the version of the last 100 blocks to see if we need to upgrade:
2312 for (int i = 0; i < 100 && pindex != nullptr; i++)
2313 {
2314 int32_t nExpectedVersion = ComputeBlockVersion(pindex->pprev, chainParams.GetConsensus());
2315 if (pindex->nVersion > VERSIONBITS_LAST_OLD_BLOCK_VERSION && (pindex->nVersion & ~nExpectedVersion) != 0)
2316 ++nUpgraded;
2317 pindex = pindex->pprev;
2318 }
2319 if (nUpgraded > 0)
2320 AppendWarning(warningMessages, strprintf(_("%d of last 100 blocks have unexpected version"), nUpgraded));
2321 if (nUpgraded > 100/2)
2322 {
2323 std::string strWarning = _("Warning: Unknown block versions being mined! It's possible unknown rules are in effect");
2324 // notify GetWarnings(), called by Qt and the JSON-RPC code to warn the user:
2325 DoWarning(strWarning);
2326 }
2327 }
2328 LogPrintf("%s: new best=%s height=%d version=0x%08x log2_work=%.8g tx=%lu date='%s' progress=%f cache=%.1fMiB(%utxo)", __func__, /* Continued */
2329 pindexNew->GetBlockHash().ToString(), pindexNew->nHeight, pindexNew->nVersion,
2330 log(pindexNew->nChainWork.getdouble())/log(2.0), (unsigned long)pindexNew->nChainTx,
2331 FormatISO8601DateTime(pindexNew->GetBlockTime()),
2332 GuessVerificationProgress(chainParams.TxData(), pindexNew), pcoinsTip->DynamicMemoryUsage() * (1.0 / (1<<20)), pcoinsTip->GetCacheSize());
2333 if (!warningMessages.empty())
2334 LogPrintf(" warning='%s'", warningMessages); /* Continued */
2335 LogPrintf("\n");
2336
2337}
2338
2339/** Disconnect chainActive's tip.
2340 * After calling, the mempool will be in an inconsistent state, with

Callers 2

DisconnectTipMethod · 0.85
ConnectTipMethod · 0.85

Calls 15

IsInitialBlockDownloadFunction · 0.85
_Function · 0.85
DoWarningFunction · 0.85
AppendWarningFunction · 0.85
ComputeBlockVersionFunction · 0.85
FormatISO8601DateTimeFunction · 0.85
getdoubleMethod · 0.80
GetCacheSizeMethod · 0.80
GetBlockHashMethod · 0.45
GetStateForMethod · 0.45

Tested by

no test coverage detected