Update chainActive and related internal data structures. */
| 2644 | |
| 2645 | /** Update chainActive and related internal data structures. */ |
| 2646 | void static UpdateTip(CBlockIndex *pindexNew) { |
| 2647 | const CChainParams& chainParams = Params(); |
| 2648 | chainActive.SetTip(pindexNew); |
| 2649 | |
| 2650 | // New best block |
| 2651 | nTimeBestReceived = GetTime(); |
| 2652 | mempool.AddTransactionsUpdated(1); |
| 2653 | |
| 2654 | LogPrintf("%s: new best=%s height=%d log2_work=%.8g tx=%lu date=%s progress=%f cache=%.1fMiB(%utx)\n", __func__, |
| 2655 | chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height(), log(chainActive.Tip()->nChainWork.getdouble())/log(2.0), (unsigned long)chainActive.Tip()->nChainTx, |
| 2656 | DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.Tip()->GetBlockTime()), |
| 2657 | Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.Tip()), pcoinsTip->DynamicMemoryUsage() * (1.0 / (1<<20)), pcoinsTip->GetCacheSize()); |
| 2658 | |
| 2659 | cvBlockChange.notify_all(); |
| 2660 | |
| 2661 | // Check the version of the last 100 blocks to see if we need to upgrade: |
| 2662 | static bool fWarned = false; |
| 2663 | if (!IsInitialBlockDownload()) |
| 2664 | { |
| 2665 | int nUpgraded = 0; |
| 2666 | const CBlockIndex* pindex = chainActive.Tip(); |
| 2667 | for (int bit = 0; bit < VERSIONBITS_NUM_BITS; bit++) { |
| 2668 | WarningBitsConditionChecker checker(bit); |
| 2669 | ThresholdState state = checker.GetStateFor(pindex, chainParams.GetConsensus(), warningcache[bit]); |
| 2670 | if (state == THRESHOLD_ACTIVE || state == THRESHOLD_LOCKED_IN) { |
| 2671 | if (state == THRESHOLD_ACTIVE) { |
| 2672 | strMiscWarning = strprintf(_("Warning: unknown new rules activated (versionbit %i)"), bit); |
| 2673 | if (!fWarned) { |
| 2674 | AlertNotify(strMiscWarning, true); |
| 2675 | fWarned = true; |
| 2676 | } |
| 2677 | } else { |
| 2678 | LogPrintf("%s: unknown new rules are about to activate (versionbit %i)\n", __func__, bit); |
| 2679 | } |
| 2680 | } |
| 2681 | } |
| 2682 | for (int i = 0; i < 100 && pindex != NULL; i++) |
| 2683 | { |
| 2684 | int32_t nExpectedVersion = ComputeBlockVersion(pindex->pprev, chainParams.GetConsensus()); |
| 2685 | if (pindex->nVersion > VERSIONBITS_LAST_OLD_BLOCK_VERSION && (pindex->nVersion & ~nExpectedVersion) != 0) |
| 2686 | ++nUpgraded; |
| 2687 | pindex = pindex->pprev; |
| 2688 | } |
| 2689 | if (nUpgraded > 0) |
| 2690 | LogPrintf("%s: %d of last 100 blocks have unexpected version\n", __func__, nUpgraded); |
| 2691 | if (nUpgraded > 100/2) |
| 2692 | { |
| 2693 | // strMiscWarning is read by GetWarnings(), called by Qt and the JSON-RPC code to warn the user: |
| 2694 | strMiscWarning = _("Warning: Unknown block versions being mined! It's possible unknown rules are in effect"); |
| 2695 | if (!fWarned) { |
| 2696 | AlertNotify(strMiscWarning, true); |
| 2697 | fWarned = true; |
| 2698 | } |
| 2699 | } |
| 2700 | } |
| 2701 | } |
| 2702 | |
| 2703 | /** Disconnect chainActive's tip. You probably want to call mempool.removeForReorg and manually re-limit mempool size after this, with cs_main held. */ |
no test coverage detected