Skip to content

Commit

Permalink
Merge pull request #11 from RSerhii/scypt2_fork
Browse files Browse the repository at this point in the history
Added checkpoint
  • Loading branch information
phoenixkonsole committed Sep 14, 2020
2 parents 236b49b + 6707ec4 commit 519db41
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
33 changes: 18 additions & 15 deletions src/pow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ bool IsScrypt2AdjustmentBlocks(const int nLastBlockHeight)
return nLastBlockHeight >= SCRYPT2_THRESHOLD + 3 && nLastBlockHeight < SCRYPT2_THRESHOLD + 50;
}

const int difficultyAdjustmentBlock = 668075;

bool IsScrypt2SecondAdjustment(const int nLastBlockHeight)
{
const int adjustmentBlock = 668075;
return nLastBlockHeight >= adjustmentBlock && nLastBlockHeight < adjustmentBlock + 190;
return nLastBlockHeight >= difficultyAdjustmentBlock && nLastBlockHeight < difficultyAdjustmentBlock + 190;
}

unsigned int static DarkGravityWave(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) {
Expand Down Expand Up @@ -106,20 +107,22 @@ unsigned int static DarkGravityWave(const CBlockIndex* pindexLast, const CBlockH
bnNew *= nActualTimespan;
bnNew /= nTargetTimespan;

// new difficulty can be maximum 50 times higher than previous
const int maxDifMultiplier = 40;
arith_uint256 bnLast = arith_uint256().SetCompact(pindexLast->nBits);
if ((bnLast / bnNew) > maxDifMultiplier) {
bnNew = bnLast / maxDifMultiplier;
}
if (pindexLast->nHeight >= difficultyAdjustmentBlock) {
// new difficulty can be maximum 50 times higher than previous
const int maxDifMultiplier = 40;
arith_uint256 bnLast = arith_uint256().SetCompact(pindexLast->nBits);
if ((bnLast / bnNew) > maxDifMultiplier) {
bnNew = bnLast / maxDifMultiplier;
}

// significantly reduce the difficulty if the last timespan is too large
const int64_t lastTimespan = pindexLast->GetBlockTime() - pindexLast->pprev->GetBlockTime();
const int timeMultiplier = lastTimespan / params.nPowTargetSpacing;
if (timeMultiplier > maxDifMultiplier) {
bnLast *= (timeMultiplier - (maxDifMultiplier / 2));
if (bnLast > bnNew) {
bnNew = bnLast;
// significantly reduce the difficulty if the last timespan is too large
const int64_t lastTimespan = pindexLast->GetBlockTime() - pindexLast->pprev->GetBlockTime();
const int timeMultiplier = lastTimespan / params.nPowTargetSpacing;
if (timeMultiplier > maxDifMultiplier) {
bnLast *= (timeMultiplier - (maxDifMultiplier / 2));
if (bnLast > bnNew) {
bnNew = bnLast;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/rpc/mining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ UniValue submitblock(const JSONRPCRequest& request)
}
}

submitblock_StateCatcher sc(block.GetNextBlockHash());
submitblock_StateCatcher sc(hash);
RegisterValidationInterface(&sc);
bool fAccepted = ProcessNewBlock(Params(), blockptr, true, nullptr);
UnregisterValidationInterface(&sc);
Expand Down
4 changes: 2 additions & 2 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2118,8 +2118,8 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
assert(pindex);
// pindex->phashBlock can be null if called by CreateNewBlock/TestBlockValidity
assert((pindex->phashBlock == nullptr) ||
(*pindex->phashBlock == block.GetMinedHash(pindex->nHeight)) ||
(*pindex->phashBlock == block.GetHash()));
(*pindex->phashBlock == block.GetHash()) ||
(*pindex->phashBlock == block.GetMinedHash(pindex->nHeight)));
int64_t nTimeStart = GetTimeMicros();

// Check it again in case a previous version let a bad block in
Expand Down

0 comments on commit 519db41

Please sign in to comment.