Skip to content

Commit 21913a9

Browse files
committed
Add AllowMinDifficultyBlocks chain parameter
1 parent d754f34 commit 21913a9

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

src/chainparams.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ class CTestNetParams : public CMainParams {
224224
base58Prefixes[EXT_PUBLIC_KEY] = list_of(0x04)(0x35)(0x87)(0xCF);
225225
base58Prefixes[EXT_SECRET_KEY] = list_of(0x04)(0x35)(0x83)(0x94);
226226
}
227+
228+
virtual bool AllowMinDifficultyBlocks() const { return true; }
227229
virtual Network NetworkID() const { return CChainParams::TESTNET; }
228230
};
229231
static CTestNetParams testNetParams;

src/chainparams.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ class CChainParams
7070
virtual bool MiningRequiresPeers() const { return true; }
7171
/* Default value for -checkmempool argument */
7272
virtual bool DefaultCheckMemPool() const { return false; }
73+
/* Allow mining of a min-difficulty block */
74+
virtual bool AllowMinDifficultyBlocks() const { return false; }
7375
const string& DataDir() const { return strDataDir; }
7476
/* Make miner stop after a block is found. In RPC, don't return
7577
* until nGenProcLimit blocks are generated */

src/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,7 @@ unsigned int ComputeMinWork(unsigned int nBase, int64_t nTime)
12101210
const uint256 &bnLimit = Params().ProofOfWorkLimit();
12111211
// Testnet has min-difficulty blocks
12121212
// after nTargetSpacing*2 time between blocks:
1213-
if (TestNet() && nTime > nTargetSpacing*2)
1213+
if (Params().AllowMinDifficultyBlocks() && nTime > nTargetSpacing*2)
12141214
return bnLimit.GetCompact();
12151215

12161216
uint256 bnResult;
@@ -1238,7 +1238,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
12381238
// Only change once per interval
12391239
if ((pindexLast->nHeight+1) % nInterval != 0)
12401240
{
1241-
if (TestNet())
1241+
if (Params().AllowMinDifficultyBlocks())
12421242
{
12431243
// Special difficulty rule for testnet:
12441244
// If the new block's timestamp is more than 2* 10 minutes
@@ -1468,7 +1468,7 @@ void UpdateTime(CBlockHeader& block, const CBlockIndex* pindexPrev)
14681468
block.nTime = max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
14691469

14701470
// Updating time can change work required on testnet:
1471-
if (TestNet())
1471+
if (Params().AllowMinDifficultyBlocks())
14721472
block.nBits = GetNextWorkRequired(pindexPrev, &block);
14731473
}
14741474

src/miner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ void static BitcoinMiner(CWallet *pwallet)
632632
// Update nTime every few seconds
633633
UpdateTime(*pblock, pindexPrev);
634634
nBlockTime = ByteReverse(pblock->nTime);
635-
if (TestNet())
635+
if (Params().AllowMinDifficultyBlocks())
636636
{
637637
// Changing pblock->nTime can change work required on testnet:
638638
nBlockBits = ByteReverse(pblock->nBits);

0 commit comments

Comments
 (0)