Use IsProtocolV1RetargetingFixed(), IsProtocolV3() everywhere

This commit is contained in:
lateminer
2019-03-27 20:00:34 +03:00
parent 7fd6bdd10d
commit 9148f30fbc
3 changed files with 6 additions and 5 deletions

View File

@@ -67,6 +67,7 @@ struct Params {
int64_t nProtocolV1RetargetingFixedTime;
int64_t nProtocolV2Time;
int64_t nProtocolV3Time;
bool IsProtocolV1RetargetingFixed(int64_t nTime) const { return nTime > nProtocolV1RetargetingFixedTime && nTime != 1395631999; }
bool IsProtocolV2(int64_t nTime) const { return nTime > nProtocolV2Time && nTime != 1407053678; }
bool IsProtocolV3(int64_t nTime) const { return nTime > nProtocolV3Time && nTime != 1444028400; }
unsigned int GetTargetSpacing(int nHeight) { return IsProtocolV2(nHeight) ? 64 : 60; }

View File

@@ -2340,7 +2340,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
pindex->nStakeModifier = ComputeStakeModifier(pindex->pprev, block.IsProofOfStake() ? block.vtx[1].vin[0].prevout.hash : block.GetHash());
// Check proof-of-stake
if (block.IsProofOfStake() && block.GetBlockTime() > chainparams.GetConsensus().nProtocolV3Time) {
if (block.IsProofOfStake() && chainparams.GetConsensus().IsProtocolV3(block.GetBlockTime())) {
const COutPoint &prevout = block.vtx[1].vin[0].prevout;
const CCoins *coins = view.AccessCoins(prevout.hash);
if (!coins)
@@ -2416,7 +2416,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
flags |= SCRIPT_VERIFY_LOW_S;
// Start enforcing CHECKLOCKTIMEVERIFY, (BIP65) since protocol v3
if (block.GetBlockTime() > chainparams.GetConsensus().nProtocolV3Time) {
if (chainparams.GetConsensus().IsProtocolV3(block.GetBlockTime())) {
flags |= SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY;
flags |= SCRIPT_VERIFY_NULLDUMMY;
}
@@ -2518,7 +2518,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
REJECT_INVALID, "bad-cb-amount");
}
if (block.IsProofOfStake() && block.GetBlockTime() > chainparams.GetConsensus().nProtocolV3Time) {
if (block.IsProofOfStake() && chainparams.GetConsensus().IsProtocolV3(block.GetBlockTime())) {
CAmount blockReward = nFees + GetProofOfStakeSubsidy();
if (nActualStakeReward > blockReward)
return state.DoS(100,

View File

@@ -61,9 +61,9 @@ unsigned int CalculateNextTargetRequired(const CBlockIndex* pindexLast, int64_t
int64_t nActualSpacing = pindexLast->GetBlockTime() - nFirstBlockTime;
// Limit adjustment step
if (pindexLast->GetBlockTime() > params.nProtocolV1RetargetingFixedTime && nActualSpacing < 0)
if (params.IsProtocolV1RetargetingFixed(pindexLast->GetBlockTime()) && nActualSpacing < 0)
nActualSpacing = nTargetSpacing;
if (pindexLast->GetBlockTime() > params.nProtocolV3Time && nActualSpacing > nTargetSpacing*10)
if (params.IsProtocolV3(pindexLast->GetBlockTime()) && nActualSpacing > nTargetSpacing*10)
nActualSpacing = nTargetSpacing*10;
// retarget with exponential moving toward target spacing