refactor: Use initializer list in CompressedHeader
What changed, and why it matters
This is a small, safe code cleanup in Bitcoin Core's header synchronization code. It changes how one internal data structure is initialized, marks a constructor as explicit to prevent accidental implicit conversions, and marks a helper method as const to indicate it does not modify the object. There is no security-relevant behavior change.
No security action needed. Treat as ordinary code-quality refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors CompressedHeader in src/headerssync.h: it switches the constructor from assignment statements in the body to C++ member initializer lists, adds the explicit keyword to that constructor, and adds const to GetFullHeader. These are compile-time/semantic improvements with no functional change to header synchronization logic or network behavior.
Changed components
src/headerssync.hInspect captured patch +8 / −7
diff --git a/src/headerssync.h b/src/headerssync.h
index 9e3af58d..a29726fb 100644
--- a/src/headerssync.h
+++ b/src/headerssync.h
@@ -31,16 +31,17 @@ struct CompressedHeader {
hashMerkleRoot.SetNull();
}
- CompressedHeader(const CBlockHeader& header)
+ explicit CompressedHeader(const CBlockHeader& header)
+ : nVersion{header.nVersion},
+ hashMerkleRoot{header.hashMerkleRoot},
+ nTime{header.nTime},
+ nBits{header.nBits},
+ nNonce{header.nNonce}
{
- nVersion = header.nVersion;
- hashMerkleRoot = header.hashMerkleRoot;
- nTime = header.nTime;
- nBits = header.nBits;
- nNonce = header.nNonce;
}
- CBlockHeader GetFullHeader(const uint256& hash_prev_block) {
+ CBlockHeader GetFullHeader(const uint256& hash_prev_block) const
+ {
CBlockHeader ret;
ret.nVersion = nVersion;
ret.hashPrevBlock = hash_prev_block;
Why this scored 15/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.