Skip to content

Commit

Permalink
Properly check the transaction time in CheckStakeKernelHash()
Browse files Browse the repository at this point in the history
  • Loading branch information
teamswipp committed Jan 13, 2020
1 parent 26b56af commit 5e3409a
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ bool CheckStakeKernelHash(unsigned int nBits, const CBlock& blockFrom, unsigned

uint256 hashBlockFrom = blockFrom.GetHash();

CBigNum bnCoinDayWeight = CBigNum(nValueIn) * GetWeight((int64_t)txPrev.nTime, (int64_t)nTimeTx) / COIN / (24 * 60 * 60);
CBigNum bnCoinDayWeight = CBigNum(nValueIn) * GetWeight((int64_t) txPrev.nTime, (int64_t )nTimeTx) / COIN / (24 * 60 * 60);

if (fTestNet)
bnCoinDayWeight *= 1000;
Expand Down Expand Up @@ -366,16 +366,14 @@ bool CheckStakeKernelHash(unsigned int nBits, const CBlock& blockFrom, unsigned
// Now check if proof-of-stake hash meets target protocol
if (CBigNum(hashProofOfStake) > bnCoinDayWeight * bnTargetPerCoinDay)
{
LogPrintf("%s : [ERROR] hashProofOfStake=%s > bnCoinDayWeight=%s * bnTargetPerCoinDay=%s\n",
__func__, hashProofOfStake.ToString().c_str(), bnCoinDayWeight.ToString().c_str(),
bnTargetPerCoinDay.ToString().c_str());

if (POS_HASHCHECK_MAX_BLOCK_AGE > GetTime() - blockFrom.GetBlockTime())
if (POS_HASHCHECK_MAX_BLOCK_AGE > GetTime() - nTimeTx)
return false;
else
{
LogPrintf("%s : skipping target protocol check on old POS block %d\n", __func__,
mapBlockIndex[hashBlockFrom]->nHeight);
LogPrintf("%s : skipping target protocol check on old POS block %d, time=%d "
"GetTime()=%d nTimeTx=%d\n", __func__,
mapBlockIndex[hashBlockFrom]->nHeight, GetTime() - nTimeTx,
GetTime(), nTimeTx);
}
}

Expand Down

0 comments on commit 5e3409a

Please sign in to comment.