move pow constants to chainparams
This commit is contained in:
parent
df852d2bcc
commit
fd704c7b2c
@ -117,6 +117,8 @@ public:
|
|||||||
nRejectBlockOutdatedMajority = 950;
|
nRejectBlockOutdatedMajority = 950;
|
||||||
nToCheckBlockUpgradeMajority = 1000;
|
nToCheckBlockUpgradeMajority = 1000;
|
||||||
nMinerThreads = 0;
|
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
|
// Build the genesis block. Note that the output of the genesis coinbase cannot
|
||||||
// be spent as it did not originally exist in the database.
|
// be spent as it did not originally exist in the database.
|
||||||
@ -204,6 +206,9 @@ public:
|
|||||||
nEnforceBlockUpgradeMajority = 51;
|
nEnforceBlockUpgradeMajority = 51;
|
||||||
nRejectBlockOutdatedMajority = 75;
|
nRejectBlockOutdatedMajority = 75;
|
||||||
nToCheckBlockUpgradeMajority = 100;
|
nToCheckBlockUpgradeMajority = 100;
|
||||||
|
nMinerThreads = 0;
|
||||||
|
nTargetTimespan = 14 * 24 * 60 * 60; // two weeks
|
||||||
|
nTargetSpacing = 10 * 60;
|
||||||
strDataDir = "testnet3";
|
strDataDir = "testnet3";
|
||||||
|
|
||||||
// Modify the testnet genesis block so the timestamp is valid for a later start.
|
// Modify the testnet genesis block so the timestamp is valid for a later start.
|
||||||
@ -251,6 +256,8 @@ public:
|
|||||||
nRejectBlockOutdatedMajority = 950;
|
nRejectBlockOutdatedMajority = 950;
|
||||||
nToCheckBlockUpgradeMajority = 1000;
|
nToCheckBlockUpgradeMajority = 1000;
|
||||||
nMinerThreads = 1;
|
nMinerThreads = 1;
|
||||||
|
nTargetTimespan = 14 * 24 * 60 * 60; // two weeks
|
||||||
|
nTargetSpacing = 10 * 60;
|
||||||
bnProofOfWorkLimit = ~uint256(0) >> 1;
|
bnProofOfWorkLimit = ~uint256(0) >> 1;
|
||||||
genesis.nTime = 1296688602;
|
genesis.nTime = 1296688602;
|
||||||
genesis.nBits = 0x207fffff;
|
genesis.nBits = 0x207fffff;
|
||||||
|
@ -70,6 +70,9 @@ public:
|
|||||||
bool AllowMinDifficultyBlocks() const { return fAllowMinDifficultyBlocks; }
|
bool AllowMinDifficultyBlocks() const { return fAllowMinDifficultyBlocks; }
|
||||||
/* Make standard checks */
|
/* Make standard checks */
|
||||||
bool RequireStandard() const { return fRequireStandard; }
|
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; }
|
const std::string& DataDir() const { return strDataDir; }
|
||||||
/* Make miner stop after a block is found. In RPC, don't return
|
/* Make miner stop after a block is found. In RPC, don't return
|
||||||
* until nGenProcLimit blocks are generated */
|
* until nGenProcLimit blocks are generated */
|
||||||
@ -95,6 +98,8 @@ protected:
|
|||||||
int nEnforceBlockUpgradeMajority;
|
int nEnforceBlockUpgradeMajority;
|
||||||
int nRejectBlockOutdatedMajority;
|
int nRejectBlockOutdatedMajority;
|
||||||
int nToCheckBlockUpgradeMajority;
|
int nToCheckBlockUpgradeMajority;
|
||||||
|
int64_t nTargetTimespan;
|
||||||
|
int64_t nTargetSpacing;
|
||||||
std::string strDataDir;
|
std::string strDataDir;
|
||||||
int nMinerThreads;
|
int nMinerThreads;
|
||||||
std::vector<CDNSSeedData> vSeeds;
|
std::vector<CDNSSeedData> vSeeds;
|
||||||
|
30
src/pow.cpp
30
src/pow.cpp
@ -10,10 +10,6 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "uint256.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 GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock)
|
||||||
{
|
{
|
||||||
unsigned int nProofOfWorkLimit = Params().ProofOfWorkLimit().GetCompact();
|
unsigned int nProofOfWorkLimit = Params().ProofOfWorkLimit().GetCompact();
|
||||||
@ -23,20 +19,20 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
|
|||||||
return nProofOfWorkLimit;
|
return nProofOfWorkLimit;
|
||||||
|
|
||||||
// Only change once per interval
|
// Only change once per interval
|
||||||
if ((pindexLast->nHeight+1) % nInterval != 0)
|
if ((pindexLast->nHeight+1) % Params().Interval() != 0)
|
||||||
{
|
{
|
||||||
if (Params().AllowMinDifficultyBlocks())
|
if (Params().AllowMinDifficultyBlocks())
|
||||||
{
|
{
|
||||||
// Special difficulty rule for testnet:
|
// Special difficulty rule for testnet:
|
||||||
// If the new block's timestamp is more than 2* 10 minutes
|
// If the new block's timestamp is more than 2* 10 minutes
|
||||||
// then allow mining of a min-difficulty block.
|
// 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;
|
return nProofOfWorkLimit;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Return the last non-special-min-difficulty-rules-block
|
// Return the last non-special-min-difficulty-rules-block
|
||||||
const CBlockIndex* pindex = pindexLast;
|
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;
|
pindex = pindex->pprev;
|
||||||
return pindex->nBits;
|
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
|
// Go back by what we want to be 14 days worth of blocks
|
||||||
const CBlockIndex* pindexFirst = pindexLast;
|
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;
|
pindexFirst = pindexFirst->pprev;
|
||||||
assert(pindexFirst);
|
assert(pindexFirst);
|
||||||
|
|
||||||
// Limit adjustment step
|
// Limit adjustment step
|
||||||
int64_t nActualTimespan = pindexLast->GetBlockTime() - pindexFirst->GetBlockTime();
|
int64_t nActualTimespan = pindexLast->GetBlockTime() - pindexFirst->GetBlockTime();
|
||||||
LogPrintf(" nActualTimespan = %d before bounds\n", nActualTimespan);
|
LogPrintf(" nActualTimespan = %d before bounds\n", nActualTimespan);
|
||||||
if (nActualTimespan < nTargetTimespan/4)
|
if (nActualTimespan < Params().TargetTimespan()/4)
|
||||||
nActualTimespan = nTargetTimespan/4;
|
nActualTimespan = Params().TargetTimespan()/4;
|
||||||
if (nActualTimespan > nTargetTimespan*4)
|
if (nActualTimespan > Params().TargetTimespan()*4)
|
||||||
nActualTimespan = nTargetTimespan*4;
|
nActualTimespan = Params().TargetTimespan()*4;
|
||||||
|
|
||||||
// Retarget
|
// Retarget
|
||||||
uint256 bnNew;
|
uint256 bnNew;
|
||||||
@ -64,14 +60,14 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
|
|||||||
bnNew.SetCompact(pindexLast->nBits);
|
bnNew.SetCompact(pindexLast->nBits);
|
||||||
bnOld = bnNew;
|
bnOld = bnNew;
|
||||||
bnNew *= nActualTimespan;
|
bnNew *= nActualTimespan;
|
||||||
bnNew /= nTargetTimespan;
|
bnNew /= Params().TargetTimespan();
|
||||||
|
|
||||||
if (bnNew > Params().ProofOfWorkLimit())
|
if (bnNew > Params().ProofOfWorkLimit())
|
||||||
bnNew = Params().ProofOfWorkLimit();
|
bnNew = Params().ProofOfWorkLimit();
|
||||||
|
|
||||||
/// debug print
|
/// debug print
|
||||||
LogPrintf("GetNextWorkRequired RETARGET\n");
|
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("Before: %08x %s\n", pindexLast->nBits, bnOld.ToString());
|
||||||
LogPrintf("After: %08x %s\n", bnNew.GetCompact(), bnNew.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();
|
const uint256 &bnLimit = Params().ProofOfWorkLimit();
|
||||||
// Testnet has min-difficulty blocks
|
// Testnet has min-difficulty blocks
|
||||||
// after nTargetSpacing*2 time between blocks:
|
// after Params().TargetSpacing()*2 time between blocks:
|
||||||
if (Params().AllowMinDifficultyBlocks() && nTime > nTargetSpacing*2)
|
if (Params().AllowMinDifficultyBlocks() && nTime > Params().TargetSpacing()*2)
|
||||||
return bnLimit.GetCompact();
|
return bnLimit.GetCompact();
|
||||||
|
|
||||||
uint256 bnResult;
|
uint256 bnResult;
|
||||||
@ -115,7 +111,7 @@ unsigned int ComputeMinWork(unsigned int nBase, int64_t nTime)
|
|||||||
// Maximum 400% adjustment...
|
// Maximum 400% adjustment...
|
||||||
bnResult *= 4;
|
bnResult *= 4;
|
||||||
// ... in best-case exactly 4-times-normal target time
|
// ... in best-case exactly 4-times-normal target time
|
||||||
nTime -= nTargetTimespan*4;
|
nTime -= Params().TargetTimespan()*4;
|
||||||
}
|
}
|
||||||
if (bnResult > bnLimit)
|
if (bnResult > bnLimit)
|
||||||
bnResult = bnLimit;
|
bnResult = bnLimit;
|
||||||
|
Loading…
Reference in New Issue
Block a user