Skip to content

Commit 61a51ec

Browse files
committed
validation: don't use GetAll() in CheckBlockIndex()
GetAll() is non-const, preventing CheckBlockIndex() from being const. Rather than add a const GetAll() method, just iterate over the chainstates directly. Slight behaviour change by also subjecting non-`IsUsable()` chainstates to consistency checks.
1 parent d05481d commit 61a51ec

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/validation.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5354,8 +5354,8 @@ void ChainstateManager::CheckBlockIndex()
53545354
if (pindex->pprev == nullptr) {
53555355
// Genesis block checks.
53565356
assert(pindex->GetBlockHash() == GetConsensus().hashGenesisBlock); // Genesis block's hash must match.
5357-
for (auto c : GetAll()) {
5358-
if (c->m_chain.Genesis() != nullptr) {
5357+
for (const Chainstate* c : {m_ibd_chainstate.get(), m_snapshot_chainstate.get()}) {
5358+
if (c && c->m_chain.Genesis() != nullptr) {
53595359
assert(pindex == c->m_chain.Genesis()); // The chain's genesis block must be this block.
53605360
}
53615361
}
@@ -5408,8 +5408,8 @@ void ChainstateManager::CheckBlockIndex()
54085408
}
54095409

54105410
// Chainstate-specific checks on setBlockIndexCandidates
5411-
for (auto c : GetAll()) {
5412-
if (c->m_chain.Tip() == nullptr) continue;
5411+
for (const Chainstate* c : {m_ibd_chainstate.get(), m_snapshot_chainstate.get()}) {
5412+
if (!c || c->m_chain.Tip() == nullptr) continue;
54135413
// Two main factors determine whether pindex is a candidate in
54145414
// setBlockIndexCandidates:
54155415
//
@@ -5492,7 +5492,8 @@ void ChainstateManager::CheckBlockIndex()
54925492
// tip.
54935493
// So if this block is itself better than any m_chain.Tip() and it wasn't in
54945494
// setBlockIndexCandidates, then it must be in m_blocks_unlinked.
5495-
for (auto c : GetAll()) {
5495+
for (const Chainstate* c : {m_ibd_chainstate.get(), m_snapshot_chainstate.get()}) {
5496+
if (!c) continue;
54965497
const bool is_active = c == &ActiveChainstate();
54975498
if (!CBlockIndexWorkComparator()(pindex, c->m_chain.Tip()) && c->setBlockIndexCandidates.count(pindex) == 0) {
54985499
if (pindexFirstInvalid == nullptr) {

0 commit comments

Comments
 (0)