10
10
#include " main.h"
11
11
#include " uint256.h"
12
12
13
- static const int64_t nTargetTimespan = 14 * 24 * 60 * 60 ; // two weeks
14
- static const int64_t nTargetSpacing = 10 * 60 ;
15
- static const int64_t nInterval = nTargetTimespan / nTargetSpacing;
16
-
17
13
unsigned int GetNextWorkRequired (const CBlockIndex* pindexLast, const CBlockHeader *pblock)
18
14
{
19
15
unsigned int nProofOfWorkLimit = Params ().ProofOfWorkLimit ().GetCompact ();
@@ -23,20 +19,20 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
23
19
return nProofOfWorkLimit;
24
20
25
21
// Only change once per interval
26
- if ((pindexLast->nHeight +1 ) % nInterval != 0 )
22
+ if ((pindexLast->nHeight +1 ) % Params (). Interval () != 0 )
27
23
{
28
24
if (Params ().AllowMinDifficultyBlocks ())
29
25
{
30
26
// Special difficulty rule for testnet:
31
27
// If the new block's timestamp is more than 2* 10 minutes
32
28
// then allow mining of a min-difficulty block.
33
- if (pblock->nTime > pindexLast->nTime + nTargetSpacing *2 )
29
+ if (pblock->nTime > pindexLast->nTime + Params (). TargetSpacing () *2 )
34
30
return nProofOfWorkLimit;
35
31
else
36
32
{
37
33
// Return the last non-special-min-difficulty-rules-block
38
34
const CBlockIndex* pindex = pindexLast;
39
- while (pindex->pprev && pindex->nHeight % nInterval != 0 && pindex->nBits == nProofOfWorkLimit)
35
+ while (pindex->pprev && pindex->nHeight % Params (). Interval () != 0 && pindex->nBits == nProofOfWorkLimit)
40
36
pindex = pindex->pprev ;
41
37
return pindex->nBits ;
42
38
}
@@ -46,32 +42,32 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
46
42
47
43
// Go back by what we want to be 14 days worth of blocks
48
44
const CBlockIndex* pindexFirst = pindexLast;
49
- for (int i = 0 ; pindexFirst && i < nInterval -1 ; i++)
45
+ for (int i = 0 ; pindexFirst && i < Params (). Interval () -1 ; i++)
50
46
pindexFirst = pindexFirst->pprev ;
51
47
assert (pindexFirst);
52
48
53
49
// Limit adjustment step
54
50
int64_t nActualTimespan = pindexLast->GetBlockTime () - pindexFirst->GetBlockTime ();
55
51
LogPrintf (" nActualTimespan = %d before bounds\n " , nActualTimespan);
56
- if (nActualTimespan < nTargetTimespan /4 )
57
- nActualTimespan = nTargetTimespan /4 ;
58
- if (nActualTimespan > nTargetTimespan *4 )
59
- nActualTimespan = nTargetTimespan *4 ;
52
+ if (nActualTimespan < Params (). TargetTimespan () /4 )
53
+ nActualTimespan = Params (). TargetTimespan () /4 ;
54
+ if (nActualTimespan > Params (). TargetTimespan () *4 )
55
+ nActualTimespan = Params (). TargetTimespan () *4 ;
60
56
61
57
// Retarget
62
58
uint256 bnNew;
63
59
uint256 bnOld;
64
60
bnNew.SetCompact (pindexLast->nBits );
65
61
bnOld = bnNew;
66
62
bnNew *= nActualTimespan;
67
- bnNew /= nTargetTimespan ;
63
+ bnNew /= Params (). TargetTimespan () ;
68
64
69
65
if (bnNew > Params ().ProofOfWorkLimit ())
70
66
bnNew = Params ().ProofOfWorkLimit ();
71
67
72
68
// / debug print
73
69
LogPrintf (" GetNextWorkRequired RETARGET\n " );
74
- LogPrintf (" nTargetTimespan = %d nActualTimespan = %d\n " , nTargetTimespan , nActualTimespan);
70
+ LogPrintf (" Params().TargetTimespan() = %d nActualTimespan = %d\n " , Params (). TargetTimespan () , nActualTimespan);
75
71
LogPrintf (" Before: %08x %s\n " , pindexLast->nBits , bnOld.ToString ());
76
72
LogPrintf (" After: %08x %s\n " , bnNew.GetCompact (), bnNew.ToString ());
77
73
@@ -104,8 +100,8 @@ unsigned int ComputeMinWork(unsigned int nBase, int64_t nTime)
104
100
{
105
101
const uint256 &bnLimit = Params ().ProofOfWorkLimit ();
106
102
// Testnet has min-difficulty blocks
107
- // after nTargetSpacing *2 time between blocks:
108
- if (Params ().AllowMinDifficultyBlocks () && nTime > nTargetSpacing *2 )
103
+ // after Params().TargetSpacing() *2 time between blocks:
104
+ if (Params ().AllowMinDifficultyBlocks () && nTime > Params (). TargetSpacing () *2 )
109
105
return bnLimit.GetCompact ();
110
106
111
107
uint256 bnResult;
@@ -115,7 +111,7 @@ unsigned int ComputeMinWork(unsigned int nBase, int64_t nTime)
115
111
// Maximum 400% adjustment...
116
112
bnResult *= 4 ;
117
113
// ... in best-case exactly 4-times-normal target time
118
- nTime -= nTargetTimespan *4 ;
114
+ nTime -= Params (). TargetTimespan () *4 ;
119
115
}
120
116
if (bnResult > bnLimit)
121
117
bnResult = bnLimit;
0 commit comments