diff --git a/src/chain.h b/src/chain.h index 33e588750d0f1..8aed998e4491f 100644 --- a/src/chain.h +++ b/src/chain.h @@ -192,11 +192,11 @@ class CBlockIndex //! block header int32_t nVersion{0}; uint256 hashMerkleRoot{}; - uint256 hashFinalSaplingRoot{}; + Optional hashFinalSaplingRoot{}; uint32_t nTime{0}; uint32_t nBits{0}; uint32_t nNonce{0}; - uint256 nAccumulatorCheckpoint{}; + Optional nAccumulatorCheckpoint{}; //! (memory only) Sequential id assigned to distinguish order in which blocks are received. uint32_t nSequenceId{0}; @@ -297,12 +297,25 @@ class CDiskBlockIndex : public CBlockIndex READWRITE(obj.nTime); READWRITE(obj.nBits); READWRITE(obj.nNonce); - if(obj.nVersion > 3 && obj.nVersion < 7) - READWRITE(obj.nAccumulatorCheckpoint); + if(this->nVersion > 3 && this->nVersion < 7) { + if (ser_action.ForRead()) { + uint256 _nAccumulatorCheckpoint; + READWRITE(_nAccumulatorCheckpoint); + nAccumulatorCheckpoint = _nAccumulatorCheckpoint; + } else { + READWRITE(*nAccumulatorCheckpoint); + } + } // Sapling blocks if (obj.nVersion >= 8) { - READWRITE(obj.hashFinalSaplingRoot); + if (ser_action.ForRead()) { + uint256 _hashFinalSaplingRoot; + READWRITE(_hashFinalSaplingRoot); + hashFinalSaplingRoot = _hashFinalSaplingRoot; + } else { + READWRITE(*hashFinalSaplingRoot); + } READWRITE(obj.nSaplingValue); } } else if (nSerVersion > DBI_OLD_SER_VERSION && ser_action.ForRead()) { @@ -320,7 +333,11 @@ class CDiskBlockIndex : public CBlockIndex READWRITE(obj.nNonce); if (obj.nVersion > 3) { READWRITE(mapZerocoinSupply); - if (obj.nVersion < 7) READWRITE(obj.nAccumulatorCheckpoint); + if(this->nVersion < 7) { + uint256 _nAccumulatorCheckpoint; + READWRITE(_nAccumulatorCheckpoint); + nAccumulatorCheckpoint = _nAccumulatorCheckpoint; + } } } else if (ser_action.ForRead()) { // Serialization with CLIENT_VERSION = 4009900- @@ -355,7 +372,9 @@ class CDiskBlockIndex : public CBlockIndex if (obj.nVersion > 3) { std::map mapZerocoinSupply; std::vector vMintDenominationsInBlock; - READWRITE(obj.nAccumulatorCheckpoint); + uint256 _nAccumulatorCheckpoint; + READWRITE(_nAccumulatorCheckpoint); + nAccumulatorCheckpoint = _nAccumulatorCheckpoint; READWRITE(mapZerocoinSupply); READWRITE(vMintDenominationsInBlock); } diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 3e9e331184dbd..d2be91c09caa0 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -269,8 +269,6 @@ class CMainParams : public CChainParams "31438167899885040445364023527381951378636564391212010397122822120720357"; consensus.ZC_MaxPublicSpendsPerTx = 637; // Assume about 220 bytes each input consensus.ZC_MaxSpendsPerTx = 7; // Assume about 20kb each input - consensus.ZC_MinMintConfirmations = 20; - consensus.ZC_MinMintFee = 1 * CENT; consensus.ZC_MinStakeDepth = 200; consensus.ZC_TimeStart = 1508214600; // October 17, 2017 4:30:00 AM consensus.ZC_HeightStart = 863735; @@ -426,8 +424,6 @@ class CTestNetParams : public CChainParams "31438167899885040445364023527381951378636564391212010397122822120720357"; consensus.ZC_MaxPublicSpendsPerTx = 637; // Assume about 220 bytes each input consensus.ZC_MaxSpendsPerTx = 7; // Assume about 20kb each input - consensus.ZC_MinMintConfirmations = 20; - consensus.ZC_MinMintFee = 1 * CENT; consensus.ZC_MinStakeDepth = 200; consensus.ZC_TimeStart = 1508214600; // October 17, 2017 4:30:00 AM @@ -571,8 +567,6 @@ class CRegTestParams : public CChainParams "31438167899885040445364023527381951378636564391212010397122822120720357"; consensus.ZC_MaxPublicSpendsPerTx = 637; // Assume about 220 bytes each input consensus.ZC_MaxSpendsPerTx = 7; // Assume about 20kb each input - consensus.ZC_MinMintConfirmations = 10; - consensus.ZC_MinMintFee = 1 * CENT; consensus.ZC_MinStakeDepth = 10; consensus.ZC_TimeStart = 0; // not implemented on regtest consensus.ZC_HeightStart = 0; diff --git a/src/consensus/params.h b/src/consensus/params.h index bfb6203b24839..21e00dd21369c 100644 --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -250,8 +250,6 @@ struct Params { std::string ZC_Modulus; // parsed in Zerocoin_Params (either as hex or dec string) int ZC_MaxPublicSpendsPerTx; int ZC_MaxSpendsPerTx; - int ZC_MinMintConfirmations; - CAmount ZC_MinMintFee; int ZC_MinStakeDepth; int ZC_TimeStart; int ZC_HeightStart; diff --git a/src/legacy/stakemodifier.cpp b/src/legacy/stakemodifier.cpp index a718a571043f6..ad5a781d310e6 100644 --- a/src/legacy/stakemodifier.cpp +++ b/src/legacy/stakemodifier.cpp @@ -117,7 +117,7 @@ bool GetOldStakeModifier(CStakeInput* stake, uint64_t& nStakeModifier) const int nHeightStop = std::min(chainActive.Height(), Params().GetConsensus().height_last_ZC_AccumCheckpoint-1); while (pindexFrom && pindexFrom->nHeight + 1 <= nHeightStop) { if (pindexFrom->GetBlockTime() - nTimeBlockFrom > 60 * 60) { - nStakeModifier = pindexFrom->nAccumulatorCheckpoint.GetCheapHash(); + nStakeModifier = pindexFrom->nAccumulatorCheckpoint->GetCheapHash(); return true; } pindexFrom = chainActive.Next(pindexFrom); diff --git a/src/legacy/validation_zerocoin_legacy.cpp b/src/legacy/validation_zerocoin_legacy.cpp index b1b4d296b2e3f..507364a4037ff 100644 --- a/src/legacy/validation_zerocoin_legacy.cpp +++ b/src/legacy/validation_zerocoin_legacy.cpp @@ -54,8 +54,8 @@ void CacheAccChecksum(const CBlockIndex* pindex, bool fWrite) pindex->nAccumulatorCheckpoint == pindex->pprev->nAccumulatorCheckpoint) return; - arith_uint256 accCurr = UintToArith256(pindex->nAccumulatorCheckpoint); - arith_uint256 accPrev = UintToArith256(pindex->pprev->nAccumulatorCheckpoint); + arith_uint256 accCurr = UintToArith256(*pindex->nAccumulatorCheckpoint); + arith_uint256 accPrev = UintToArith256(*pindex->pprev->nAccumulatorCheckpoint); // add/remove changed checksums to/from cache for (int i = (int)libzerocoin::zerocoinDenomList.size()-1; i >= 0; i--) { const uint32_t nChecksum = accCurr.Get32(); diff --git a/src/primitives/block.cpp b/src/primitives/block.cpp index 37936129f0525..9b0462c629b4f 100644 --- a/src/primitives/block.cpp +++ b/src/primitives/block.cpp @@ -41,7 +41,7 @@ std::string CBlock::ToString() const hashPrevBlock.ToString(), hashMerkleRoot.ToString(), nTime, nBits, nNonce, - hashFinalSaplingRoot.ToString(), + hashFinalSaplingRoot->ToString(), vtx.size()); for (unsigned int i = 0; i < vtx.size(); i++) { diff --git a/src/primitives/block.h b/src/primitives/block.h index 411151c2b3485..2103143e829d4 100644 --- a/src/primitives/block.h +++ b/src/primitives/block.h @@ -30,8 +30,8 @@ class CBlockHeader uint32_t nTime; uint32_t nBits; uint32_t nNonce; - uint256 nAccumulatorCheckpoint; // only for version 4, 5 and 6. - uint256 hashFinalSaplingRoot; // only for version 8+ + Optional nAccumulatorCheckpoint; // only for version 4, 5 and 6. + Optional hashFinalSaplingRoot; // only for version 8+ CBlockHeader() { @@ -42,12 +42,26 @@ class CBlockHeader READWRITE(obj.nVersion, obj.hashPrevBlock, obj.hashMerkleRoot, obj.nTime, obj.nBits, obj.nNonce); //zerocoin active, header changes to include accumulator checksum - if(obj.nVersion > 3 && obj.nVersion < 7) - READWRITE(obj.nAccumulatorCheckpoint); + if(nVersion > 3 && nVersion < 7) { + if (ser_action.ForRead()) { + uint256 _nAccumulatorCheckpoint; + READWRITE(_nAccumulatorCheckpoint); + nAccumulatorCheckpoint = _nAccumulatorCheckpoint; + } else { + READWRITE(*nAccumulatorCheckpoint); + } + } // Sapling active - if (obj.nVersion >= 8) - READWRITE(obj.hashFinalSaplingRoot); + if (nVersion >= 8) { + if (ser_action.ForRead()) { + uint256 _hashFinalSaplingRoot; + READWRITE(_hashFinalSaplingRoot); + hashFinalSaplingRoot = _hashFinalSaplingRoot; + } else { + READWRITE(*hashFinalSaplingRoot); + } + } } void SetNull() @@ -58,8 +72,8 @@ class CBlockHeader nTime = 0; nBits = 0; nNonce = 0; - nAccumulatorCheckpoint.SetNull(); - hashFinalSaplingRoot.SetNull(); + nAccumulatorCheckpoint.reset(); + hashFinalSaplingRoot.reset(); } bool IsNull() const diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index f096b294a840a..12e43a9316878 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -126,7 +126,7 @@ UniValue blockheaderToJSON(const CBlockIndex* tip, const CBlockIndex* blockindex result.pushKV("bits", strprintf("%08x", blockindex->nBits)); result.pushKV("difficulty", GetDifficulty(blockindex)); result.pushKV("chainwork", blockindex->nChainWork.GetHex()); - result.pushKV("acc_checkpoint", blockindex->nAccumulatorCheckpoint.GetHex()); + result.pushKV("acc_checkpoint", blockindex->nAccumulatorCheckpoint->GetHex()); // Sapling shield pool value result.pushKV("shield_pool_value", ValuePoolDesc(blockindex->nChainSaplingValue, blockindex->nSaplingValue)); if (blockindex->pprev) @@ -147,8 +147,8 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* tip, const CBlockIn result.pushKV("height", blockindex->nHeight); result.pushKV("version", block.nVersion); result.pushKV("merkleroot", block.hashMerkleRoot.GetHex()); - result.pushKV("acc_checkpoint", block.nAccumulatorCheckpoint.GetHex()); - result.pushKV("finalsaplingroot", block.hashFinalSaplingRoot.GetHex()); + result.pushKV("acc_checkpoint", block.nAccumulatorCheckpoint->GetHex()); + result.pushKV("finalsaplingroot", block.hashFinalSaplingRoot->GetHex()); UniValue txs(UniValue::VARR); for (const auto& txIn : block.vtx) { const CTransaction& tx = *txIn; diff --git a/src/validation.cpp b/src/validation.cpp index 323de2aac46dc..f968e19d86ef1 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1364,7 +1364,7 @@ DisconnectResult DisconnectBlock(CBlock& block, const CBlockIndex* pindex, CCoin // the Sapling activation height. Otherwise, the last anchor was the // empty root. if (consensus.NetworkUpgradeActive(pindex->pprev->nHeight, Consensus::UPGRADE_V5_0)) { - view.PopAnchor(pindex->pprev->hashFinalSaplingRoot); + view.PopAnchor(*pindex->pprev->hashFinalSaplingRoot); } else { view.PopAnchor(SaplingMerkleTree::empty_root()); } @@ -1603,7 +1603,7 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd if (isV5UpgradeEnforced) { // If Sapling is active, block.hashFinalSaplingRoot must be the // same as the root of the Sapling tree - if (block.hashFinalSaplingRoot != sapling_tree.root()) { + if (*block.hashFinalSaplingRoot != sapling_tree.root()) { return state.DoS(100, error("ConnectBlock(): block's hashFinalSaplingRoot is incorrect (should be Sapling tree root)"), REJECT_INVALID, "bad-sapling-root-in-block"); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index c430877bfa44d..79d1d251d5fe9 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1327,7 +1327,7 @@ void CWallet::BlockConnected(const std::shared_ptr& pblock, const Params().GetConsensus().NetworkUpgradeActive(pprev->nHeight, Consensus::UPGRADE_V5_0); if (isSaplingActive) { - assert(pcoinsTip->GetSaplingAnchorAt(pprev->hashFinalSaplingRoot, oldSaplingTree)); + assert(pcoinsTip->GetSaplingAnchorAt(*pprev->hashFinalSaplingRoot, oldSaplingTree)); } else { assert(pcoinsTip->GetSaplingAnchorAt(SaplingMerkleTree::empty_root(), oldSaplingTree)); } @@ -1925,7 +1925,7 @@ CBlockIndex* CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, CBlock if (pindex->pprev) { if (Params().GetConsensus().NetworkUpgradeActive(pindex->pprev->nHeight, Consensus::UPGRADE_V5_0)) { SaplingMerkleTree saplingTree; - assert(pcoinsTip->GetSaplingAnchorAt(pindex->pprev->hashFinalSaplingRoot, saplingTree)); + assert(pcoinsTip->GetSaplingAnchorAt(*pindex->pprev->hashFinalSaplingRoot, saplingTree)); // Increment note witness caches ChainTipAdded(pindex, &block, saplingTree); } diff --git a/src/zpiv/zpos.cpp b/src/zpiv/zpos.cpp index 53d3e6825ed60..70fa07bfbb2ba 100644 --- a/src/zpiv/zpos.cpp +++ b/src/zpiv/zpos.cpp @@ -42,7 +42,7 @@ static const CBlockIndex* FindIndexFrom(uint32_t nChecksum, libzerocoin::CoinDen CBlockIndex* pindex = chainActive[(cpHeight/10)*10 - 10]; if (!pindex) return nullptr; - while (ParseAccChecksum(pindex->nAccumulatorCheckpoint, denom) == nChecksum && pindex->nHeight > zc_activation) { + while (ParseAccChecksum(*pindex->nAccumulatorCheckpoint, denom) == nChecksum && pindex->nHeight > zc_activation) { //Skip backwards in groups of 10 blocks since checkpoints only change every 10 blocks pindex = chainActive[pindex->nHeight - 10]; } @@ -85,7 +85,7 @@ CLegacyZPivStake* CLegacyZPivStake::NewZPivStake(const CTxIn& txin, int nHeight) // The checkpoint needs to be from 200 blocks ago const int cpHeight = nHeight - 1 - consensus.ZC_MinStakeDepth; - if (ParseAccChecksum(chainActive[cpHeight]->nAccumulatorCheckpoint, _denom) != _nChecksum) { + if (ParseAccChecksum(*chainActive[cpHeight]->nAccumulatorCheckpoint, _denom) != _nChecksum) { LogPrint(BCLog::LEGACYZC, "%s : accum. checksum at height %d is wrong.", __func__, nHeight); }