]> Git Repo - VerusCoin.git/commitdiff
Remove testnet-only difficulty rules
authorJack Grigg <[email protected]>
Mon, 5 Sep 2016 11:06:20 +0000 (23:06 +1200)
committerJack Grigg <[email protected]>
Mon, 5 Sep 2016 11:13:25 +0000 (23:13 +1200)
The min-difficulty blocks are incompatible with difficulty averaging.

Network difficulty is also now defined as the difficulty the network is
currently working to solve, rather than the last non-min-difficulty block
difficulty.

src/gtest/test_rpc.cpp
src/pow.cpp
src/rpcblockchain.cpp

index c505bbbe4e9dd7436741d1f4248375b1d9f984d3..dc7a07e0dd64eee648e7e0d38b6111945840b790 100644 (file)
 #include "streams.h"
 #include "utilstrencodings.h"
 
-TEST(rpc, GetDifficultyTestnetRules) {
-    SelectParams(CBaseChainParams::TESTNET);
-
-    CBlockIndex prev;
-    prev.nTime = 1472700000;
-    prev.nBits = 0x201fffff;
-
-    CBlockIndex curr;
-    curr.pprev = &prev;
-    curr.nTime = 1472700300;
-    curr.nBits = 0x207fffff;
-
-    // Time interval is within 5 minutes, so the min-difficulty block should be
-    // interpreted as a valid network difficulty.
-    EXPECT_EQ(1, GetDifficulty(&curr));
-    EXPECT_EQ(1, GetNetworkDifficulty(&curr));
-
-    curr.nTime += 1;
-
-    // Time interval is over 5 minutes, so the min-difficulty block should be
-    // ignored for network difficulty determination.
-    EXPECT_EQ(1, GetDifficulty(&curr));
-    // We have to check this directly, because of some combination of rounding
-    // and truncation issues that result in Google Test displaying 4 != 4
-    EXPECT_EQ((double)0x7fffff/(double)0x1fffff, GetNetworkDifficulty(&curr));
-}
-
 extern json_spirit::Object blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDetails = false);
 
 TEST(rpc, check_blockToJSON_returns_minified_solution) {
index c45a95a9dc6bc607fe1fff2930dfea9e7b259eb2..3e595d6f7a82e2eac83570e8207a4be222b5fd0f 100644 (file)
@@ -24,23 +24,6 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
     if (pindexLast == NULL)
         return nProofOfWorkLimit;
 
-    const CBlockIndex* pindexBits = pindexLast;
-    {
-        if (params.fPowAllowMinDifficultyBlocks)
-        {
-            // Special difficulty rule for testnet:
-            // If the new block's timestamp is more than 2* 2.5 minutes
-            // then allow mining of a min-difficulty block.
-            if (pblock->GetBlockTime() > pindexLast->GetBlockTime() + params.nPowTargetSpacing*2)
-                return nProofOfWorkLimit;
-            else {
-                // Get the last non-min-difficulty (or at worst the genesis difficulty)
-                while (pindexBits->pprev && pindexBits->nBits == nProofOfWorkLimit)
-                    pindexBits = pindexBits->pprev;
-            }
-        }
-    }
-
     // Find the first block in the averaging interval
     const CBlockIndex* pindexFirst = pindexLast;
     arith_uint256 bnAvg;
index 44e30c623a7f663c8dca961b36245d9e6809e270..cf2b889e8cce2fc2101664b5e19493da0e8e2c86 100644 (file)
@@ -33,29 +33,21 @@ double GetDifficultyINTERNAL(const CBlockIndex* blockindex, bool networkDifficul
             blockindex = chainActive.Tip();
     }
 
-    uint32_t powLimit =
-        UintToArith256(Params().GetConsensus().powLimit).GetCompact();;
-    {
-        if (networkDifficulty && Params().GetConsensus().fPowAllowMinDifficultyBlocks)
-        {
-            // Special difficulty rule for testnet:
-            // If a block's timestamp is more than 2*nPowTargetSpacing minutes after
-            // the previous block, then it is permitted to be min-difficulty. So
-            // get the last non-min-difficulty (or at worst the genesis difficulty).
-            auto window = Params().GetConsensus().nPowTargetSpacing*2;
-            while (blockindex->pprev && blockindex->nBits == powLimit &&
-                    blockindex->GetBlockTime() > blockindex->pprev->GetBlockTime() + window) {
-                blockindex = blockindex->pprev;
-            }
-        }
+    uint32_t bits;
+    if (networkDifficulty) {
+        bits = GetNextWorkRequired(blockindex, nullptr, Params().GetConsensus());
+    } else {
+        bits = blockindex->nBits;
     }
 
-    int nShift = (blockindex->nBits >> 24) & 0xff;
+    uint32_t powLimit =
+        UintToArith256(Params().GetConsensus().powLimit).GetCompact();;
+    int nShift = (bits >> 24) & 0xff;
     int nShiftAmount = (powLimit >> 24) & 0xff;
 
     double dDiff =
         (double)(powLimit & 0x00ffffff) / 
-        (double)(blockindex->nBits & 0x00ffffff);
+        (double)(bits & 0x00ffffff);
 
     while (nShift < nShiftAmount)
     {
This page took 0.031443 seconds and 4 git commands to generate.