Skip to content

Commit 13dd025

Browse files
MarcoFalkeZannick
MarcoFalke
authored andcommitted
chain: Set all CBlockIndex members to null, remove SetNull helper
=== Veil: cannot presently remove SetNull helper due to other use, however, this is still worthwhile due to the initialization changes.
1 parent ad442a4 commit 13dd025

File tree

1 file changed

+57
-56
lines changed

1 file changed

+57
-56
lines changed

src/chain.h

+57-56
Original file line numberDiff line numberDiff line change
@@ -180,92 +180,104 @@ class CBlockIndex
180180
{
181181
public:
182182
//! pointer to the hash of the block, if any. Memory is owned by mapBlockIndex
183-
const uint256* phashBlock;
183+
const uint256* phashBlock{nullptr};
184184

185185
//! pointer to the index of the predecessor of this block
186-
CBlockIndex* pprev;
186+
CBlockIndex* pprev{nullptr};
187187

188188
//! pointer to the index of some further predecessor of this block
189-
CBlockIndex* pskip;
189+
CBlockIndex* pskip{nullptr};
190190

191191
//! height of the entry in the chain. The genesis block has height 0
192-
int nHeight;
192+
int nHeight{0};
193193

194194
//! money supply tracking
195-
int64_t nMoneySupply;
195+
int64_t nMoneySupply{0};
196196

197197
//! zerocoin mint supply tracking
198-
int64_t nMint;
198+
int64_t nMint{0};
199199

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

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

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

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

212212
//! (memory only) Total amount of work (only looking at PoW) in the chain up to and including this block
213-
arith_uint256 nChainPoW;
213+
arith_uint256 nChainPoW{};
214214

215215
//! Number of transactions in this block.
216216
//! Note: in a potential headers-first mode, this number cannot be relied upon
217-
unsigned int nTx;
217+
unsigned int nTx{0};
218218

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

224-
int64_t nAnonOutputs; // last index
224+
int64_t nAnonOutputs{0}; // last index
225225

226226
//! Verification status of this block. See enum BlockStatus
227-
uint32_t nStatus;
227+
uint32_t nStatus{0};
228228

229-
bool fProofOfStake;
230-
bool fProofOfFullNode;
229+
bool fProofOfStake{false};
230+
bool fProofOfFullNode{false};
231231

232232
//! Funds sent into the network to serve as an additional reward to stakers and miners
233-
CAmount nNetworkRewardReserve;
233+
CAmount nNetworkRewardReserve{0};
234234

235235
//! block header
236-
int32_t nVersion;
237-
uint256 hashVeilData;
238-
uint32_t nTime;
239-
uint32_t nBits;
240-
uint32_t nNonce;
236+
int32_t nVersion{0};
237+
uint256 hashVeilData{};
238+
uint32_t nTime{0};
239+
uint32_t nBits{0};
240+
uint32_t nNonce{0};
241241

242242
//! ProgPow Header items
243243
// Height was already in the CBlockIndex
244-
uint64_t nNonce64;
245-
uint256 mixHash;
244+
uint64_t nNonce64{0};
245+
uint256 mixHash{};
246246

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

250250
//! zerocoin specific fields
251251
std::map<libzerocoin::CoinDenomination, int64_t> mapZerocoinSupply;
252252
std::vector<libzerocoin::CoinDenomination> vMintDenominationsInBlock;
253253

254254
//! (memory only) Maximum nTime in the chain up to and including this block.
255-
unsigned int nTimeMax;
255+
unsigned int nTimeMax{0};
256256

257257
//! Hash value for the accumulator. Can be used to access the zerocoindb for the accumulator value
258258
std::map<libzerocoin::CoinDenomination ,uint256> mapAccumulatorHashes;
259259

260-
uint256 hashMerkleRoot;
261-
uint256 hashWitnessMerkleRoot;
262-
uint256 hashPoFN;
263-
uint256 hashAccumulators;
260+
uint256 hashMerkleRoot{};
261+
uint256 hashWitnessMerkleRoot{};
262+
uint256 hashPoFN{};
263+
uint256 hashAccumulators{};
264264

265265
//! vector that holds a proof of stake proof hash if the block has one. If not, its empty and has less memory
266266
//! overhead than an empty uint256
267267
std::vector<unsigned char> vHashProof;
268268

269+
void ResetMaps()
270+
{
271+
for (auto& denom : libzerocoin::zerocoinDenomList) {
272+
mapAccumulatorHashes[denom] = uint256();
273+
}
274+
275+
// Start supply of each denomination with 0s
276+
for (auto& denom : libzerocoin::zerocoinDenomList) {
277+
mapZerocoinSupply.insert(std::make_pair(denom, 0));
278+
}
279+
}
280+
269281
void SetNull()
270282
{
271283
phashBlock = nullptr;
@@ -301,14 +313,7 @@ class CBlockIndex
301313
hashWitnessMerkleRoot = uint256();
302314
hashAccumulators = uint256();
303315

304-
for (auto& denom : libzerocoin::zerocoinDenomList) {
305-
mapAccumulatorHashes[denom] = uint256();
306-
}
307-
308-
// Start supply of each denomination with 0s
309-
for (auto& denom : libzerocoin::zerocoinDenomList) {
310-
mapZerocoinSupply.insert(std::make_pair(denom, 0));
311-
}
316+
ResetMaps();
312317

313318
vMintDenominationsInBlock.clear();
314319

@@ -327,27 +332,23 @@ class CBlockIndex
327332

328333
CBlockIndex()
329334
{
330-
SetNull();
335+
ResetMaps();
331336
}
332337

333338
explicit CBlockIndex(const CBlockHeader& block)
339+
: nHeight{static_cast<int>(block.nHeight)},
340+
nVersion{block.nVersion},
341+
hashVeilData{block.hashVeilData},
342+
nTime{block.nTime},
343+
nBits{block.nBits},
344+
nNonce{block.nNonce},
345+
nNonce64{block.nNonce64},
346+
mixHash{block.mixHash},
347+
hashMerkleRoot{block.hashMerkleRoot},
348+
hashWitnessMerkleRoot{block.hashWitnessMerkleRoot},
349+
hashAccumulators{block.hashAccumulators}
334350
{
335-
SetNull();
336-
337-
nVersion = block.nVersion;
338-
hashVeilData = block.hashVeilData;
339-
hashMerkleRoot = block.hashMerkleRoot;
340-
hashWitnessMerkleRoot = block.hashWitnessMerkleRoot;
341-
hashAccumulators = block.hashAccumulators;
342-
nTime = block.nTime;
343-
nBits = block.nBits;
344-
nNonce = block.nNonce;
345-
nMint = 0;
346-
347-
//ProgPow
348-
nNonce64 = block.nNonce64;
349-
mixHash = block.mixHash;
350-
nHeight = block.nHeight;
351+
ResetMaps();
351352
}
352353

353354
CDiskBlockPos GetBlockPos() const {

0 commit comments

Comments
 (0)