1
The implementation of GetBlockWork() in the bitcoin v0.9.3 source (https://github.com/bitcoin/bitcoin/blob/v0.9.3/src/main.h#L815-L822) seems strange to me. The code is given below for convenience.
CBigNum GetBlockWork() const
{
CBigNum bnTarget;
bnTarget.SetCompact(nBits);
if (bnTarget <= 0)
return 0;
return (CBigNum(1)<<256) / (bnTarget+1);
}
- Why the +1 in the denominator?
- And shouldn't the numerator be the maximum possible 256 bit integer, instead of 2^256?
I would expect the implementation to be:
CBigNum GetBlockWork() const
{
CBigNum bnTarget;
bnTarget.SetCompact(nBits);
if (bnTarget <= 0)
return 0;
CBigNum bnMax;
bnMax.SetHex("0xFFFFFFFFFFFFFFFF"); // Max 256 bit int
return (bnMax / bnTarget);
}
1So basically, the +1 in the denominator is because there are
target+1values that are less than or equal to the target, which makes sense. And the numerator is `1+maxtarget', because there are 1+maxtarget values that are less than or equal to the max target. This clears it up, thanks! – morsecoder – 2014-12-19T00:09:13.537Hi, so eventually, based on recent litecoin source, how to code for actually mine the genesis block? For example, this is based on version 0.8 litecoin source. https://pastebin.com/du2XdxCC From this, how should be changed? Thanks.
– creator – 2018-02-24T10:19:25.363