@@ -180,92 +180,104 @@ class CBlockIndex
180
180
{
181
181
public:
182
182
// ! pointer to the hash of the block, if any. Memory is owned by mapBlockIndex
183
- const uint256* phashBlock;
183
+ const uint256* phashBlock{ nullptr } ;
184
184
185
185
// ! pointer to the index of the predecessor of this block
186
- CBlockIndex* pprev;
186
+ CBlockIndex* pprev{ nullptr } ;
187
187
188
188
// ! pointer to the index of some further predecessor of this block
189
- CBlockIndex* pskip;
189
+ CBlockIndex* pskip{ nullptr } ;
190
190
191
191
// ! height of the entry in the chain. The genesis block has height 0
192
- int nHeight;
192
+ int nHeight{ 0 } ;
193
193
194
194
// ! money supply tracking
195
- int64_t nMoneySupply;
195
+ int64_t nMoneySupply{ 0 } ;
196
196
197
197
// ! zerocoin mint supply tracking
198
- int64_t nMint;
198
+ int64_t nMint{ 0 } ;
199
199
200
200
// ! Which # file this block is stored in (blk?????.dat)
201
- int nFile;
201
+ int nFile{ 0 } ;
202
202
203
203
// ! Byte offset within blk?????.dat where this block's data is stored
204
- unsigned int nDataPos;
204
+ unsigned int nDataPos{ 0 } ;
205
205
206
206
// ! Byte offset within rev?????.dat where this block's undo data is stored
207
- unsigned int nUndoPos;
207
+ unsigned int nUndoPos{ 0 } ;
208
208
209
209
// ! (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{} ;
211
211
212
212
// ! (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{} ;
214
214
215
215
// ! Number of transactions in this block.
216
216
// ! Note: in a potential headers-first mode, this number cannot be relied upon
217
- unsigned int nTx;
217
+ unsigned int nTx{ 0 } ;
218
218
219
219
// ! (memory only) Number of transactions in the chain up to and including this block.
220
220
// ! This value will be non-zero only if and only if transactions for this block and all its parents are available.
221
221
// ! Change to 64-bit type when necessary; won't happen before 2030
222
- unsigned int nChainTx;
222
+ unsigned int nChainTx{ 0 } ;
223
223
224
- int64_t nAnonOutputs; // last index
224
+ int64_t nAnonOutputs{ 0 } ; // last index
225
225
226
226
// ! Verification status of this block. See enum BlockStatus
227
- uint32_t nStatus;
227
+ uint32_t nStatus{ 0 } ;
228
228
229
- bool fProofOfStake ;
230
- bool fProofOfFullNode ;
229
+ bool fProofOfStake { false } ;
230
+ bool fProofOfFullNode { false } ;
231
231
232
232
// ! Funds sent into the network to serve as an additional reward to stakers and miners
233
- CAmount nNetworkRewardReserve;
233
+ CAmount nNetworkRewardReserve{ 0 } ;
234
234
235
235
// ! 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 } ;
241
241
242
242
// ! ProgPow Header items
243
243
// Height was already in the CBlockIndex
244
- uint64_t nNonce64;
245
- uint256 mixHash;
244
+ uint64_t nNonce64{ 0 } ;
245
+ uint256 mixHash{} ;
246
246
247
247
// ! (memory only) Sequential id assigned to distinguish order in which blocks are received.
248
- int32_t nSequenceId;
248
+ int32_t nSequenceId{ 0 } ;
249
249
250
250
// ! zerocoin specific fields
251
251
std::map<libzerocoin::CoinDenomination, int64_t > mapZerocoinSupply;
252
252
std::vector<libzerocoin::CoinDenomination> vMintDenominationsInBlock;
253
253
254
254
// ! (memory only) Maximum nTime in the chain up to and including this block.
255
- unsigned int nTimeMax;
255
+ unsigned int nTimeMax{ 0 } ;
256
256
257
257
// ! Hash value for the accumulator. Can be used to access the zerocoindb for the accumulator value
258
258
std::map<libzerocoin::CoinDenomination ,uint256> mapAccumulatorHashes;
259
259
260
- uint256 hashMerkleRoot;
261
- uint256 hashWitnessMerkleRoot;
262
- uint256 hashPoFN;
263
- uint256 hashAccumulators;
260
+ uint256 hashMerkleRoot{} ;
261
+ uint256 hashWitnessMerkleRoot{} ;
262
+ uint256 hashPoFN{} ;
263
+ uint256 hashAccumulators{} ;
264
264
265
265
// ! vector that holds a proof of stake proof hash if the block has one. If not, its empty and has less memory
266
266
// ! overhead than an empty uint256
267
267
std::vector<unsigned char > vHashProof;
268
268
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
+
269
281
void SetNull ()
270
282
{
271
283
phashBlock = nullptr ;
@@ -301,14 +313,7 @@ class CBlockIndex
301
313
hashWitnessMerkleRoot = uint256 ();
302
314
hashAccumulators = uint256 ();
303
315
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 ();
312
317
313
318
vMintDenominationsInBlock.clear ();
314
319
@@ -327,27 +332,23 @@ class CBlockIndex
327
332
328
333
CBlockIndex ()
329
334
{
330
- SetNull ();
335
+ ResetMaps ();
331
336
}
332
337
333
338
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 }
334
350
{
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 ();
351
352
}
352
353
353
354
CDiskBlockPos GetBlockPos () const {
0 commit comments