Skip to content

Commit

Permalink
[Cleanup] LoadStakeInput: no need for the previous block
Browse files Browse the repository at this point in the history
  • Loading branch information
random-zebra committed May 3, 2021
1 parent c6f71b2 commit 944e793
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions src/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,8 @@ bool CStakeKernel::CheckKernelHash(bool fSkipLog) const
*/

// helper function for CheckProofOfStake and GetStakeKernelHash
bool LoadStakeInput(const CBlock& block, const CBlockIndex* pindexPrev, std::unique_ptr<CStakeInput>& stake)
static bool LoadStakeInput(const CBlock& block, std::unique_ptr<CStakeInput>& stake)
{
// If previous index is not provided, look for it in the blockmap
if (!pindexPrev) {
BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock);
if (mi != mapBlockIndex.end() && (*mi).second) pindexPrev = (*mi).second;
else return error("%s : couldn't find previous block", __func__);
} else {
// check that is the actual parent block
if (block.hashPrevBlock != pindexPrev->GetBlockHash())
return error("%s : previous block mismatch", __func__);
}

// Check that this is a PoS block
if (!block.IsProofOfStake())
return error("called on non PoS block");
Expand Down Expand Up @@ -153,7 +142,7 @@ bool CheckProofOfStake(const CBlock& block, std::string& strError, const CBlockI
const int nHeight = pindexPrev->nHeight + 1;
// Initialize stake input
std::unique_ptr<CStakeInput> stakeInput;
if (!LoadStakeInput(block, pindexPrev, stakeInput)) {
if (!LoadStakeInput(block, stakeInput)) {
strError = "stake input initialization failed";
return false;
}
Expand Down Expand Up @@ -207,7 +196,7 @@ bool GetStakeKernelHash(uint256& hashRet, const CBlock& block, const CBlockIndex
{
// Initialize stake input
std::unique_ptr<CStakeInput> stakeInput;
if (!LoadStakeInput(block, pindexPrev, stakeInput))
if (!LoadStakeInput(block, stakeInput))
return error("%s : stake input initialization failed", __func__);

CStakeKernel stakeKernel(pindexPrev, stakeInput.get(), block.nBits, block.nTime);
Expand Down

0 comments on commit 944e793

Please sign in to comment.