From 8d5284422914164f73bfbdf3b275879da355af30 Mon Sep 17 00:00:00 2001 From: Ross Nicoll Date: Mon, 6 Jul 2015 00:07:37 +0100 Subject: [PATCH] Minor Dogecoin consensus fixes Updated maximum coins to match Dogecoin. Updated protocol version to disable connections to pre-AuxPoW clients. Disable version 2 block requirement Update coinbase maturity to match Dogecoin --- src/amount.h | 2 +- src/consensus/consensus.h | 6 +++++- src/main.cpp | 13 +++++++++---- src/pow.cpp | 16 ---------------- src/rpcserver.cpp | 3 ++- src/version.h | 4 ++-- 6 files changed, 19 insertions(+), 25 deletions(-) diff --git a/src/amount.h b/src/amount.h index 9212244a8..5e33b7958 100644 --- a/src/amount.h +++ b/src/amount.h @@ -17,7 +17,7 @@ static const CAmount COIN = 100000000; static const CAmount CENT = 1000000; /** No amount larger than this (in satoshi) is valid */ -static const CAmount MAX_MONEY = 21000000 * COIN; +static const CAmount MAX_MONEY = 10000000000 * COIN; // Dogecoin: maximum of 100B coins (given some randomness), max transaction 10,000,000,000 inline bool MoneyRange(const CAmount& nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); } /** Type-safe wrapper class to for fee rates diff --git a/src/consensus/consensus.h b/src/consensus/consensus.h index 9c5b7d4ff..1bf388bef 100644 --- a/src/consensus/consensus.h +++ b/src/consensus/consensus.h @@ -11,7 +11,11 @@ static const unsigned int MAX_BLOCK_SIZE = 1000000; /** The maximum allowed number of signature check operations in a block (network rule) */ static const unsigned int MAX_BLOCK_SIGOPS = MAX_BLOCK_SIZE/50; /** Coinbase transaction outputs can only be spent after this number of new blocks (network rule) */ -static const int COINBASE_MATURITY = 100; +static const int COINBASE_MATURITY = 60*4; // 4 hours of blocks +/** Coinbase maturity before block 145000 **/ +static const int COINBASE_MATURITY_OLD = 30; +/** Block at which COINBASE_MATURITY_OLD was deprecated **/ +static const int COINBASE_MATURITY_SWITCH = 145000; /** Threshold for nLockTime: below this value it is interpreted as block number, otherwise as UNIX timestamp. */ static const unsigned int LOCKTIME_THRESHOLD = 500000000; // Tue Nov 5 00:53:20 1985 UTC diff --git a/src/main.cpp b/src/main.cpp index a5a8db09e..dfcd50310 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1444,7 +1444,11 @@ bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsVi // If prev is coinbase, check that it's matured if (coins->IsCoinBase()) { - if (nSpendHeight - coins->nHeight < COINBASE_MATURITY) + // Dogecoin: Switch maturity at depth 145,000 + int nCoinbaseMaturity = coins->nHeight < COINBASE_MATURITY_SWITCH + ? COINBASE_MATURITY_OLD + : COINBASE_MATURITY; + if (nSpendHeight - coins->nHeight < nCoinbaseMaturity) return state.Invalid( error("CheckInputs(): tried to spend coinbase at depth %d", nSpendHeight - coins->nHeight), REJECT_INVALID, "bad-txns-premature-spend-of-coinbase"); @@ -2783,9 +2787,10 @@ 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 < 2 && IsSuperMajority(2, pindexPrev, consensusParams.nMajorityRejectBlockOutdated, consensusParams)) - return state.Invalid(error("%s: rejected nVersion=1 block", __func__), - REJECT_OBSOLETE, "bad-version"); + // Dogecoin: Version 2 enforcement was never used + //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 < 3 && IsSuperMajority(3, pindexPrev, consensusParams.nMajorityRejectBlockOutdated, consensusParams)) diff --git a/src/pow.cpp b/src/pow.cpp index 772e11f2f..a0fac9219 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -12,22 +12,6 @@ #include "uint256.h" #include "util.h" -// Determine if the for the given block, a min difficulty setting applies -bool AllowMinDifficultyForBlock(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) -{ - // check if the chain allows minimum difficulty blocks - if (!params.fPowAllowMinDifficultyBlocks) - return false; - - // Dogecoin: Magic number at which reset protocol switches - // check if we allow minimum difficulty at this block-height - if (pindexLast->nHeight < 157500) - return false; - - // Allow for a minimum block time if the elapsed time > 2*nTargetSpacing - return (pblock->GetBlockTime() > pindexLast->GetBlockTime() + params.nPowTargetSpacing*2); -} - unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) { unsigned int nProofOfWorkLimit = UintToArith256(params.powLimit).GetCompact(); diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index f5902d2e5..b2dc252f8 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -126,7 +126,8 @@ static inline int64_t roundint64(double d) CAmount AmountFromValue(const Value& value) { double dAmount = value.get_real(); - if (dAmount <= 0.0 || dAmount > 21000000.0) + double dMaxAmount = MAX_MONEY / COIN; + if (dAmount <= 0.0 || dAmount > dMaxAmount) throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount"); CAmount nAmount = roundint64(dAmount * COIN); if (!MoneyRange(nAmount)) diff --git a/src/version.h b/src/version.h index 38b3d2e73..278ddb71e 100644 --- a/src/version.h +++ b/src/version.h @@ -9,7 +9,7 @@ * network protocol versioning */ -static const int PROTOCOL_VERSION = 70002; +static const int PROTOCOL_VERSION = 70003; //! initial proto version, to be increased after version/verack negotiation static const int INIT_PROTO_VERSION = 209; @@ -18,7 +18,7 @@ static const int INIT_PROTO_VERSION = 209; static const int GETHEADERS_VERSION = 31800; //! disconnect from peers older than this proto version -static const int MIN_PEER_PROTO_VERSION = GETHEADERS_VERSION; +static const int MIN_PEER_PROTO_VERSION = 70003; //! nTime field added to CAddress, starting with this version; //! if possible, avoid requesting addresses nodes older than this