mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
validation: Move SetBestBlock out of ConnectBlock
This is a part of a series of commits for removing access to the CCoinsViewCache in consensus verification functions. The goal is to allow calling verification functions with pre-fetched, or a user-defined set of coins.
This commit is contained in:
parent
008748c3ae
commit
e1f88913b7
1 changed files with 3 additions and 5 deletions
|
@ -2475,8 +2475,6 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
|
||||||
// Special case for the genesis block, skipping connection of its transactions
|
// Special case for the genesis block, skipping connection of its transactions
|
||||||
// (its coinbase is unspendable)
|
// (its coinbase is unspendable)
|
||||||
if (block_hash == params.GetConsensus().hashGenesisBlock) {
|
if (block_hash == params.GetConsensus().hashGenesisBlock) {
|
||||||
if (!fJustCheck)
|
|
||||||
view.SetBestBlock(pindex->GetBlockHash());
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2676,9 +2674,6 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
|
||||||
m_blockman.m_dirty_blockindex.insert(pindex);
|
m_blockman.m_dirty_blockindex.insert(pindex);
|
||||||
}
|
}
|
||||||
|
|
||||||
// add this block to the view's block chain
|
|
||||||
view.SetBestBlock(pindex->GetBlockHash());
|
|
||||||
|
|
||||||
const auto time_6{SteadyClock::now()};
|
const auto time_6{SteadyClock::now()};
|
||||||
m_chainman.time_index += time_6 - time_5;
|
m_chainman.time_index += time_6 - time_5;
|
||||||
LogDebug(BCLog::BENCH, " - Index writing: %.2fms [%.2fs (%.2fms/blk)]\n",
|
LogDebug(BCLog::BENCH, " - Index writing: %.2fms [%.2fs (%.2fms/blk)]\n",
|
||||||
|
@ -3253,6 +3248,8 @@ bool Chainstate::ConnectTip(BlockValidationState& state, CBlockIndex* pindexNew,
|
||||||
LogError("%s: ConnectBlock %s failed, %s\n", __func__, pindexNew->GetBlockHash().ToString(), state.ToString());
|
LogError("%s: ConnectBlock %s failed, %s\n", __func__, pindexNew->GetBlockHash().ToString(), state.ToString());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// add this block to the view's block chain
|
||||||
|
view.SetBestBlock(block_hash);
|
||||||
time_3 = SteadyClock::now();
|
time_3 = SteadyClock::now();
|
||||||
m_chainman.time_connect_total += time_3 - time_2;
|
m_chainman.time_connect_total += time_3 - time_2;
|
||||||
assert(m_chainman.num_blocks_total > 0);
|
assert(m_chainman.num_blocks_total > 0);
|
||||||
|
@ -4917,6 +4914,7 @@ VerifyDBResult CVerifyDB::VerifyDB(
|
||||||
LogPrintf("Verification error: found unconnectable block at %d, hash=%s (%s)\n", pindex->nHeight, pindex->GetBlockHash().ToString(), state.ToString());
|
LogPrintf("Verification error: found unconnectable block at %d, hash=%s (%s)\n", pindex->nHeight, pindex->GetBlockHash().ToString(), state.ToString());
|
||||||
return VerifyDBResult::CORRUPTED_BLOCK_DB;
|
return VerifyDBResult::CORRUPTED_BLOCK_DB;
|
||||||
}
|
}
|
||||||
|
coins.SetBestBlock(block_hash);
|
||||||
if (chainstate.m_chainman.m_interrupt) return VerifyDBResult::INTERRUPTED;
|
if (chainstate.m_chainman.m_interrupt) return VerifyDBResult::INTERRUPTED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue