Skip to content

Commit 3bd98b4

Browse files
committed
refactor: use transparent comparator for setBlockIndexCandidates lookups
This allows checking for existence in setBlockIndexCandidates using a const CBlockIndex* without casting away constness, replacing a legacy const_cast check in validation.cpp.
1 parent 2bcb3f6 commit 3bd98b4

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/node/blockstorage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ using BlockMap = std::unordered_map<uint256, CBlockIndex, BlockHasher>;
136136

137137
struct CBlockIndexWorkComparator {
138138
bool operator()(const CBlockIndex* pa, const CBlockIndex* pb) const;
139+
using is_transparent = void;
139140
};
140141

141142
struct CBlockIndexHeightOnlyComparator {

src/validation.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5401,15 +5401,15 @@ void ChainstateManager::CheckBlockIndex() const
54015401
// needs to be added if it is an ancestor of the target
54025402
// block.
54035403
if (!c->TargetBlock() || c->TargetBlock()->GetAncestor(pindex->nHeight) == pindex) {
5404-
assert(c->setBlockIndexCandidates.contains(const_cast<CBlockIndex*>(pindex)));
5404+
assert(c->setBlockIndexCandidates.contains(pindex));
54055405
}
54065406
}
54075407
// If some parent is missing, then it could be that this block was in
54085408
// setBlockIndexCandidates but had to be removed because of the missing data.
54095409
// In this case it must be in m_blocks_unlinked -- see test below.
54105410
}
54115411
} else { // If this block sorts worse than the current tip or some ancestor's block has never been seen, it cannot be in setBlockIndexCandidates.
5412-
assert(!c->setBlockIndexCandidates.contains(const_cast<CBlockIndex*>(pindex)));
5412+
assert(!c->setBlockIndexCandidates.contains(pindex));
54135413
}
54145414
}
54155415
// Check whether this block is in m_blocks_unlinked.
@@ -5441,7 +5441,7 @@ void ChainstateManager::CheckBlockIndex() const
54415441
// So if this block is itself better than any m_chain.Tip() and it wasn't in
54425442
// setBlockIndexCandidates, then it must be in m_blocks_unlinked.
54435443
for (const auto& c : m_chainstates) {
5444-
if (!CBlockIndexWorkComparator()(pindex, c->m_chain.Tip()) && !c->setBlockIndexCandidates.contains(const_cast<CBlockIndex*>(pindex))) {
5444+
if (!CBlockIndexWorkComparator()(pindex, c->m_chain.Tip()) && !c->setBlockIndexCandidates.contains(pindex)) {
54455445
if (pindexFirstInvalid == nullptr) {
54465446
if (!c->TargetBlock() || c->TargetBlock()->GetAncestor(pindex->nHeight) == pindex) {
54475447
assert(foundInUnlinked);

0 commit comments

Comments
 (0)