diff options
| -rw-r--r-- | src/chain.h | 17 | ||||
| -rw-r--r-- | src/chainparams.cpp | 3 | ||||
| -rw-r--r-- | src/consensus/params.h | 1 | ||||
| -rw-r--r-- | src/dogecoin.cpp | 8 | ||||
| -rw-r--r-- | src/main.cpp | 5 | ||||
| -rw-r--r-- | src/test/dogecoin_tests.cpp | 6 | ||||
| -rw-r--r-- | src/txdb.cpp | 14 |
7 files changed, 42 insertions, 12 deletions
diff --git a/src/chain.h b/src/chain.h index c735f6a70..359a14771 100644 --- a/src/chain.h +++ b/src/chain.h @@ -111,6 +111,9 @@ public: //! pointer to the index of some further predecessor of this block CBlockIndex* pskip; + //! pointer to the AuxPoW header, if this block has one + boost::shared_ptr<CAuxPow> pauxpow; + //! height of the entry in the chain. The genesis block has height 0 int nHeight; @@ -145,6 +148,9 @@ public: unsigned int nBits; unsigned int nNonce; + // Dogecoin: Keep the Scrypt hash as well as SHA256 + uint256 hashBlockPoW; + //! (memory only) Sequential id assigned to distinguish order in which blocks are received. uint32_t nSequenceId; @@ -153,6 +159,7 @@ public: phashBlock = NULL; pprev = NULL; pskip = NULL; + pauxpow.reset(); nHeight = 0; nFile = 0; nDataPos = 0; @@ -168,6 +175,7 @@ public: nTime = 0; nBits = 0; nNonce = 0; + hashBlockPoW = uint256(); } CBlockIndex() @@ -184,6 +192,7 @@ public: nTime = block.nTime; nBits = block.nBits; nNonce = block.nNonce; + hashBlockPoW = block.GetPoWHash(); } CDiskBlockPos GetBlockPos() const { @@ -309,6 +318,14 @@ public: READWRITE(nTime); READWRITE(nBits); READWRITE(nNonce); + READWRITE(hashBlockPoW); + if (this->nVersion.IsAuxpow()) { + if (ser_action.ForRead()) + pauxpow.reset(new CAuxPow()); + assert(pauxpow); + READWRITE(*pauxpow); + } else if (ser_action.ForRead()) + pauxpow.reset(); } uint256 GetBlockHash() const diff --git a/src/chainparams.cpp b/src/chainparams.cpp index a26655585..94bf5b33f 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -45,6 +45,7 @@ public: consensus.nPowTargetSpacing = 60; // 1 minute consensus.fPowAllowMinDifficultyBlocks = false; consensus.fPowAllowDigishieldMinDifficultyBlocks = false; + consensus.fSimplifiedRewards = false; consensus.nAuxpowChainId = 0x0062; // 98 - Josh Wise! consensus.fStrictChainId = true; consensus.fAllowLegacyBlocks = true; @@ -54,6 +55,7 @@ public: // Blocks 145000 - 371336 are Digishield without AuxPoW digishieldConsensus = consensus; digishieldConsensus.nHeightEffective = 145000; + digishieldConsensus.fSimplifiedRewards = true; digishieldConsensus.fDigishieldDifficultyCalculation = true; digishieldConsensus.nPowTargetTimespan = 60; // post-digishield: 1 minute @@ -199,6 +201,7 @@ public: digishieldConsensus.nHeightEffective = 145000; digishieldConsensus.nPowTargetTimespan = 60; // post-digishield: 1 minute digishieldConsensus.fDigishieldDifficultyCalculation = true; + digishieldConsensus.fSimplifiedRewards = true; digishieldConsensus.fPowAllowMinDifficultyBlocks = false; // Blocks 157500 - 158099 are Digishield with minimum difficulty on all blocks diff --git a/src/consensus/params.h b/src/consensus/params.h index f0fdae660..906599ff4 100644 --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -29,6 +29,7 @@ struct Params { /** Dogecoin-specific parameters */ bool fDigishieldDifficultyCalculation; bool fPowAllowDigishieldMinDifficultyBlocks; // Allow minimum difficulty blocks where a retarget would normally occur + bool fSimplifiedRewards; /** Auxpow parameters */ int16_t nAuxpowChainId; diff --git a/src/dogecoin.cpp b/src/dogecoin.cpp index 6916982e0..90eaec9ec 100644 --- a/src/dogecoin.cpp +++ b/src/dogecoin.cpp @@ -113,12 +113,6 @@ bool CheckAuxPowProofOfWork(const CBlockHeader& block, const Consensus::Params& if (!block.nVersion.IsAuxpow()) return error("%s : auxpow on block with non-auxpow version", __func__); - /* Temporary check: Disallow parent blocks with auxpow version. This is - for compatibility with the old client. */ - /* FIXME: Remove this check with a hardfork later on. */ - if (block.auxpow->getParentBlock().nVersion.IsAuxpow()) - return error("%s : auxpow parent block has auxpow version", __func__); - if (!block.auxpow->check(block.GetHash(), block.nVersion.GetChainId(), params)) return error("%s : AUX POW is not valid", __func__); if (!CheckProofOfWork(block.auxpow->getParentBlockPoWHash(), block.nBits, params)) @@ -131,7 +125,7 @@ CAmount GetDogecoinBlockSubsidy(int nHeight, const Consensus::Params& consensusP { int halvings = nHeight / consensusParams.nSubsidyHalvingInterval; - if (nHeight < 145000) // && !consensusParams.SimplifiedRewards()) + if (!consensusParams.fSimplifiedRewards) { // Old-style rewards derived from the previous block hash const std::string cseed_str = prevHash.ToString().substr(7, 7); diff --git a/src/main.cpp b/src/main.cpp index cd4670254..b42638096 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2532,6 +2532,11 @@ CBlockIndex* AddToBlockIndex(const CBlockHeader& block) pindexNew->BuildSkip(); } pindexNew->nChainWork = (pindexNew->pprev ? pindexNew->pprev->nChainWork : 0) + GetBlockProof(*pindexNew); + // Dogecoin: Add AuxPoW + if (block.nVersion.IsAuxpow()) { + pindexNew->pauxpow = block.auxpow; + assert(NULL != pindexNew->pauxpow.get()); + } pindexNew->RaiseValidity(BLOCK_VALID_TREE); if (pindexBestHeader == NULL || pindexBestHeader->nChainWork < pindexNew->nChainWork) pindexBestHeader = pindexNew; diff --git a/src/test/dogecoin_tests.cpp b/src/test/dogecoin_tests.cpp index 7185b377a..efa4e9207 100644 --- a/src/test/dogecoin_tests.cpp +++ b/src/test/dogecoin_tests.cpp @@ -63,23 +63,26 @@ BOOST_AUTO_TEST_CASE(subsidy_limit_test) { int nHeight = 0; int nStepSize= 1; - const Consensus::Params& params = Params(CBaseChainParams::MAIN).GetConsensus(0); CAmount nSum = 0; uint256 prevHash = uint256S("0"); + const CChainParams mainParams = Params(CBaseChainParams::MAIN); for (nHeight = 0; nHeight <= 100000; nHeight++) { + const Consensus::Params& params = mainParams.GetConsensus(nHeight); CAmount nSubsidy = GetDogecoinBlockSubsidy(nHeight, params, prevHash); BOOST_CHECK(MoneyRange(nSubsidy)); BOOST_CHECK(nSubsidy <= 1000000 * COIN); nSum += nSubsidy * nStepSize; } for (; nHeight <= 145000; nHeight++) { + const Consensus::Params& params = mainParams.GetConsensus(nHeight); CAmount nSubsidy = GetDogecoinBlockSubsidy(nHeight, params, prevHash); BOOST_CHECK(MoneyRange(nSubsidy)); BOOST_CHECK(nSubsidy <= 500000 * COIN); nSum += nSubsidy * nStepSize; } for (; nHeight < 600000; nHeight++) { + const Consensus::Params& params = mainParams.GetConsensus(nHeight); CAmount nSubsidy = GetDogecoinBlockSubsidy(nHeight, params, prevHash); CAmount nExpectedSubsidy = (500000 >> (nHeight / 100000)) * COIN; BOOST_CHECK(MoneyRange(nSubsidy)); @@ -95,6 +98,7 @@ BOOST_AUTO_TEST_CASE(subsidy_limit_test) BOOST_CHECK(nSum >= lowerlimit); // Test reward at 600k+ is constant + const Consensus::Params& params = mainParams.GetConsensus(600000); CAmount nConstantSubsidy = GetDogecoinBlockSubsidy(600000, params, prevHash); BOOST_CHECK_EQUAL(nConstantSubsidy, 10000 * COIN); diff --git a/src/txdb.cpp b/src/txdb.cpp index bdc67a049..7eb857ed5 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -213,6 +213,7 @@ bool CBlockTreeDB::LoadBlockIndexGuts() // Construct block index object CBlockIndex* pindexNew = InsertBlockIndex(diskindex.GetBlockHash()); pindexNew->pprev = InsertBlockIndex(diskindex.hashPrev); + pindexNew->pauxpow = diskindex.pauxpow; pindexNew->nHeight = diskindex.nHeight; pindexNew->nFile = diskindex.nFile; pindexNew->nDataPos = diskindex.nDataPos; @@ -224,11 +225,16 @@ bool CBlockTreeDB::LoadBlockIndexGuts() pindexNew->nNonce = diskindex.nNonce; pindexNew->nStatus = diskindex.nStatus; pindexNew->nTx = diskindex.nTx; + pindexNew->hashBlockPoW = diskindex.hashBlockPoW; - /* Bitcoin checks the PoW here. We don't do this because - the CDiskBlockIndex does not contain the auxpow. - This check isn't important, since the data on disk should - already be valid and can be trusted. */ + if (pindexNew->nVersion.IsAuxpow()) { + if (!diskindex.pauxpow->check(diskindex.GetBlockHash(), pindexNew->nVersion.GetChainId(), Params().GetConsensus(pindexNew->nHeight))) { + return error("LoadBlockIndex(): CheckProofOfWork failed: %s", pindexNew->ToString()); + } + } else { + if (!CheckProofOfWork(pindexNew->hashBlockPoW, pindexNew->nBits, Params().GetConsensus(pindexNew->nHeight))) + return error("LoadBlockIndex(): CheckProofOfWork failed: %s", pindexNew->ToString()); + } pcursor->Next(); } else { |