diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 7b8a5a7c3..582c7b6f9 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -358,6 +358,7 @@ public: // in #2795. nSproutValuePoolCheckpointHeight = 440329; nSproutValuePoolCheckpointBalance = 40000029096803; + fSproutValuePoolCheckpointEnabled = true; // Founders reward script expects a vector of 2-of-3 multisig addresses vFoundersRewardAddress = { @@ -472,6 +473,10 @@ public: // Founders reward script expects a vector of 2-of-3 multisig addresses vFoundersRewardAddress = { "t2FwcEhFdNXuFMv1tcYwaBJtYVtMj8b1uTg" }; assert(vFoundersRewardAddress.size() <= consensus.GetLastFoundersRewardBlockHeight()); + + // Enable Sprout shielded value pool checkpointing on + // regtest. + fSproutValuePoolCheckpointEnabled = true; } void UpdateNetworkUpgradeParameters(Consensus::UpgradeIndex idx, int nActivationHeight) diff --git a/src/chainparams.h b/src/chainparams.h index 90a0712ae..c9c1284d3 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -72,6 +72,7 @@ public: CAmount SproutValuePoolCheckpointHeight() const { return nSproutValuePoolCheckpointHeight; } CAmount SproutValuePoolCheckpointBalance() const { return nSproutValuePoolCheckpointBalance; } + bool SproutValuePoolCheckpointEnabled() const { return fSproutValuePoolCheckpointEnabled; } const CBlock& GenesisBlock() const { return genesis; } /** Make miner wait to have peers to avoid wasting work */ @@ -131,6 +132,7 @@ protected: CAmount nSproutValuePoolCheckpointHeight = 0; CAmount nSproutValuePoolCheckpointBalance = 0; + bool fSproutValuePoolCheckpointEnabled = false; }; /** diff --git a/src/main.cpp b/src/main.cpp index 3516deff6..40291aab1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2451,9 +2451,8 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin return true; } - // If we're on testnet, reject a block that results in a negative - // shielded value pool balance. - if (Params().NetworkIDString() == "test") { + // Reject a block that results in a negative shielded value pool balance. + if (Params().SproutValuePoolCheckpointEnabled()) { // Sprout // // We can expect nChainSproutValue to be valid after the hardcoded @@ -3327,6 +3326,12 @@ void FallbackSproutValuePoolBalance( const CChainParams& chainparams ) { + // We might not want to enable the checkpointing for mainnet + // yet. + if (!chainparams.SproutValuePoolCheckpointEnabled()) { + return; + } + // Check if the height of this block matches the checkpoint if (pindex->nHeight == chainparams.SproutValuePoolCheckpointHeight()) { // Are we monitoring the Sprout pool? @@ -3348,7 +3353,6 @@ void FallbackSproutValuePoolBalance( bool ReceivedBlockTransactions(const CBlock &block, CValidationState& state, CBlockIndex *pindexNew, const CDiskBlockPos& pos) { const CChainParams& chainparams = Params(); - bool this_is_testnet = chainparams.NetworkIDString() == "test"; pindexNew->nTx = block.vtx.size(); pindexNew->nChainTx = 0; @@ -3403,11 +3407,8 @@ bool ReceivedBlockTransactions(const CBlock &block, CValidationState& state, CBl pindex->nChainSaplingValue = pindex->nSaplingValue; } - // Fall back to hardcoded Sprout value pool balance if we're on - // testnet. - if (this_is_testnet) { - FallbackSproutValuePoolBalance(pindex, chainparams); - } + // Fall back to hardcoded Sprout value pool balance + FallbackSproutValuePoolBalance(pindex, chainparams); { LOCK(cs_nBlockSequenceId); @@ -4061,7 +4062,6 @@ CBlockIndex * InsertBlockIndex(uint256 hash) bool static LoadBlockIndexDB() { const CChainParams& chainparams = Params(); - bool this_is_testnet = chainparams.NetworkIDString() == "test"; if (!pblocktree->LoadBlockIndexGuts()) return false; @@ -4109,11 +4109,8 @@ bool static LoadBlockIndexDB() pindex->nChainSaplingValue = pindex->nSaplingValue; } - // Fall back to hardcoded Sprout value pool balance if we're on - // testnet. - if (this_is_testnet) { - FallbackSproutValuePoolBalance(pindex, chainparams); - } + // Fall back to hardcoded Sprout value pool balance + FallbackSproutValuePoolBalance(pindex, chainparams); } // Construct in-memory chain of branch IDs. // Relies on invariant: a block that does not activate a network upgrade diff --git a/src/miner.cpp b/src/miner.cpp index f45582ba2..ec5a198ce 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -109,9 +109,6 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) { const CChainParams& chainparams = Params(); - bool this_is_testnet_or_regtest = - (chainparams.NetworkIDString() == "test") || - (chainparams.NetworkIDString() == "regtest"); // Create new block std::unique_ptr pblocktemplate(new CBlockTemplate()); @@ -263,7 +260,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) CAmount sproutValue = 0; CAmount saplingValue = 0; bool monitoring_pool_balances = true; - if (this_is_testnet_or_regtest) { + if (chainparams.SproutValuePoolCheckpointEnabled()) { if (pindexPrev->nChainSproutValue) { sproutValue = *pindexPrev->nChainSproutValue; } else { @@ -331,7 +328,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) if (!ContextualCheckInputs(tx, state, view, true, MANDATORY_SCRIPT_VERIFY_FLAGS, true, txdata, Params().GetConsensus(), consensusBranchId)) continue; - if (this_is_testnet_or_regtest && monitoring_pool_balances) { + if (chainparams.SproutValuePoolCheckpointEnabled() && monitoring_pool_balances) { // Does this transaction lead to a turnstile violation? CAmount sproutValueDummy = sproutValue; @@ -344,8 +341,14 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) sproutValueDummy -= js.vpub_new; } - if (sproutValueDummy < 0) continue; - if (saplingValueDummy < 0) continue; + if (sproutValueDummy < 0) { + LogPrintf("CreateNewBlock(): tx %s appears to violate Sprout turnstile", tx.GetHash().ToString()); + continue; + } + if (saplingValueDummy < 0) { + LogPrintf("CreateNewBlock(): tx %s appears to violate Sapling turnstile", tx.GetHash().ToString()); + continue; + } sproutValue = sproutValueDummy; saplingValue = saplingValueDummy;