From 4d16bfd1811e92051326ae385b35c1176cd3d96b Mon Sep 17 00:00:00 2001 From: Daira Hopwood Date: Thu, 12 Nov 2020 10:52:49 +0000 Subject: [PATCH] GetNextWorkRequired: clarify why this computation is equivalent to that in the protocol spec. refs https://github.com/zcash/zips/pull/418 Signed-off-by: Daira Hopwood --- src/pow.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/pow.cpp b/src/pow.cpp index e8ebcd304..fe9658570 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -51,6 +51,12 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if (pindexFirst == NULL) return nProofOfWorkLimit; + // The protocol specification leaves MeanTarget(height) as a rational, and takes the floor + // only after dividing by AveragingWindowTimespan in the computation of Threshold(height): + // + // + // Here we take the floor of MeanTarget(height) immediately, but that is equivalent to doing + // so only after a further division, as proven in . arith_uint256 bnAvg {bnTot / params.nPowAveragingWindow}; return CalculateNextWorkRequired(bnAvg,