77
88#include " arith_uint256.h"
99#include " chain.h"
10- #include " chainparams.h"
1110#include " primitives/block.h"
1211#include " uint256.h"
1312#include " util.h"
1413
15- unsigned int GetNextWorkRequired (const CBlockIndex* pindexLast, const CBlockHeader *pblock)
14+ unsigned int GetNextWorkRequired (const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params )
1615{
17- unsigned int nProofOfWorkLimit = Params (). ProofOfWorkLimit () .GetCompact ();
16+ unsigned int nProofOfWorkLimit = params. powLimit .GetCompact ();
1817
1918 // Genesis block
2019 if (pindexLast == NULL )
2120 return nProofOfWorkLimit;
2221
2322 // Only change once per difficulty adjustment interval
24- if ((pindexLast->nHeight +1 ) % Params () .DifficultyAdjustmentInterval () != 0 )
23+ if ((pindexLast->nHeight +1 ) % params .DifficultyAdjustmentInterval () != 0 )
2524 {
26- if (Params (). AllowMinDifficultyBlocks () )
25+ if (params. fPowAllowMinDifficultyBlocks )
2726 {
2827 // Special difficulty rule for testnet:
2928 // If the new block's timestamp is more than 2* 10 minutes
3029 // then allow mining of a min-difficulty block.
31- if (pblock->GetBlockTime () > pindexLast->GetBlockTime () + Params (). TargetSpacing () *2 )
30+ if (pblock->GetBlockTime () > pindexLast->GetBlockTime () + params. nPowTargetSpacing *2 )
3231 return nProofOfWorkLimit;
3332 else
3433 {
3534 // Return the last non-special-min-difficulty-rules-block
3635 const CBlockIndex* pindex = pindexLast;
37- while (pindex->pprev && pindex->nHeight % Params () .DifficultyAdjustmentInterval () != 0 && pindex->nBits == nProofOfWorkLimit)
36+ while (pindex->pprev && pindex->nHeight % params .DifficultyAdjustmentInterval () != 0 && pindex->nBits == nProofOfWorkLimit)
3837 pindex = pindex->pprev ;
3938 return pindex->nBits ;
4039 }
@@ -44,44 +43,44 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
4443
4544 // Go back by what we want to be 14 days worth of blocks
4645 const CBlockIndex* pindexFirst = pindexLast;
47- for (int i = 0 ; pindexFirst && i < Params () .DifficultyAdjustmentInterval ()-1 ; i++)
46+ for (int i = 0 ; pindexFirst && i < params .DifficultyAdjustmentInterval ()-1 ; i++)
4847 pindexFirst = pindexFirst->pprev ;
4948 assert (pindexFirst);
5049
51- return CalculateNextWorkRequired (pindexLast, pindexFirst->GetBlockTime ());
50+ return CalculateNextWorkRequired (pindexLast, pindexFirst->GetBlockTime (), params );
5251}
5352
54- unsigned int CalculateNextWorkRequired (const CBlockIndex* pindexLast, int64_t nFirstBlockTime)
53+ unsigned int CalculateNextWorkRequired (const CBlockIndex* pindexLast, int64_t nFirstBlockTime, const Consensus::Params& params )
5554{
5655 // Limit adjustment step
5756 int64_t nActualTimespan = pindexLast->GetBlockTime () - nFirstBlockTime;
5857 LogPrintf (" nActualTimespan = %d before bounds\n " , nActualTimespan);
59- if (nActualTimespan < Params (). TargetTimespan () /4 )
60- nActualTimespan = Params (). TargetTimespan () /4 ;
61- if (nActualTimespan > Params (). TargetTimespan () *4 )
62- nActualTimespan = Params (). TargetTimespan () *4 ;
58+ if (nActualTimespan < params. nPowTargetTimespan /4 )
59+ nActualTimespan = params. nPowTargetTimespan /4 ;
60+ if (nActualTimespan > params. nPowTargetTimespan *4 )
61+ nActualTimespan = params. nPowTargetTimespan *4 ;
6362
6463 // Retarget
6564 arith_uint256 bnNew;
6665 arith_uint256 bnOld;
6766 bnNew.SetCompact (pindexLast->nBits );
6867 bnOld = bnNew;
6968 bnNew *= nActualTimespan;
70- bnNew /= Params (). TargetTimespan () ;
69+ bnNew /= params. nPowTargetTimespan ;
7170
72- if (bnNew > Params (). ProofOfWorkLimit () )
73- bnNew = Params (). ProofOfWorkLimit () ;
71+ if (bnNew > params. powLimit )
72+ bnNew = params. powLimit ;
7473
7574 // / debug print
7675 LogPrintf (" GetNextWorkRequired RETARGET\n " );
77- LogPrintf (" Params().TargetTimespan() = %d nActualTimespan = %d\n " , Params (). TargetTimespan () , nActualTimespan);
76+ LogPrintf (" params.nPowTargetTimespan = %d nActualTimespan = %d\n " , params. nPowTargetTimespan , nActualTimespan);
7877 LogPrintf (" Before: %08x %s\n " , pindexLast->nBits , bnOld.ToString ());
7978 LogPrintf (" After: %08x %s\n " , bnNew.GetCompact (), bnNew.ToString ());
8079
8180 return bnNew.GetCompact ();
8281}
8382
84- bool CheckProofOfWork (uint256 hash, unsigned int nBits)
83+ bool CheckProofOfWork (uint256 hash, unsigned int nBits, const Consensus::Params& params )
8584{
8685 bool fNegative ;
8786 bool fOverflow ;
@@ -90,7 +89,7 @@ bool CheckProofOfWork(uint256 hash, unsigned int nBits)
9089 bnTarget.SetCompact (nBits, &fNegative , &fOverflow );
9190
9291 // Check range
93- if (fNegative || bnTarget == 0 || fOverflow || bnTarget > Params (). ProofOfWorkLimit () )
92+ if (fNegative || bnTarget == 0 || fOverflow || bnTarget > params. powLimit )
9493 return error (" CheckProofOfWork(): nBits below minimum work" );
9594
9695 // Check proof of work matches claimed amount
0 commit comments