aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoss Nicoll <[email protected]>2017-09-24 15:56:19 +0100
committerRoss Nicoll <[email protected]>2019-07-13 22:25:22 +0000
commit3f788348e1621457629cce8d891b0ea459af7317 (patch)
tree1bcf22a94f2fea76789398d51f39a50fa1f8b362 /src
parentMerge AuxPoW support from Namecore (diff)
downloaddiscoin-3f788348e1621457629cce8d891b0ea459af7317.tar.xz
discoin-3f788348e1621457629cce8d891b0ea459af7317.zip
Sync changes from Dogecoin 1.10
Diffstat (limited to 'src')
-rw-r--r--src/dogecoin.cpp21
-rw-r--r--src/dogecoin.h1
-rw-r--r--src/pow.cpp15
-rw-r--r--src/qt/test/addressbooktests.cpp2
-rw-r--r--src/test/auxpow_tests.cpp4
5 files changed, 38 insertions, 5 deletions
diff --git a/src/dogecoin.cpp b/src/dogecoin.cpp
index 7e9281a4d..396c4cbc4 100644
--- a/src/dogecoin.cpp
+++ b/src/dogecoin.cpp
@@ -17,6 +17,24 @@ int static generateMTRandom(unsigned int s, int range)
return dist(gen);
}
+// Dogecoin: Normally minimum difficulty blocks can only occur in between
+// retarget blocks. However, once we introduce Digishield every block is
+// a retarget, so we need to handle minimum difficulty on all blocks.
+bool AllowDigishieldMinDifficultyForBlock(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params)
+{
+ // check if the chain allows minimum difficulty blocks
+ if (!params.fPowAllowMinDifficultyBlocks)
+ return false;
+
+ // check if the chain allows minimum difficulty blocks on recalc blocks
+ if (pindexLast->nHeight < 157500)
+ // if (!params.fPowAllowDigishieldMinDifficultyBlocks)
+ return false;
+
+ // Allow for a minimum block time if the elapsed time > 2*nTargetSpacing
+ return (pblock->GetBlockTime() > pindexLast->GetBlockTime() + params.nPowTargetSpacing*2);
+}
+
unsigned int CalculateDogecoinNextWorkRequired(const CBlockIndex* pindexLast, int64_t nFirstBlockTime, const Consensus::Params& params)
{
int nHeight = pindexLast->nHeight + 1;
@@ -90,8 +108,7 @@ bool CheckAuxPowProofOfWork(const CBlockHeader& block, const Consensus::Params&
params.nAuxpowChainId, block.nVersion);
/* If there is no auxpow, just check the block hash. */
- if (!block.auxpow)
- {
+ if (!block.auxpow) {
if (block.IsAuxpow())
return error("%s : no auxpow on block with auxpow version",
__func__);
diff --git a/src/dogecoin.h b/src/dogecoin.h
index 1adbc1925..403673da5 100644
--- a/src/dogecoin.h
+++ b/src/dogecoin.h
@@ -6,6 +6,7 @@
#include "chain.h"
#include "chainparams.h"
+bool AllowDigishieldMinDifficultyForBlock(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params);
CAmount GetDogecoinBlockSubsidy(int nHeight, const Consensus::Params& consensusParams, uint256 prevHash);
unsigned int CalculateDogecoinNextWorkRequired(const CBlockIndex* pindexLast, int64_t nLastRetargetTime, const Consensus::Params& params);
diff --git a/src/pow.cpp b/src/pow.cpp
index 8996b3b58..220dcba63 100644
--- a/src/pow.cpp
+++ b/src/pow.cpp
@@ -18,8 +18,21 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
assert(pindexLast != nullptr);
unsigned int nProofOfWorkLimit = UintToArith256(params.powLimit).GetCompact();
+ // Dogecoin: Special rules for minimum difficulty blocks with Digishield
+ if (AllowDigishieldMinDifficultyForBlock(pindexLast, pblock, params))
+ {
+ // Special difficulty rule for testnet:
+ // If the new block's timestamp is more than 2* nTargetSpacing minutes
+ // then allow mining of a min-difficulty block.
+ return nProofOfWorkLimit;
+ }
+
// Only change once per difficulty adjustment interval
- if ((pindexLast->nHeight+1) % params.DifficultyAdjustmentInterval() != 0)
+ bool fNewDifficultyProtocol = (pindexLast->nHeight >= 145000);
+ const int64_t difficultyAdjustmentInterval = fNewDifficultyProtocol
+ ? 1
+ : params.DifficultyAdjustmentInterval();
+ if ((pindexLast->nHeight+1) % difficultyAdjustmentInterval != 0)
{
if (params.fPowAllowMinDifficultyBlocks)
{
diff --git a/src/qt/test/addressbooktests.cpp b/src/qt/test/addressbooktests.cpp
index 352584604..6760b0786 100644
--- a/src/qt/test/addressbooktests.cpp
+++ b/src/qt/test/addressbooktests.cpp
@@ -56,7 +56,7 @@ void EditAddressAndSubmit(
*/
void TestAddAddressesToSendBook()
{
- TestChain100Setup test;
+ TestChain240Setup test;
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>("mock", WalletDatabase::CreateMock());
bool firstRun;
wallet->LoadWallet(firstRun);
diff --git a/src/test/auxpow_tests.cpp b/src/test/auxpow_tests.cpp
index ce9954fe6..6447ef9fd 100644
--- a/src/test/auxpow_tests.cpp
+++ b/src/test/auxpow_tests.cpp
@@ -414,7 +414,9 @@ BOOST_FIXTURE_TEST_CASE (auxpow_pow, BasicTestingSetup)
mineBlock(block, true);
BOOST_CHECK(CheckAuxPowProofOfWork(block, params));
- block.nVersion = 2;
+ // Dogecoin block version 2 can be both AuxPoW and regular, so test 3
+
+ block.nVersion = 3;
mineBlock(block, true);
BOOST_CHECK(!CheckAuxPowProofOfWork(block, params));