Skip to content

Commit

Permalink
Allow to use low difficulty and higher block rewards for devnet (#2369)
Browse files Browse the repository at this point in the history
* Allow to use low difficulty and higher block rewards for devnet

Configurable through -minimumdifficultyblocks, -highsubsidyblocks and -highsubsidyfactor

* Fix review comments

* Handle review comments
  • Loading branch information
codablock authored Oct 25, 2018
1 parent de426e9 commit 1c25356
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
5 changes: 5 additions & 0 deletions src/chainparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 6 additions & 0 deletions src/pow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 1c25356

Please sign in to comment.