mirror of
https://github.com/bitcoinbook/bitcoinbook
synced 2025-06-07 08:38:49 +00:00
Correction for errata 152557
This commit is contained in:
parent
419d2c0868
commit
0d050d01ab
@ -642,35 +642,30 @@ New Difficulty = Old Difficulty * (Actual Time of Last 2016 Blocks / 20160 minut
|
|||||||
<<retarget_difficulty_code>> shows the code used in the Bitcoin Core client.
|
<<retarget_difficulty_code>> shows the code used in the Bitcoin Core client.
|
||||||
|
|
||||||
[[retarget_difficulty_code]]
|
[[retarget_difficulty_code]]
|
||||||
.Retargeting the proof-of-work difficulty—GetNextWorkRequired() in pow.cpp, line 43
|
.Retargeting the proof-of-work difficulty — CalculateNextWorkRequired() in pow.cpp
|
||||||
====
|
====
|
||||||
[source,cpp]
|
[source,cpp]
|
||||||
----
|
----
|
||||||
|
|
||||||
// Go back by what we want to be 14 days worth of blocks
|
// Limit adjustment step
|
||||||
const CBlockIndex* pindexFirst = pindexLast;
|
int64_t nActualTimespan = pindexLast->GetBlockTime() - nFirstBlockTime;
|
||||||
for (int i = 0; pindexFirst && i < Params().Interval()-1; i++)
|
LogPrintf(" nActualTimespan = %d before bounds\n", nActualTimespan);
|
||||||
pindexFirst = pindexFirst->pprev;
|
if (nActualTimespan < params.nPowTargetTimespan/4)
|
||||||
assert(pindexFirst);
|
nActualTimespan = params.nPowTargetTimespan/4;
|
||||||
|
if (nActualTimespan > params.nPowTargetTimespan*4)
|
||||||
|
nActualTimespan = params.nPowTargetTimespan*4;
|
||||||
|
|
||||||
// Limit adjustment step
|
// Retarget
|
||||||
int64_t nActualTimespan = pindexLast->GetBlockTime() - pindexFirst->GetBlockTime();
|
const arith_uint256 bnPowLimit = UintToArith256(params.powLimit);
|
||||||
LogPrintf(" nActualTimespan = %d before bounds\n", nActualTimespan);
|
arith_uint256 bnNew;
|
||||||
if (nActualTimespan < Params().TargetTimespan()/4)
|
arith_uint256 bnOld;
|
||||||
nActualTimespan = Params().TargetTimespan()/4;
|
bnNew.SetCompact(pindexLast->nBits);
|
||||||
if (nActualTimespan > Params().TargetTimespan()*4)
|
bnOld = bnNew;
|
||||||
nActualTimespan = Params().TargetTimespan()*4;
|
bnNew *= nActualTimespan;
|
||||||
|
bnNew /= params.nPowTargetTimespan;
|
||||||
|
|
||||||
// Retarget
|
if (bnNew > bnPowLimit)
|
||||||
uint256 bnNew;
|
bnNew = bnPowLimit;
|
||||||
uint256 bnOld;
|
|
||||||
bnNew.SetCompact(pindexLast->nBits);
|
|
||||||
bnOld = bnNew;
|
|
||||||
bnNew *= nActualTimespan;
|
|
||||||
bnNew /= Params().TargetTimespan();
|
|
||||||
|
|
||||||
if (bnNew > Params().ProofOfWorkLimit())
|
|
||||||
bnNew = Params().ProofOfWorkLimit();
|
|
||||||
|
|
||||||
----
|
----
|
||||||
====
|
====
|
||||||
|
Loading…
Reference in New Issue
Block a user