block_connected: don't serialize block hash twice

In the validation:block_connected tracepoint, we call block->GetHash(),
which ends up calling CBlockHeader::GetHash(), executing around 8000
serialization instructions. We don't need to do this extra work, because
block->GetHash() is already called further up in the function. Let's
save that value as a local variable and re-use it in our tracepoint so
there is no unnecessary tracepoint overhead.

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin 2021-12-19 12:52:59 -08:00 committed by JSKitty
parent 95194d28e9
commit 7f2c84b7be
No known key found for this signature in database
GPG Key ID: 328CA5D971C144DD

View File

@ -1978,7 +1978,10 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
AssertLockHeld(cs_main);
assert(pindex);
assert(*pindex->phashBlock == block.GetHash());
uint256 block_hash{block.GetHash()};
assert(*pindex->phashBlock == block_hash);
assert(m_clhandler);
assert(m_isman);
assert(m_quorum_block_processor);
@ -2026,7 +2029,7 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
// Special case for the genesis block, skipping connection of its transactions
// (its coinbase is unspendable)
if (block.GetHash() == chainparams.GetConsensus().hashGenesisBlock) {
if (block_hash == chainparams.GetConsensus().hashGenesisBlock) {
if (!fJustCheck)
view.SetBestBlock(pindex->GetBlockHash());
return true;