Skip to content

Commit

Permalink
[Consensus] Readd checks removed in 3b778f5
Browse files Browse the repository at this point in the history
Two importants checks were removed while refactoring to add zPIV
staking. Their equivalents were added to zPIV staking but missing for
simple PIV staking. We add them back with this commit.
  • Loading branch information
Warrows committed Jun 17, 2019
1 parent 2621b7f commit 105ee5f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
19 changes: 13 additions & 6 deletions src/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,13 +412,14 @@ bool CheckProofOfStake(const CBlock block, uint256& hashProofOfStake, std::uniqu
stake = std::unique_ptr<CStakeInput>(pivInput);
}

CBlockIndex* pindex = stake->GetIndexFrom();
if (!pindex)
return error("%s: Failed to find the block index", __func__);
//Get the
CBlockIndex* pindexfrom = stake->GetIndexFrom();
if (!pindexfrom)
return error("%s: Failed to find the block index for stake origin", __func__);

// Read block header
CBlock blockprev;
if (!ReadBlockFromDisk(blockprev, pindex->GetBlockPos()))
CBlock blockfrom;
if (!ReadBlockFromDisk(blockfrom, pindexfrom->GetBlockPos()))
return error("CheckProofOfStake(): INFO: failed to find block");

uint256 bnTargetPerCoinDay;
Expand All @@ -428,8 +429,14 @@ bool CheckProofOfStake(const CBlock block, uint256& hashProofOfStake, std::uniqu
if (!stake->GetModifier(nStakeModifier))
return error("%s failed to get modifier for stake input\n", __func__);

unsigned int nBlockFromTime = blockprev.nTime;
unsigned int nBlockFromTime = blockfrom.nTime;
unsigned int nTxTime = block.nTime;
if (!txin.IsZerocoinSpend()) { //Equivalent for zPIV is checked above in ContextualCheckZerocoinStake()
if (nTxTime < nBlockFromTime) // Transaction timestamp nTxTime
return error("CheckStakeKernelHash() : nTime violation - nBlockFromTime=%d nTimeTx=%d", nBlockFromTime, nTxTime);
if (nBlockFromTime + nStakeMinAge > nTxTime) // Min age requirement
return error("CheckStakeKernelHash() : min age violation - nBlockFromTime=%d nStakeMinAge=%d nTimeTx=%d", nBlockFromTime, nStakeMinAge, nTxTime);
}
if (!CheckStake(stake->GetUniqueness(), stake->GetValue(), nStakeModifier, bnTargetPerCoinDay, nBlockFromTime,
nTxTime, hashProofOfStake)) {
return error("CheckProofOfStake() : INFO: check kernel failed on coinstake %s, hashProof=%s \n",
Expand Down
2 changes: 1 addition & 1 deletion src/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ bool Stake(CStakeInput* stakeInput, unsigned int nBits, unsigned int nTimeBlockF

// Check kernel hash target and coinstake signature
// Sets hashProofOfStake on success return
bool CheckProofOfStake(const CBlock block, uint256& hashProofOfStake, std::unique_ptr<CStakeInput>& stake);
bool CheckProofOfStake(const CBlock block, uint256& hashProofOfStake, std::unique_ptr<CStakeInput>& stake, int nPreviousBlockHeight);

// Check whether the coinstake timestamp meets protocol
bool CheckCoinStakeTimestamp(int64_t nTimeBlock, int64_t nTimeTx);
Expand Down

0 comments on commit 105ee5f

Please sign in to comment.