diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 265d3c366d843..9816a5ad427eb 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -554,6 +554,13 @@ class CDevNetParams : public CChainParams { 0.01 // * estimated number of transactions per second }; } + + void UpdateSubsidyAndDiffParams(int nMinimumDifficultyBlocks, int nHighSubsidyBlocks, int nHighSubsidyFactor) + { + consensus.nMinimumDifficultyBlocks = nMinimumDifficultyBlocks; + consensus.nHighSubsidyBlocks = nHighSubsidyBlocks; + consensus.nHighSubsidyFactor = nHighSubsidyFactor; + } }; static CDevNetParams *devNetParams; @@ -731,3 +738,9 @@ void UpdateRegtestBudgetParameters(int nMasternodePaymentsStartBlock, int nBudge { regTestParams.UpdateBudgetParameters(nMasternodePaymentsStartBlock, nBudgetPaymentsStartBlock, nSuperblockStartBlock); } + +void UpdateDevnetSubsidyAndDiffParams(int nMinimumDifficultyBlocks, int nHighSubsidyBlocks, int nHighSubsidyFactor) +{ + assert(devNetParams); + devNetParams->UpdateSubsidyAndDiffParams(nMinimumDifficultyBlocks, nHighSubsidyBlocks, nHighSubsidyFactor); +} diff --git a/src/chainparams.h b/src/chainparams.h index 29e3b95884741..3c93e0c9aa2f3 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -148,4 +148,9 @@ void UpdateRegtestBIP9Parameters(Consensus::DeploymentPos d, int64_t nStartTime, */ void UpdateRegtestBudgetParameters(int nMasternodePaymentsStartBlock, int nBudgetPaymentsStartBlock, int nSuperblockStartBlock); +/** + * Allows modifying the subsidy and difficulty devnet parameters. + */ +void UpdateDevnetSubsidyAndDiffParams(int nMinimumDifficultyBlocks, int nHighSubsidyBlocks, int nHighSubsidyFactor); + #endif // BITCOIN_CHAINPARAMS_H diff --git a/src/consensus/params.h b/src/consensus/params.h index f602bc029ec6d..6c3efccf7a05c 100644 --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -91,6 +91,11 @@ struct Params { int64_t DifficultyAdjustmentInterval() const { return nPowTargetTimespan / nPowTargetSpacing; } uint256 nMinimumChainWork; uint256 defaultAssumeValid; + + /** these parameters are only used on devnet and can be configured from the outside */ + int nMinimumDifficultyBlocks{0}; + int nHighSubsidyBlocks{0}; + int nHighSubsidyFactor{1}; }; } // namespace Consensus diff --git a/src/init.cpp b/src/init.cpp index c8071fc9ae1a3..86626e3dc8252 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1323,6 +1323,15 @@ bool AppInitParameterInteraction() UpdateRegtestBudgetParameters(nMasternodePaymentsStartBlock, nBudgetPaymentsStartBlock, nSuperblockStartBlock); } + if (chainparams.NetworkIDString() == CBaseChainParams::DEVNET) { + int nMinimumDifficultyBlocks = GetArg("-minimumdifficultyblocks", chainparams.GetConsensus().nMinimumDifficultyBlocks); + int nHighSubsidyBlocks = GetArg("-highsubsidyblocks", chainparams.GetConsensus().nHighSubsidyBlocks); + int nHighSubsidyFactor = GetArg("-highsubsidyfactor", chainparams.GetConsensus().nHighSubsidyFactor); + UpdateDevnetSubsidyAndDiffParams(nMinimumDifficultyBlocks, nHighSubsidyBlocks, nHighSubsidyFactor); + } else if (IsArgSet("-minimumdifficultyblocks") || IsArgSet("-highsubsidyblocks") || IsArgSet("-highsubsidyfactor")) { + return InitError("Difficulty and subsidy parameters may only be overridden on devnet."); + } + return true; } diff --git a/src/pow.cpp b/src/pow.cpp index 749ff9db28497..34af27b9b1d2b 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -210,6 +210,12 @@ unsigned int GetNextWorkRequiredBTC(const CBlockIndex* pindexLast, const CBlockH unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) { + // this is only active on devnets + if (pindexLast->nHeight < params.nMinimumDifficultyBlocks) { + unsigned int nProofOfWorkLimit = UintToArith256(params.powLimit).GetCompact(); + return nProofOfWorkLimit; + } + // Most recent algo first if (pindexLast->nHeight + 1 >= params.nPowDGWHeight) { return DarkGravityWave(pindexLast, pblock, params); diff --git a/src/validation.cpp b/src/validation.cpp index b1768672506ef..aaebe6dd7dd3a 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1171,6 +1171,11 @@ CAmount GetBlockSubsidy(int nPrevBits, int nPrevHeight, const Consensus::Params& nSubsidy -= nSubsidy/14; } + // this is only active on devnets + if (nPrevHeight < consensusParams.nHighSubsidyBlocks) { + nSubsidy *= consensusParams.nHighSubsidyFactor; + } + // Hard fork to reduce the block reward by 10 extra percent (allowing budget/superblocks) CAmount nSuperblockPart = (nPrevHeight > consensusParams.nBudgetPaymentsStartBlock) ? nSubsidy/10 : 0;