Commit 81e67d9
committed
Merge bitcoin#34179: refactor: Enable transparent lookup for setBlockIndexCandidates to remove const_cast
3bd98b4 refactor: use transparent comparator for setBlockIndexCandidates lookups (joaonevess)
Pull request description:
### 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
1. **Enable Heterogeneous Lookup:** Added `using is_transparent = void;` to `CBlockIndexWorkComparator` in `src/node/blockstorage.h`. This allows the `std::set` to natively accept `const CBlockIndex*` for lookup (utilizing C++14 heterogeneous lookup).
2. **Remove Cast:** Removed the now unnecessary `const_cast<CBlockIndex*>` in `src/validation.cpp`, allowing the compiler to strictly enforce const-correctness.
### Notes
- **Refactoring only:** No behavioral change.
- **Verification:** `validation_tests` and `blockmanager_tests` pass.
ACKs for top commit:
maflcko:
review ACK 3bd98b4 🚪
frankomosh:
ACK 3bd98b4. Good use of transparent comparator to eliminate `const_cast` in this specific code path.
sedited:
ACK 3bd98b4
Tree-SHA512: 0f76bdce2a54b759dfec99633afce1e95586e62f4057ecf1e82eed1a073eb8ecb2d659ccbf28a7a139f0aa09a30f058ac6966cafdfbf1f2ee878fa2d86b2c4872 files changed
+4
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
| 139 | + | |
139 | 140 | | |
140 | 141 | | |
141 | 142 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5380 | 5380 | | |
5381 | 5381 | | |
5382 | 5382 | | |
5383 | | - | |
| 5383 | + | |
5384 | 5384 | | |
5385 | 5385 | | |
5386 | 5386 | | |
5387 | 5387 | | |
5388 | 5388 | | |
5389 | 5389 | | |
5390 | 5390 | | |
5391 | | - | |
| 5391 | + | |
5392 | 5392 | | |
5393 | 5393 | | |
5394 | 5394 | | |
| |||
5420 | 5420 | | |
5421 | 5421 | | |
5422 | 5422 | | |
5423 | | - | |
| 5423 | + | |
5424 | 5424 | | |
5425 | 5425 | | |
5426 | 5426 | | |
| |||
0 commit comments