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/main.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/main.cpp')
| -rw-r--r-- | src/main.cpp | 61 |
1 files changed, 8 insertions, 53 deletions
diff --git a/src/main.cpp b/src/main.cpp index 4046330e9..39b97d1d6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1139,51 +1139,6 @@ bool GetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock // CBlock and CBlockIndex // -bool CheckProofOfWork(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.GetHash(), 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->getParentBlockHash(), block.nBits, params)) - return error("%s : AUX proof of work failed", __func__); - - return true; -} - bool WriteBlockToDisk(CBlock& block, CDiskBlockPos& pos, const CMessageHeader::MessageStartChars& messageStart) { // Open history file to append @@ -1227,7 +1182,7 @@ static bool ReadBlockOrHeader(T& block, const CDiskBlockPos& pos) } // Check the header - if (!CheckProofOfWork(block, Params().GetConsensus())) + if (!CheckAuxPowProofOfWork(block, Params().GetConsensus())) return error("ReadBlockFromDisk: Errors in block header at %s", pos.ToString()); return true; @@ -1895,7 +1850,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin unsigned int flags = fStrictPayToScriptHash ? SCRIPT_VERIFY_P2SH : SCRIPT_VERIFY_NONE; // Start enforcing the DERSIG (BIP66) rules, for block.nVersion=3 blocks, when 75% of the network has upgraded: - if (block.nVersion.GetBaseVersion() >= 3 && IsSuperMajority(3, pindex->pprev, chainparams.GetConsensus().nMajorityEnforceBlockUpgrade, chainparams.GetConsensus())) { + if (block.nVersion >= 3 && IsSuperMajority(3, pindex->pprev, chainparams.GetConsensus().nMajorityEnforceBlockUpgrade, chainparams.GetConsensus())) { flags |= SCRIPT_VERIFY_DERSIG; } @@ -2157,7 +2112,7 @@ void static UpdateTip(CBlockIndex *pindexNew) { const CBlockIndex* pindex = chainActive.Tip(); for (int i = 0; i < 100 && pindex != NULL; i++) { - if (pindex->nVersion.GetBaseVersion() > CBlock::CURRENT_VERSION) + if (pindex->nVersion > CBlock::CURRENT_VERSION) ++nUpgraded; pindex = pindex->pprev; } @@ -2712,7 +2667,7 @@ bool FindUndoPos(CValidationState &state, int nFile, CDiskBlockPos &pos, unsigne bool CheckBlockHeader(const CBlockHeader& block, CValidationState& state, bool fCheckPOW) { // Check proof of work matches claimed amount - if (fCheckPOW && !CheckProofOfWork(block, Params().GetConsensus())) + if (fCheckPOW && !CheckAuxPowProofOfWork(block, Params().GetConsensus())) return state.DoS(50, error("CheckBlockHeader(): proof of work failed"), REJECT_INVALID, "high-hash"); @@ -2827,12 +2782,12 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta } // Reject block.nVersion=1 blocks when 95% (75% on testnet) of the network has upgraded: - if (block.nVersion.GetBaseVersion() < 2 && IsSuperMajority(2, pindexPrev, consensusParams.nMajorityRejectBlockOutdated, consensusParams)) + if (block.nVersion < 2 && IsSuperMajority(2, pindexPrev, consensusParams.nMajorityRejectBlockOutdated, consensusParams)) return state.Invalid(error("%s: rejected nVersion=1 block", __func__), REJECT_OBSOLETE, "bad-version"); // Reject block.nVersion=2 blocks when 95% (75% on testnet) of the network has upgraded: - if (block.nVersion.GetBaseVersion() < 3 && IsSuperMajority(3, pindexPrev, consensusParams.nMajorityRejectBlockOutdated, consensusParams)) + if (block.nVersion < 3 && IsSuperMajority(3, pindexPrev, consensusParams.nMajorityRejectBlockOutdated, consensusParams)) return state.Invalid(error("%s : rejected nVersion=2 block", __func__), REJECT_OBSOLETE, "bad-version"); @@ -2852,7 +2807,7 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn // Enforce block.nVersion=2 rule that the coinbase starts with serialized block height // if 750 of the last 1,000 blocks are version 2 or greater (51/100 if testnet): - if (block.nVersion.GetBaseVersion() >= 2 && IsSuperMajority(2, pindexPrev, consensusParams.nMajorityEnforceBlockUpgrade, consensusParams)) + if (block.nVersion >= 2 && IsSuperMajority(2, pindexPrev, consensusParams.nMajorityEnforceBlockUpgrade, consensusParams)) { CScript expect = CScript() << nHeight; if (block.vtx[0].vin[0].scriptSig.size() < expect.size() || @@ -2970,7 +2925,7 @@ static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned unsigned int nFound = 0; for (int i = 0; i < consensusParams.nMajorityWindow && nFound < nRequired && pstart != NULL; i++) { - if (pstart->nVersion.GetBaseVersion() >= minVersion) + if (pstart->nVersion >= minVersion) ++nFound; pstart = pstart->pprev; } |