Update chainActive and related internal data structures. */
| 3477 | |
| 3478 | /** Update chainActive and related internal data structures. */ |
| 3479 | void static UpdateTip(CBlockIndex* pindexNew, const CChainParams& chainParams) |
| 3480 | { |
| 3481 | chainActive.SetTip(pindexNew); |
| 3482 | |
| 3483 | // New best block |
| 3484 | nTimeBestReceived = GetTime(); |
| 3485 | mempool.AddTransactionsUpdated(1); |
| 3486 | |
| 3487 | if (!hideLogMessage) |
| 3488 | LogPrintf("UpdateTip: new best=%s height=%d log2_work=%.8g tx=%lu date=%s progress=%.2f cache=%u\n", |
| 3489 | chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height(), log(chainActive.Tip()->nChainWork.getdouble()) / log(2.0), (unsigned long)chainActive.Tip()->nChainTx, |
| 3490 | DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.Tip()->GetBlockTime()), |
| 3491 | Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.Tip()), (unsigned int)pcoinsTip->GetCacheSize()); |
| 3492 | |
| 3493 | cvBlockChange.notify_all(); |
| 3494 | |
| 3495 | // Check the version of the last 100 blocks to see if we need to upgrade: |
| 3496 | static bool fWarned = false; |
| 3497 | std::vector<std::string> warningMessages; |
| 3498 | if (!IsInitialBlockDownload() && !fWarned) { |
| 3499 | int nUpgraded = 0; |
| 3500 | const CBlockIndex* pindex = chainActive.Tip(); |
| 3501 | for (int bit = 0; bit < VERSIONBITS_NUM_BITS; bit++) { |
| 3502 | WarningBitsConditionChecker checker(bit); |
| 3503 | ThresholdState state = checker.GetStateFor(pindex, chainParams.GetConsensus(), warningcache[bit]); |
| 3504 | if (state == THRESHOLD_ACTIVE || state == THRESHOLD_LOCKED_IN) { |
| 3505 | if (state == THRESHOLD_ACTIVE) { |
| 3506 | strMiscWarning = strprintf(_("Warning: unknown new rules activated (versionbit %i)"), bit); |
| 3507 | if (!fWarned) { |
| 3508 | CAlert::Notify(strMiscWarning, true); |
| 3509 | fWarned = true; |
| 3510 | } |
| 3511 | } else { |
| 3512 | warningMessages.push_back(strprintf("unknown new rules are about to activate (versionbit %i)", bit)); |
| 3513 | } |
| 3514 | } |
| 3515 | } |
| 3516 | // Check the version of the last 100 blocks to see if we need to upgrade: |
| 3517 | for (int i = 0; i < 100 && pindex != NULL; i++) |
| 3518 | { |
| 3519 | int32_t nExpectedVersion = ComputeBlockVersion(pindex->pprev, chainParams.GetConsensus()); |
| 3520 | if (pindex->nVersion > VERSIONBITS_LAST_OLD_BLOCK_VERSION && (pindex->nVersion & ~nExpectedVersion) != 0) |
| 3521 | ++nUpgraded; |
| 3522 | pindex = pindex->pprev; |
| 3523 | } |
| 3524 | if (nUpgraded > 0) |
| 3525 | warningMessages.push_back(strprintf("%d of last 100 blocks have unexpected version", nUpgraded)); |
| 3526 | if (nUpgraded > 100/2) |
| 3527 | { |
| 3528 | // strMiscWarning is read by GetWarnings(), called by Qt and the JSON-RPC code to warn the user: |
| 3529 | strMiscWarning = _("Warning: This version is obsolete, upgrade required!"); |
| 3530 | CAlert::Notify(strMiscWarning, true); |
| 3531 | fWarned = true; |
| 3532 | } |
| 3533 | } |
| 3534 | } |
| 3535 | |
| 3536 | /** Disconnect chainActive's tip. */ |
no test coverage detected