coins: use hashBlock setter internally for CCoinsViewCache methods
What changed, and why it matters
This is a small internal cleanup in Bitcoin Core's coin-cache code. It replaces two direct assignments to an internal 'hashBlock' field with calls to an existing setter method named SetBestBlock. By itself, this change does not fix a known bug or add a security boundary; it is a code-quality refactor that makes future maintenance easier and slightly reduces the chance of someone later bypassing the setter if it ever needs to enforce invariants.
No security action required. Treat as normal code-quality review. If auditing, verify that SetBestBlock has no side effects beyond assignment and that the new include does not introduce a circular dependency.
Security signals we found
Refactor only: no functional change to cache write/reset behavior
Uses existing setter to centralize mutation of hashBlock
No new validation, no locking changes, no consensus-critical modification
Adds uint256.h include for uint256::ZERO constant
Evidence from the diff
The commit modifies CCoinsViewCache::BatchWrite and CCoinsViewCache::Reset in src/coins.cpp to use SetBestBlock(…) instead of directly mutating the protected hashBlock member. A new #include
Changed components
src/coins.cppCCoinsViewCache::BatchWriteCCoinsViewCache::ResetInspect captured patch +3 / −2
diff --git a/src/coins.cpp b/src/coins.cpp
index 2afbbbff..449adcde 100644
--- a/src/coins.cpp
+++ b/src/coins.cpp
@@ -7,6 +7,7 @@
#include <consensus/consensus.h>
#include <logging.h>
#include <random.h>
+#include <uint256.h>
#include <util/trace.h>
TRACEPOINT_SEMAPHORE(utxocache, add);
@@ -250,7 +251,7 @@ void CCoinsViewCache::BatchWrite(CoinsViewCacheCursor& cursor, const uint256& ha
}
}
}
- hashBlock = hashBlockIn;
+ SetBestBlock(hashBlockIn);
}
void CCoinsViewCache::Flush(bool will_reuse_cache)
@@ -278,7 +279,7 @@ void CCoinsViewCache::Reset() noexcept
{
cacheCoins.clear();
cachedCoinsUsage = 0;
- hashBlock.SetNull();
+ SetBestBlock(uint256::ZERO);
}
void CCoinsViewCache::Uncache(const COutPoint& hash)
Why this scored 16/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.