Skip to content

Commit 4daadce

Browse files
committed
Merge #17162: chain: Remove CBlockIndex::SetNull helper
fa04673 chain: Set all CBlockIndex members to null, remove SetNull helper (MarcoFalke) Pull request description: The first commit removes the `SetNull` helper and inlines the member initialization (C++11). See https://github.com/bitcoin/bitcoin/blob/master/doc/developer-notes.md#c-data-structures for rationale. <strike>The second commit adds the `cs_main` lock annotation to `RaiseValidity`. See also #17161.</strike> ACKs for top commit: promag: Code review ACK fa04673. practicalswift: ACK fa04673 -- diff still looks correct :) laanwj: ACK fa04673, this makes it easy to see that all fields are initialized. Tree-SHA512: 1b2b9fb0951c03c75b9cce322b89d4ecc9a364ae78b94d91b0b4669437824394dfada820ab6f74dfac3193f602899abfdc244ae2d9351ad293f555488f03470e
2 parents 88eff96 + fa04673 commit 4daadce

File tree

1 file changed

+23
-49
lines changed

1 file changed

+23
-49
lines changed

src/chain.h

Lines changed: 23 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -140,91 +140,65 @@ class CBlockIndex
140140
{
141141
public:
142142
//! pointer to the hash of the block, if any. Memory is owned by this CBlockIndex
143-
const uint256* phashBlock;
143+
const uint256* phashBlock{nullptr};
144144

145145
//! pointer to the index of the predecessor of this block
146-
CBlockIndex* pprev;
146+
CBlockIndex* pprev{nullptr};
147147

148148
//! pointer to the index of some further predecessor of this block
149-
CBlockIndex* pskip;
149+
CBlockIndex* pskip{nullptr};
150150

151151
//! height of the entry in the chain. The genesis block has height 0
152-
int nHeight;
152+
int nHeight{0};
153153

154154
//! Which # file this block is stored in (blk?????.dat)
155-
int nFile;
155+
int nFile{0};
156156

157157
//! Byte offset within blk?????.dat where this block's data is stored
158-
unsigned int nDataPos;
158+
unsigned int nDataPos{0};
159159

160160
//! Byte offset within rev?????.dat where this block's undo data is stored
161-
unsigned int nUndoPos;
161+
unsigned int nUndoPos{0};
162162

163163
//! (memory only) Total amount of work (expected number of hashes) in the chain up to and including this block
164-
arith_uint256 nChainWork;
164+
arith_uint256 nChainWork{};
165165

166166
//! Number of transactions in this block.
167167
//! Note: in a potential headers-first mode, this number cannot be relied upon
168-
unsigned int nTx;
168+
unsigned int nTx{0};
169169

170170
//! (memory only) Number of transactions in the chain up to and including this block.
171171
//! This value will be non-zero only if and only if transactions for this block and all its parents are available.
172172
//! Change to 64-bit type when necessary; won't happen before 2030
173-
unsigned int nChainTx;
173+
unsigned int nChainTx{0};
174174

175175
//! Verification status of this block. See enum BlockStatus
176-
uint32_t nStatus;
176+
uint32_t nStatus{0};
177177

178178
//! block header
179-
int32_t nVersion;
180-
uint256 hashMerkleRoot;
181-
uint32_t nTime;
182-
uint32_t nBits;
183-
uint32_t nNonce;
179+
int32_t nVersion{0};
180+
uint256 hashMerkleRoot{};
181+
uint32_t nTime{0};
182+
uint32_t nBits{0};
183+
uint32_t nNonce{0};
184184

185185
//! (memory only) Sequential id assigned to distinguish order in which blocks are received.
186-
int32_t nSequenceId;
186+
int32_t nSequenceId{0};
187187

188188
//! (memory only) Maximum nTime in the chain up to and including this block.
189-
unsigned int nTimeMax;
190-
191-
void SetNull()
192-
{
193-
phashBlock = nullptr;
194-
pprev = nullptr;
195-
pskip = nullptr;
196-
nHeight = 0;
197-
nFile = 0;
198-
nDataPos = 0;
199-
nUndoPos = 0;
200-
nChainWork = arith_uint256();
201-
nTx = 0;
202-
nChainTx = 0;
203-
nStatus = 0;
204-
nSequenceId = 0;
205-
nTimeMax = 0;
206-
207-
nVersion = 0;
208-
hashMerkleRoot = uint256();
209-
nTime = 0;
210-
nBits = 0;
211-
nNonce = 0;
212-
}
189+
unsigned int nTimeMax{0};
213190

214191
CBlockIndex()
215192
{
216-
SetNull();
217193
}
218194

219195
explicit CBlockIndex(const CBlockHeader& block)
196+
: nVersion{block.nVersion},
197+
hashMerkleRoot{block.hashMerkleRoot},
198+
nTime{block.nTime},
199+
nBits{block.nBits},
200+
nNonce{block.nNonce}
220201
{
221-
SetNull();
222-
223-
nVersion = block.nVersion;
224-
hashMerkleRoot = block.hashMerkleRoot;
225-
nTime = block.nTime;
226-
nBits = block.nBits;
227-
nNonce = block.nNonce;
228202
}
229203

230204
FlatFilePos GetBlockPos() const {

0 commit comments

Comments
 (0)