Skip to content

Commit ceb7b35

Browse files
jamesobjnewbery
andcommitted
refactor: move UpdateTip into CChainState
Makes sense and saves on arguments. Co-authored-by: John Newbery <[email protected]>
1 parent 4abf077 commit ceb7b35

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/validation.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2199,13 +2199,11 @@ static void AppendWarning(bilingual_str& res, const bilingual_str& warn)
21992199
res += warn;
22002200
}
22012201

2202-
/** Check warning conditions and do some notifications on new chain tip set. */
2203-
static void UpdateTip(CTxMemPool* mempool, const CBlockIndex* pindexNew, const CChainParams& chainParams, CChainState& active_chainstate)
2204-
EXCLUSIVE_LOCKS_REQUIRED(::cs_main)
2202+
void CChainState::UpdateTip(const CBlockIndex* pindexNew)
22052203
{
22062204
// New best block
2207-
if (mempool) {
2208-
mempool->AddTransactionsUpdated(1);
2205+
if (m_mempool) {
2206+
m_mempool->AddTransactionsUpdated(1);
22092207
}
22102208

22112209
{
@@ -2215,11 +2213,11 @@ static void UpdateTip(CTxMemPool* mempool, const CBlockIndex* pindexNew, const C
22152213
}
22162214

22172215
bilingual_str warning_messages;
2218-
if (!active_chainstate.IsInitialBlockDownload()) {
2216+
if (!this->IsInitialBlockDownload()) {
22192217
const CBlockIndex* pindex = pindexNew;
22202218
for (int bit = 0; bit < VERSIONBITS_NUM_BITS; bit++) {
22212219
WarningBitsConditionChecker checker(bit);
2222-
ThresholdState state = checker.GetStateFor(pindex, chainParams.GetConsensus(), warningcache[bit]);
2220+
ThresholdState state = checker.GetStateFor(pindex, m_params.GetConsensus(), warningcache[bit]);
22232221
if (state == ThresholdState::ACTIVE || state == ThresholdState::LOCKED_IN) {
22242222
const bilingual_str warning = strprintf(_("Unknown new rules activated (versionbit %i)"), bit);
22252223
if (state == ThresholdState::ACTIVE) {
@@ -2234,7 +2232,7 @@ static void UpdateTip(CTxMemPool* mempool, const CBlockIndex* pindexNew, const C
22342232
pindexNew->GetBlockHash().ToString(), pindexNew->nHeight, pindexNew->nVersion,
22352233
log(pindexNew->nChainWork.getdouble())/log(2.0), (unsigned long)pindexNew->nChainTx,
22362234
FormatISO8601DateTime(pindexNew->GetBlockTime()),
2237-
GuessVerificationProgress(chainParams.TxData(), pindexNew), active_chainstate.CoinsTip().DynamicMemoryUsage() * (1.0 / (1<<20)), active_chainstate.CoinsTip().GetCacheSize(),
2235+
GuessVerificationProgress(m_params.TxData(), pindexNew), this->CoinsTip().DynamicMemoryUsage() * (1.0 / (1<<20)), this->CoinsTip().GetCacheSize(),
22382236
!warning_messages.empty() ? strprintf(" warning='%s'", warning_messages.original) : "");
22392237
}
22402238

@@ -2292,7 +2290,7 @@ bool CChainState::DisconnectTip(BlockValidationState& state, DisconnectedBlockTr
22922290

22932291
m_chain.SetTip(pindexDelete->pprev);
22942292

2295-
UpdateTip(m_mempool, pindexDelete->pprev, m_params, *this);
2293+
UpdateTip(pindexDelete->pprev);
22962294
// Let wallets know transactions went from 1-confirmed to
22972295
// 0-confirmed or conflicted:
22982296
GetMainSignals().BlockDisconnected(pblock, pindexDelete);
@@ -2404,7 +2402,7 @@ bool CChainState::ConnectTip(BlockValidationState& state, CBlockIndex* pindexNew
24042402
}
24052403
// Update m_chain & related variables.
24062404
m_chain.SetTip(pindexNew);
2407-
UpdateTip(m_mempool, pindexNew, m_params, *this);
2405+
UpdateTip(pindexNew);
24082406

24092407
int64_t nTime6 = GetTimeMicros(); nTimePostConnect += nTime6 - nTime5; nTimeTotal += nTime6 - nTime1;
24102408
LogPrint(BCLog::BENCH, " - Connect postprocess: %.2fms [%.2fs (%.2fms/blk)]\n", (nTime6 - nTime5) * MILLI, nTimePostConnect * MICRO, nTimePostConnect * MILLI / nBlocksTotal);

src/validation.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,10 @@ class CChainState
823823
DisconnectedBlockTransactions& disconnectpool,
824824
bool fAddToMempool) EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_mempool->cs);
825825

826+
/** Check warning conditions and do some notifications on new chain tip set. */
827+
void UpdateTip(const CBlockIndex* pindexNew)
828+
EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
829+
826830
friend ChainstateManager;
827831
};
828832

0 commit comments

Comments
 (0)