diff --git a/src/chain.h b/src/chain.h index 064dadea59..a3ef70a4a5 100644 --- a/src/chain.h +++ b/src/chain.h @@ -140,101 +140,72 @@ class CBlockIndex { public: //! pointer to the hash of the block, if any. Memory is owned by this CBlockIndex - const uint256* phashBlock; + const uint256* phashBlock{nullptr}; //! pointer to the index of the predecessor of this block - CBlockIndex* pprev; + CBlockIndex* pprev{nullptr}; //! pointer to the index of some further predecessor of this block - CBlockIndex* pskip; + CBlockIndex* pskip{nullptr}; //! height of the entry in the chain. The genesis block has height 0 - int nHeight; + int nHeight{0}; //! Which # file this block is stored in (blk?????.dat) - int nFile; + int nFile{0}; //! Byte offset within blk?????.dat where this block's data is stored - unsigned int nDataPos; + unsigned int nDataPos{0}; //! Byte offset within rev?????.dat where this block's undo data is stored - unsigned int nUndoPos; + unsigned int nUndoPos{0}; //! (memory only) Total amount of work (expected number of hashes) in the chain up to and including this block - arith_uint256 nChainWork; + arith_uint256 nChainWork{}; //! Number of transactions in this block. //! Note: in a potential headers-first mode, this number cannot be relied upon - unsigned int nTx; + unsigned int nTx{0}; //! (memory only) Number of transactions in the chain up to and including this block. //! This value will be non-zero only if and only if transactions for this block and all its parents are available. //! Change to 64-bit type when necessary; won't happen before 2030 - unsigned int nChainTx; + unsigned int nChainTx{0}; //! Verification status of this block. See enum BlockStatus - uint32_t nStatus; + uint32_t nStatus{0}; //! block header - int32_t nVersion; - uint256 hashMerkleRoot; - uint32_t nTime; - uint32_t nBits; - uint32_t nNonce; - CProof proof; + int32_t nVersion{0}; + uint256 hashMerkleRoot{}; + uint32_t nTime{0}; + uint32_t nBits{0}; + uint32_t nNonce{0}; + CProof proof{}; // Dynamic federation fields - DynaFedParams dynafed_params; - CScriptWitness m_signblock_witness; + DynaFedParams dynafed_params{}; + CScriptWitness m_signblock_witness{}; //! (memory only) Sequential id assigned to distinguish order in which blocks are received. - int32_t nSequenceId; + int32_t nSequenceId{0}; //! (memory only) Maximum nTime in the chain up to and including this block. - unsigned int nTimeMax; - - void SetNull() - { - phashBlock = nullptr; - pprev = nullptr; - pskip = nullptr; - nHeight = 0; - nFile = 0; - nDataPos = 0; - nUndoPos = 0; - nChainWork = arith_uint256(); - nTx = 0; - nChainTx = 0; - nStatus = 0; - nSequenceId = 0; - nTimeMax = 0; - - nVersion = 0; - hashMerkleRoot = uint256(); - nTime = 0; - nBits = 0; - nNonce = 0; - proof.SetNull(); - dynafed_params.SetNull(); - m_signblock_witness.SetNull(); - } + unsigned int nTimeMax{0}; CBlockIndex() { - SetNull(); } explicit CBlockIndex(const CBlockHeader& block) + : nVersion{block.nVersion}, + hashMerkleRoot{block.hashMerkleRoot}, + nTime{block.nTime}, + nBits{block.nBits}, + nNonce{block.nNonce}, + proof{block.proof}, + dynafed_params{block.m_dynafed_params}, + m_signblock_witness{block.m_signblock_witness} { - SetNull(); - - nVersion = block.nVersion; - hashMerkleRoot = block.hashMerkleRoot; - nTime = block.nTime; - nBits = block.nBits; - nNonce = block.nNonce; - proof = block.proof; - dynafed_params = block.m_dynafed_params; - m_signblock_witness = block.m_signblock_witness; } FlatFilePos GetBlockPos() const { diff --git a/src/primitives/block.h b/src/primitives/block.h index 6c3b1a99c3..bec1449a60 100644 --- a/src/primitives/block.h +++ b/src/primitives/block.h @@ -19,13 +19,10 @@ extern bool g_signed_blocks; class CProof { public: - CScript challenge; - CScript solution; + CScript challenge{}; + CScript solution{}; - CProof() - { - SetNull(); - } + CProof() {} CProof(CScript challengeIn, CScript solutionIn) : challenge(challengeIn), solution(solutionIn) {} ADD_SERIALIZE_METHODS; @@ -58,17 +55,17 @@ public: class DynaFedParamEntry { public: - unsigned char m_serialize_type; // Determines how it is serialized, defaults to null - CScript m_signblockscript; - uint32_t m_signblock_witness_limit; // Max block signature witness serialized size - CScript m_fedpeg_program; // The "scriptPubKey" of the fedpegscript - CScript m_fedpegscript; // The witnessScript for witness v0 or undefined otherwise. + unsigned char m_serialize_type{0}; // Determines how it is serialized, defaults to null + CScript m_signblockscript{}; + uint32_t m_signblock_witness_limit{0}; // Max block signature witness serialized size + CScript m_fedpeg_program{}; // The "scriptPubKey" of the fedpegscript + CScript m_fedpegscript{}; // The witnessScript for witness v0 or undefined otherwise. // No consensus meaning to the particular bytes, currently we interpret as PAK keys, details in pak.h - std::vector> m_extension_space; + std::vector> m_extension_space{}; // Each constructor sets its own serialization type implicitly based on which // arguments are given - DynaFedParamEntry() { m_signblock_witness_limit = 0; m_serialize_type = 0; }; + DynaFedParamEntry() {}; DynaFedParamEntry(const CScript& signblockscript_in, const uint32_t sbs_wit_limit_in) : m_signblockscript(signblockscript_in), m_signblock_witness_limit(sbs_wit_limit_in) { m_serialize_type = 1; }; DynaFedParamEntry(const CScript& signblockscript_in, const uint32_t sbs_wit_limit_in, const CScript& fedpeg_program_in, const CScript& fedpegscript_in, const std::vector> extension_space_in) : m_signblockscript(signblockscript_in), m_signblock_witness_limit(sbs_wit_limit_in), m_fedpeg_program(fedpeg_program_in), m_fedpegscript(fedpegscript_in), m_extension_space(extension_space_in) { m_serialize_type = 2; }; @@ -143,9 +140,9 @@ class DynaFedParams public: // Currently enforced by network, not all fields may be known - DynaFedParamEntry m_current; + DynaFedParamEntry m_current{}; // Proposed rules for next epoch - DynaFedParamEntry m_proposed; + DynaFedParamEntry m_proposed{}; DynaFedParams() {}; DynaFedParams(const DynaFedParamEntry& current, const DynaFedParamEntry& proposed) : m_current(current), m_proposed(proposed) {}; diff --git a/src/script/script.h b/src/script/script.h index bfe8469d1c..ef44f1211c 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -595,7 +595,7 @@ struct CScriptWitness { // Note that this encodes the data elements being pushed, rather than // encoding them as a CScript that pushes them. - std::vector > stack; + std::vector > stack{}; // Some compilers complain without a default constructor CScriptWitness() { }