Changeset View
Changeset View
Standalone View
Standalone View
src/chain.cpp
Show First 20 Lines • Show All 135 Lines • ▼ Show 20 Lines | arith_uint256 GetBlockProof(const CBlockIndex &block) { | ||||
bool fOverflow; | bool fOverflow; | ||||
bnTarget.SetCompact(block.nBits, &fNegative, &fOverflow); | bnTarget.SetCompact(block.nBits, &fNegative, &fOverflow); | ||||
if (fNegative || fOverflow || bnTarget == 0) { | if (fNegative || fOverflow || bnTarget == 0) { | ||||
return 0; | return 0; | ||||
} | } | ||||
// We need to compute 2**256 / (bnTarget+1), but we can't represent 2**256 | // We need to compute 2**256 / (bnTarget+1), but we can't represent 2**256 | ||||
// as it's too large for an arith_uint256. However, as 2**256 is at least as | // as it's too large for an arith_uint256. However, as 2**256 is at least as | ||||
// large as bnTarget+1, it is equal to ((2**256 - bnTarget - 1) / | // large as bnTarget+1, it is equal to ((2**256 - bnTarget - 1) / | ||||
// (bnTarget+1)) + 1, or ~bnTarget / (nTarget+1) + 1. | // (bnTarget+1)) + 1, or ~bnTarget / (bnTarget+1) + 1. | ||||
return (~bnTarget / (bnTarget + 1)) + 1; | return (~bnTarget / (bnTarget + 1)) + 1; | ||||
} | } | ||||
int64_t GetBlockProofEquivalentTime(const CBlockIndex &to, | int64_t GetBlockProofEquivalentTime(const CBlockIndex &to, | ||||
const CBlockIndex &from, | const CBlockIndex &from, | ||||
const CBlockIndex &tip, | const CBlockIndex &tip, | ||||
const Consensus::Params ¶ms) { | const Consensus::Params ¶ms) { | ||||
arith_uint256 r; | arith_uint256 r; | ||||
▲ Show 20 Lines • Show All 42 Lines • Show Last 20 Lines |