Skip to content

Commit ec30a79

Browse files
committed
Fix UB with bench on genesis block
1 parent d6e700e commit ec30a79

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/validation.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,6 +1834,8 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
18341834
uint256 hashPrevBlock = pindex->pprev == nullptr ? uint256() : pindex->pprev->GetBlockHash();
18351835
assert(hashPrevBlock == view.GetBestBlock());
18361836

1837+
nBlocksTotal++;
1838+
18371839
// Special case for the genesis block, skipping connection of its transactions
18381840
// (its coinbase is unspendable)
18391841
if (block.GetHash() == chainparams.GetConsensus().hashGenesisBlock) {
@@ -1842,8 +1844,6 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
18421844
return true;
18431845
}
18441846

1845-
nBlocksTotal++;
1846-
18471847
bool fScriptChecks = true;
18481848
if (!hashAssumeValid.IsNull()) {
18491849
// We've been configured with the hash of a block which has been externally verified to have a valid history.
@@ -2445,6 +2445,7 @@ bool CChainState::ConnectTip(CValidationState& state, const CChainParams& chainp
24452445
return error("%s: ConnectBlock %s failed, %s", __func__, pindexNew->GetBlockHash().ToString(), FormatStateMessage(state));
24462446
}
24472447
nTime3 = GetTimeMicros(); nTimeConnectTotal += nTime3 - nTime2;
2448+
assert(nBlocksTotal > 0);
24482449
LogPrint(BCLog::BENCH, " - Connect total: %.2fms [%.2fs (%.2fms/blk)]\n", (nTime3 - nTime2) * MILLI, nTimeConnectTotal * MICRO, nTimeConnectTotal * MILLI / nBlocksTotal);
24492450
bool flushed = view.Flush();
24502451
assert(flushed);

0 commit comments

Comments
 (0)