Rationale
This PR improves code safety by removing a const_cast in src/validation.cpp.
Currently, setBlockIndexCandidates stores mutable CBlockIndex*. However, validation logic (like CVerifyDB) often holds const CBlockIndex*. Previously, checking for existence in the set required casting away constness. While currently benign, this bypasses compiler safety checks and could mask accidental modifications in future refactors.
Description
- Enable Heterogeneous Lookup: Added
using is_transparent = void;toCBlockIndexWorkComparatorinsrc/node/blockstorage.h. This allows thestd::setto natively acceptconst CBlockIndex*for lookup (utilizing C++14 heterogeneous lookup). - Remove Cast: Removed the now unnecessary
const_cast<CBlockIndex*>insrc/validation.cpp, allowing the compiler to strictly enforce const-correctness.
Notes
- Refactoring only: No behavioral change.
- Verification:
validation_testsandblockmanager_testspass.