收到新区块后,需要检测区块的工作量证明是否真的完成了,检测代码如下:
代码文件:src/pow.cpp
/**
*
**/
bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params& params)
{
bool fNegative;
bool fOverflow;
arith_uint256 bnTarget;
bnTarget.SetCompact(nBits, &fNegative, &fOverflow);
//negative:负数
//为负数;为0;溢出;大于最大限制
// Check range
if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit)) //难度值是否合理
return false;
// Check proof of work matches claimed amount
if (UintToArith256(hash) > bnTarget) //区块hash大于难度值
return false;
return true;
}
网友评论