From 39792671807d2188552118f9e265ee3d2fec3a93 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Thu, 9 Apr 2015 11:50:18 +0000 Subject: [PATCH] Bugfix: Allow mining on top of old tip blocks for testnet (fixes testnet-in-a-box use case) --- src/chainparams.cpp | 3 +++ src/chainparams.h | 2 ++ src/main.cpp | 3 ++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index eb0c5af545..dc4c954958 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -125,6 +125,7 @@ public: nMinerThreads = 0; nTargetTimespan = 3.5 * 24 * 60 * 60; // 3.5 days nTargetSpacing = 2.5 * 60; // 2.5 minutes + nMaxTipAge = 24 * 60 * 60; /** * Build the genesis block. Note that the output of the genesis coinbase cannot @@ -209,6 +210,7 @@ public: nMinerThreads = 0; nTargetTimespan = 3.5 * 24 * 60 * 60; // 3.5 days nTargetSpacing = 2.5 * 60; // 2.5 minutes + nMaxTipAge = 0x7fffffff; //! Modify the testnet genesis block so the timestamp is valid for a later start. genesis.nTime = 1317798646; @@ -268,6 +270,7 @@ public: nTargetTimespan = 3.5 * 24 * 60 * 60; // 3.5 days nTargetSpacing = 2.5 * 60; // 2.5 minutes bnProofOfWorkLimit = ~uint256(0) >> 1; + nMaxTipAge = 24 * 60 * 60; genesis.nTime = 1296688602; genesis.nBits = 0x207fffff; genesis.nNonce = 0; diff --git a/src/chainparams.h b/src/chainparams.h index 75261cd684..b0f58f686f 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -69,6 +69,7 @@ public: 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 */ @@ -98,6 +99,7 @@ protected: int64_t nTargetTimespan; int64_t nTargetSpacing; int nMinerThreads; + long nMaxTipAge; std::vector vSeeds; std::vector base58Prefixes[MAX_BASE58_TYPES]; CBaseChainParams::Network networkID; diff --git a/src/main.cpp b/src/main.cpp index 601001cd1e..4037fa482e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1257,6 +1257,7 @@ 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; @@ -1264,7 +1265,7 @@ bool IsInitialBlockDownload() 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;