aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjtimon <jtimon@monetize.io>2014-03-22 18:29:34 +0100
committerjtimon <jtimon@monetize.io>2014-06-23 23:10:24 +0200
commitfd704c7b2c5ab8b24b1829f000b829d7156b8b3c (patch)
treed5da5ec14cdcdd195464e4482e08dadce7cf91df /src
parentdf852d2bcc6573a3fcb3e59f82f7ea4dfa11290e (diff)
move pow constants to chainparams
Diffstat (limited to 'src')
-rw-r--r--src/chainparams.cpp7
-rw-r--r--src/chainparams.h5
-rw-r--r--src/pow.cpp30
3 files changed, 25 insertions, 17 deletions
diff --git a/src/chainparams.cpp b/src/chainparams.cpp
index afbae6fc57..eb56af750e 100644
--- a/src/chainparams.cpp
+++ b/src/chainparams.cpp
@@ -117,6 +117,8 @@ public:
nRejectBlockOutdatedMajority = 950;
nToCheckBlockUpgradeMajority = 1000;
nMinerThreads = 0;
+ nTargetTimespan = 14 * 24 * 60 * 60; // two weeks
+ nTargetSpacing = 10 * 60;
// Build the genesis block. Note that the output of the genesis coinbase cannot
// be spent as it did not originally exist in the database.
@@ -204,6 +206,9 @@ public:
nEnforceBlockUpgradeMajority = 51;
nRejectBlockOutdatedMajority = 75;
nToCheckBlockUpgradeMajority = 100;
+ nMinerThreads = 0;
+ nTargetTimespan = 14 * 24 * 60 * 60; // two weeks
+ nTargetSpacing = 10 * 60;
strDataDir = "testnet3";
// Modify the testnet genesis block so the timestamp is valid for a later start.
@@ -251,6 +256,8 @@ public:
nRejectBlockOutdatedMajority = 950;
nToCheckBlockUpgradeMajority = 1000;
nMinerThreads = 1;
+ nTargetTimespan = 14 * 24 * 60 * 60; // two weeks
+ nTargetSpacing = 10 * 60;
bnProofOfWorkLimit = ~uint256(0) >> 1;
genesis.nTime = 1296688602;
genesis.nBits = 0x207fffff;
diff --git a/src/chainparams.h b/src/chainparams.h
index c0a6ebda6b..e9774bbfa2 100644
--- a/src/chainparams.h
+++ b/src/chainparams.h
@@ -70,6 +70,9 @@ public:
bool AllowMinDifficultyBlocks() const { return fAllowMinDifficultyBlocks; }
/* Make standard checks */
bool RequireStandard() const { return fRequireStandard; }
+ int64_t TargetTimespan() const { return nTargetTimespan; }
+ int64_t TargetSpacing() const { return nTargetSpacing; }
+ int64_t Interval() const { return nTargetTimespan / nTargetSpacing; }
const std::string& DataDir() const { return strDataDir; }
/* Make miner stop after a block is found. In RPC, don't return
* until nGenProcLimit blocks are generated */
@@ -95,6 +98,8 @@ protected:
int nEnforceBlockUpgradeMajority;
int nRejectBlockOutdatedMajority;
int nToCheckBlockUpgradeMajority;
+ int64_t nTargetTimespan;
+ int64_t nTargetSpacing;
std::string strDataDir;
int nMinerThreads;
std::vector<CDNSSeedData> vSeeds;
diff --git a/src/pow.cpp b/src/pow.cpp
index 274a5d6f98..952250decd 100644
--- a/src/pow.cpp
+++ b/src/pow.cpp
@@ -10,10 +10,6 @@
#include "main.h"
#include "uint256.h"
-static const int64_t nTargetTimespan = 14 * 24 * 60 * 60; // two weeks
-static const int64_t nTargetSpacing = 10 * 60;
-static const int64_t nInterval = nTargetTimespan / nTargetSpacing;
-
unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock)
{
unsigned int nProofOfWorkLimit = Params().ProofOfWorkLimit().GetCompact();
@@ -23,20 +19,20 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
return nProofOfWorkLimit;
// Only change once per interval
- if ((pindexLast->nHeight+1) % nInterval != 0)
+ if ((pindexLast->nHeight+1) % Params().Interval() != 0)
{
if (Params().AllowMinDifficultyBlocks())
{
// Special difficulty rule for testnet:
// If the new block's timestamp is more than 2* 10 minutes
// then allow mining of a min-difficulty block.
- if (pblock->nTime > pindexLast->nTime + nTargetSpacing*2)
+ if (pblock->nTime > pindexLast->nTime + Params().TargetSpacing()*2)
return nProofOfWorkLimit;
else
{
// Return the last non-special-min-difficulty-rules-block
const CBlockIndex* pindex = pindexLast;
- while (pindex->pprev && pindex->nHeight % nInterval != 0 && pindex->nBits == nProofOfWorkLimit)
+ while (pindex->pprev && pindex->nHeight % Params().Interval() != 0 && pindex->nBits == nProofOfWorkLimit)
pindex = pindex->pprev;
return pindex->nBits;
}
@@ -46,17 +42,17 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
// Go back by what we want to be 14 days worth of blocks
const CBlockIndex* pindexFirst = pindexLast;
- for (int i = 0; pindexFirst && i < nInterval-1; i++)
+ for (int i = 0; pindexFirst && i < Params().Interval()-1; i++)
pindexFirst = pindexFirst->pprev;
assert(pindexFirst);
// Limit adjustment step
int64_t nActualTimespan = pindexLast->GetBlockTime() - pindexFirst->GetBlockTime();
LogPrintf(" nActualTimespan = %d before bounds\n", nActualTimespan);
- if (nActualTimespan < nTargetTimespan/4)
- nActualTimespan = nTargetTimespan/4;
- if (nActualTimespan > nTargetTimespan*4)
- nActualTimespan = nTargetTimespan*4;
+ if (nActualTimespan < Params().TargetTimespan()/4)
+ nActualTimespan = Params().TargetTimespan()/4;
+ if (nActualTimespan > Params().TargetTimespan()*4)
+ nActualTimespan = Params().TargetTimespan()*4;
// Retarget
uint256 bnNew;
@@ -64,14 +60,14 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
bnNew.SetCompact(pindexLast->nBits);
bnOld = bnNew;
bnNew *= nActualTimespan;
- bnNew /= nTargetTimespan;
+ bnNew /= Params().TargetTimespan();
if (bnNew > Params().ProofOfWorkLimit())
bnNew = Params().ProofOfWorkLimit();
/// debug print
LogPrintf("GetNextWorkRequired RETARGET\n");
- LogPrintf("nTargetTimespan = %d nActualTimespan = %d\n", nTargetTimespan, nActualTimespan);
+ LogPrintf("Params().TargetTimespan() = %d nActualTimespan = %d\n", Params().TargetTimespan(), nActualTimespan);
LogPrintf("Before: %08x %s\n", pindexLast->nBits, bnOld.ToString());
LogPrintf("After: %08x %s\n", bnNew.GetCompact(), bnNew.ToString());
@@ -104,8 +100,8 @@ unsigned int ComputeMinWork(unsigned int nBase, int64_t nTime)
{
const uint256 &bnLimit = Params().ProofOfWorkLimit();
// Testnet has min-difficulty blocks
- // after nTargetSpacing*2 time between blocks:
- if (Params().AllowMinDifficultyBlocks() && nTime > nTargetSpacing*2)
+ // after Params().TargetSpacing()*2 time between blocks:
+ if (Params().AllowMinDifficultyBlocks() && nTime > Params().TargetSpacing()*2)
return bnLimit.GetCompact();
uint256 bnResult;
@@ -115,7 +111,7 @@ unsigned int ComputeMinWork(unsigned int nBase, int64_t nTime)
// Maximum 400% adjustment...
bnResult *= 4;
// ... in best-case exactly 4-times-normal target time
- nTime -= nTargetTimespan*4;
+ nTime -= Params().TargetTimespan()*4;
}
if (bnResult > bnLimit)
bnResult = bnLimit;