Skip to content

Commit

Permalink
Bugfix: Allow mining on top of old tip blocks for testnet (fixes test…
Browse files Browse the repository at this point in the history
…net-in-a-box use case)
  • Loading branch information
luke-jr committed Nov 6, 2015
1 parent b3964e3 commit cf67d8b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class CMainParams : public CChainParams {
nMinerThreads = 0;
nTargetTimespan = 14 * 24 * 60 * 60; // two weeks
nTargetSpacing = 10 * 60;
nMaxTipAge = 24 * 60 * 60;

/**
* Build the genesis block. Note that the output of the genesis coinbase cannot
Expand Down Expand Up @@ -203,6 +204,7 @@ class CTestNetParams : public CMainParams {
nMinerThreads = 0;
nTargetTimespan = 14 * 24 * 60 * 60; //! two weeks
nTargetSpacing = 10 * 60;
nMaxTipAge = 0x7fffffff;

//! Modify the testnet genesis block so the timestamp is valid for a later start.
genesis.nTime = 1296688602;
Expand Down Expand Up @@ -260,6 +262,7 @@ class CRegTestParams : public CTestNetParams {
nTargetTimespan = 14 * 24 * 60 * 60; //! two weeks
nTargetSpacing = 10 * 60;
bnProofOfWorkLimit = ~uint256(0) >> 1;
nMaxTipAge = 24 * 60 * 60;
genesis.nTime = 1296688602;
genesis.nBits = 0x207fffff;
genesis.nNonce = 2;
Expand Down
2 changes: 2 additions & 0 deletions src/chainparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class CChainParams
int64_t TargetTimespan() const { return nTargetTimespan; }
int64_t TargetSpacing() const { return nTargetSpacing; }
int64_t Interval() const { return nTargetTimespan / nTargetSpacing; }
int64_t MaxTipAge() const { return nMaxTipAge; }
/** Make miner stop after a block is found. In RPC, don't return until nGenProcLimit blocks are generated */
bool MineBlocksOnDemand() const { return fMineBlocksOnDemand; }
/** In the future use NetworkIDString() for RPC fields */
Expand All @@ -95,6 +96,7 @@ class CChainParams
int64_t nTargetTimespan;
int64_t nTargetSpacing;
int nMinerThreads;
long nMaxTipAge;
std::vector<CDNSSeedData> vSeeds;
std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];
CBaseChainParams::Network networkID;
Expand Down
3 changes: 2 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1248,14 +1248,15 @@ CAmount GetBlockValue(int nHeight, const CAmount& nFees)

bool IsInitialBlockDownload()
{
const CChainParams& chainParams = Params();
LOCK(cs_main);
if (fImporting || fReindex || chainActive.Height() < Checkpoints::GetTotalBlocksEstimate())
return true;
static bool lockIBDState = false;
if (lockIBDState)
return false;
bool state = (chainActive.Height() < pindexBestHeader->nHeight - 24 * 6 ||
pindexBestHeader->GetBlockTime() < GetTime() - 24 * 60 * 60);
pindexBestHeader->GetBlockTime() < GetTime() - chainParams.MaxTipAge());
if (!state)
lockIBDState = true;
return state;
Expand Down

0 comments on commit cf67d8b

Please sign in to comment.