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
This commit is contained in:
Ross Nicoll 2015-07-06 00:07:37 +01:00
parent 949b1ccd88
commit 8d52844229
6 changed files with 19 additions and 25 deletions

View file

@ -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

View file

@ -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

View file

@ -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))

View file

@ -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();

View file

@ -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))

View file

@ -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