diff options
| author | Ross Nicoll <[email protected]> | 2015-07-05 17:45:38 +0100 |
|---|---|---|
| committer | Ross Nicoll <[email protected]> | 2015-07-10 20:23:14 +0100 |
| commit | c453bcc9e5fd98ae4aebd1f2fc85192b5fd7410a (patch) | |
| tree | 0422e17d73ffc244e48ba41c4ea63cd39c8b09dd /src/dogecoin.cpp | |
| parent | Merge AuxPoW support from Namecore (diff) | |
| download | discoin-c453bcc9e5fd98ae4aebd1f2fc85192b5fd7410a.tar.xz discoin-c453bcc9e5fd98ae4aebd1f2fc85192b5fd7410a.zip | |
Adapt AuxPoW to Dogecoin
Changed AuxPoW parent block hashing to use Scrypt rather than SHA256 hash.
Update chain parameters to match Dogecoin
Move CheckProofOfWork into dogecoin.cpp and rename it to CheckAuxPowProofOfWork.
Add operator overrides to CBlockVersion so that naive usage operates on the underlying version without chain ID or flags.
Modify RPC mining to more closely match existing submitblock() structure
Diffstat (limited to 'src/dogecoin.cpp')
| -rw-r--r-- | src/dogecoin.cpp | 51 |
1 files changed, 48 insertions, 3 deletions
diff --git a/src/dogecoin.cpp b/src/dogecoin.cpp index e946acad6..dd394d5b4 100644 --- a/src/dogecoin.cpp +++ b/src/dogecoin.cpp @@ -21,9 +21,9 @@ unsigned int CalculateDogecoinNextWorkRequired(const CBlockIndex* pindexLast, in int nHeight = pindexLast->nHeight + 1; bool fNewDifficultyProtocol = (nHeight >= 145000); // bool fNewDifficultyProtocol = (nHeight >= params.GetDigiShieldForkBlock()); - const int64_t retargetTimespan = fNewDifficultyProtocol - ? 60 // params.DigiShieldTargetTimespan() - : params.nPowTargetTimespan; + const int64_t retargetTimespan = fNewDifficultyProtocol ? 60 // params.DigiShieldTargetTimespan() + : + params.nPowTargetTimespan; const int64_t nActualTimespan = pindexLast->GetBlockTime() - nFirstBlockTime; int64_t nModulatedTimespan = nActualTimespan; @@ -75,6 +75,51 @@ unsigned int CalculateDogecoinNextWorkRequired(const CBlockIndex* pindexLast, in return bnNew.GetCompact(); } +bool CheckAuxPowProofOfWork(const CBlockHeader& block, const Consensus::Params& params) +{ + /* Except for legacy blocks with full version 1, ensure that + the chain ID is correct. Legacy blocks are not allowed since + the merge-mining start, which is checked in AcceptBlockHeader + where the height is known. */ + if (!block.nVersion.IsLegacy() && params.fStrictChainId && block.nVersion.GetChainId() != params.nAuxpowChainId) + return error("%s : block does not have our chain ID" + " (got %d, expected %d, full nVersion %d)", + __func__, + block.nVersion.GetChainId(), + params.nAuxpowChainId, + block.nVersion.GetFullVersion()); + + /* If there is no auxpow, just check the block hash. */ + if (!block.auxpow) { + if (block.nVersion.IsAuxpow()) + return error("%s : no auxpow on block with auxpow version", + __func__); + + if (!CheckProofOfWork(block.GetPoWHash(), block.nBits, params)) + return error("%s : non-AUX proof of work failed", __func__); + + return true; + } + + /* We have auxpow. Check it. */ + + 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)) + return error("%s : AUX proof of work failed", __func__); + + return true; +} + CAmount GetDogecoinBlockSubsidy(int nHeight, const Consensus::Params& consensusParams, uint256 prevHash) { int halvings = nHeight / consensusParams.nSubsidyHalvingInterval; |