MCPcopy Create free account
hub / github.com/ElementsProject/elements / UpdateTip

Method UpdateTip

src/validation.cpp:2731–2789  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2729}
2730
2731void CChainState::UpdateTip(const CBlockIndex* pindexNew)
2732{
2733 AssertLockHeld(::cs_main);
2734 const auto& coins_tip = this->CoinsTip();
2735
2736 // The remainder of the function isn't relevant if we are not acting on
2737 // the active chainstate, so return if need be.
2738 if (this != &m_chainman.ActiveChainstate()) {
2739 // Only log every so often so that we don't bury log messages at the tip.
2740 constexpr int BACKGROUND_LOG_INTERVAL = 2000;
2741 if (pindexNew->nHeight % BACKGROUND_LOG_INTERVAL == 0) {
2742 UpdateTipLog(coins_tip, pindexNew, m_params, __func__, "[background validation] ", "");
2743 }
2744 return;
2745 }
2746
2747 // New best block
2748 if (m_mempool) {
2749 m_mempool->AddTransactionsUpdated(1);
2750 }
2751
2752 {
2753 LOCK(g_best_block_mutex);
2754 g_best_block = pindexNew->GetBlockHash();
2755 g_best_block_cv.notify_all();
2756 }
2757
2758 bilingual_str warning_messages;
2759 if (!this->IsInitialBlockDownload()) {
2760 const CBlockIndex* pindex = pindexNew;
2761 for (int bit = 0; bit < VERSIONBITS_NUM_BITS; bit++) {
2762 WarningBitsConditionChecker checker(bit);
2763 ThresholdState state = checker.GetStateFor(pindex, m_params.GetConsensus(), warningcache[bit]);
2764 if (state == ThresholdState::ACTIVE || state == ThresholdState::LOCKED_IN) {
2765 const bilingual_str warning = strprintf(_("Unknown new rules activated (versionbit %i)"), bit);
2766 if (state == ThresholdState::ACTIVE) {
2767 DoWarning(warning);
2768 } else {
2769 AppendWarning(warning_messages, warning);
2770 }
2771 }
2772 }
2773 }
2774 UpdateTipLog(coins_tip, pindexNew, m_params, __func__, "", warning_messages.original);
2775
2776 ForceUntrimHeader(pindexNew);
2777 // Do some logging if dynafed parameters changed.
2778 if (pindexNew->pprev && !pindexNew->dynafed_params().IsNull()) {
2779 int height = pindexNew->nHeight;
2780 uint256 hash = pindexNew->GetBlockHash();
2781 uint256 root = pindexNew->dynafed_params().m_current.CalculateRoot();
2782 ForceUntrimHeader(pindexNew->pprev);
2783 if (pindexNew->pprev->dynafed_params().IsNull()) {
2784 LogPrintf("Dynafed activated in block %d:%s: %s\n", height, hash.GetHex(), root.GetHex());
2785 } else if (root != pindexNew->pprev->dynafed_params().m_current.CalculateRoot()) {
2786 LogPrintf("New dynafed parameters activated in block %d:%s: %s\n", height, hash.GetHex(), root.GetHex());
2787 }
2788 }

Callers

nothing calls this directly

Calls 10

_Function · 0.85
DoWarningFunction · 0.85
AppendWarningFunction · 0.85
CalculateRootMethod · 0.80
GetBlockHashMethod · 0.45
GetStateForMethod · 0.45
IsNullMethod · 0.45
GetHexMethod · 0.45

Tested by

no test coverage detected