Move majority constants to chainparams

This commit is contained in:
jtimon 2014-03-22 19:52:26 +01:00
parent 8d26721498
commit d754f34e8d
4 changed files with 34 additions and 22 deletions

View File

@ -112,6 +112,9 @@ public:
nRPCPort = 8332; nRPCPort = 8332;
bnProofOfWorkLimit = ~uint256(0) >> 32; bnProofOfWorkLimit = ~uint256(0) >> 32;
nSubsidyHalvingInterval = 210000; nSubsidyHalvingInterval = 210000;
nEnforceBlockUpgradeMajority = 750;
nRejectBlockOutdatedMajority = 950;
nToCheckBlockUpgradeMajority = 1000;
nMinerThreads = 0; nMinerThreads = 0;
// Build the genesis block. Note that the output of the genesis coinbase cannot // Build the genesis block. Note that the output of the genesis coinbase cannot
@ -199,6 +202,9 @@ public:
vAlertPubKey = ParseHex("04302390343f91cc401d56d68b123028bf52e5fca1939df127f63c6467cdf9c8e2c14b61104cf817d0b780da337893ecc4aaff1309e536162dabbdb45200ca2b0a"); vAlertPubKey = ParseHex("04302390343f91cc401d56d68b123028bf52e5fca1939df127f63c6467cdf9c8e2c14b61104cf817d0b780da337893ecc4aaff1309e536162dabbdb45200ca2b0a");
nDefaultPort = 18333; nDefaultPort = 18333;
nRPCPort = 18332; nRPCPort = 18332;
nEnforceBlockUpgradeMajority = 51;
nRejectBlockOutdatedMajority = 75;
nToCheckBlockUpgradeMajority = 100;
strDataDir = "testnet3"; strDataDir = "testnet3";
// Modify the testnet genesis block so the timestamp is valid for a later start. // Modify the testnet genesis block so the timestamp is valid for a later start.
@ -234,6 +240,9 @@ public:
pchMessageStart[2] = 0xb5; pchMessageStart[2] = 0xb5;
pchMessageStart[3] = 0xda; pchMessageStart[3] = 0xda;
nSubsidyHalvingInterval = 150; nSubsidyHalvingInterval = 150;
nEnforceBlockUpgradeMajority = 750;
nRejectBlockOutdatedMajority = 950;
nToCheckBlockUpgradeMajority = 1000;
nMinerThreads = 1; nMinerThreads = 1;
bnProofOfWorkLimit = ~uint256(0) >> 1; bnProofOfWorkLimit = ~uint256(0) >> 1;
genesis.nTime = 1296688602; genesis.nTime = 1296688602;

View File

@ -57,6 +57,11 @@ public:
int GetDefaultPort() const { return nDefaultPort; } int GetDefaultPort() const { return nDefaultPort; }
const uint256& ProofOfWorkLimit() const { return bnProofOfWorkLimit; } const uint256& ProofOfWorkLimit() const { return bnProofOfWorkLimit; }
int SubsidyHalvingInterval() const { return nSubsidyHalvingInterval; } int SubsidyHalvingInterval() const { return nSubsidyHalvingInterval; }
/* Used to check majorities for block version upgrade */
int EnforceBlockUpgradeMajority() const { return nEnforceBlockUpgradeMajority; }
int RejectBlockOutdatedMajority() const { return nRejectBlockOutdatedMajority; }
int ToCheckBlockUpgradeMajority() const { return nToCheckBlockUpgradeMajority; }
/* Used if GenerateBitcoins is called with a negative number of threads */ /* Used if GenerateBitcoins is called with a negative number of threads */
int DefaultMinerThreads() const { return nMinerThreads; } int DefaultMinerThreads() const { return nMinerThreads; }
virtual const CBlock& GenesisBlock() const = 0; virtual const CBlock& GenesisBlock() const = 0;
@ -85,6 +90,9 @@ protected:
int nRPCPort; int nRPCPort;
uint256 bnProofOfWorkLimit; uint256 bnProofOfWorkLimit;
int nSubsidyHalvingInterval; int nSubsidyHalvingInterval;
int nEnforceBlockUpgradeMajority;
int nRejectBlockOutdatedMajority;
int nToCheckBlockUpgradeMajority;
string strDataDir; string strDataDir;
int nMinerThreads; int nMinerThreads;
vector<CDNSSeedData> vSeeds; vector<CDNSSeedData> vSeeds;

View File

@ -2469,16 +2469,13 @@ bool AcceptBlockHeader(CBlockHeader& block, CValidationState& state, CBlockIndex
return state.DoS(100, error("AcceptBlock() : forked chain older than last checkpoint (height %d)", nHeight)); return state.DoS(100, error("AcceptBlock() : forked chain older than last checkpoint (height %d)", nHeight));
// Reject block.nVersion=1 blocks when 95% (75% on testnet) of the network has upgraded: // Reject block.nVersion=1 blocks when 95% (75% on testnet) of the network has upgraded:
if (block.nVersion < 2) if (block.nVersion < 2 &&
{ CBlockIndex::IsSuperMajority(2, pindexPrev, Params().RejectBlockOutdatedMajority()))
if ((!TestNet() && CBlockIndex::IsSuperMajority(2, pindexPrev, 950, 1000)) ||
(TestNet() && CBlockIndex::IsSuperMajority(2, pindexPrev, 75, 100)))
{ {
return state.Invalid(error("AcceptBlock() : rejected nVersion=1 block"), return state.Invalid(error("AcceptBlock() : rejected nVersion=1 block"),
REJECT_OBSOLETE, "bad-version"); REJECT_OBSOLETE, "bad-version");
} }
} }
}
if (pindex == NULL) if (pindex == NULL)
pindex = AddToBlockIndex(block); pindex = AddToBlockIndex(block);
@ -2517,19 +2514,15 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex,
} }
// Enforce block.nVersion=2 rule that the coinbase starts with serialized block height // Enforce block.nVersion=2 rule that the coinbase starts with serialized block height
if (block.nVersion >= 2)
{
// if 750 of the last 1,000 blocks are version 2 or greater (51/100 if testnet): // if 750 of the last 1,000 blocks are version 2 or greater (51/100 if testnet):
if ((!TestNet() && CBlockIndex::IsSuperMajority(2, pindex->pprev, 750, 1000)) || if (block.nVersion >= 2 &&
(TestNet() && CBlockIndex::IsSuperMajority(2, pindex->pprev, 51, 100))) CBlockIndex::IsSuperMajority(2, pindex->pprev, Params().EnforceBlockUpgradeMajority()))
{ {
CScript expect = CScript() << nHeight; CScript expect = CScript() << nHeight;
if (block.vtx[0].vin[0].scriptSig.size() < expect.size() || if (block.vtx[0].vin[0].scriptSig.size() < expect.size() ||
!std::equal(expect.begin(), expect.end(), block.vtx[0].vin[0].scriptSig.begin())) { !std::equal(expect.begin(), expect.end(), block.vtx[0].vin[0].scriptSig.begin())) {
pindex->nStatus |= BLOCK_FAILED_VALID; pindex->nStatus |= BLOCK_FAILED_VALID;
return state.DoS(100, error("AcceptBlock() : block height mismatch in coinbase"), return state.DoS(100, error("AcceptBlock() : block height mismatch in coinbase"), REJECT_INVALID, "bad-cb-height");
REJECT_INVALID, "bad-cb-height");
}
} }
} }
@ -2563,8 +2556,9 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex,
return true; return true;
} }
bool CBlockIndex::IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned int nRequired, unsigned int nToCheck) bool CBlockIndex::IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned int nRequired)
{ {
unsigned int nToCheck = Params().ToCheckBlockUpgradeMajority();
unsigned int nFound = 0; unsigned int nFound = 0;
for (unsigned int i = 0; i < nToCheck && nFound < nRequired && pstart != NULL; i++) for (unsigned int i = 0; i < nToCheck && nFound < nRequired && pstart != NULL; i++)
{ {

View File

@ -848,10 +848,11 @@ public:
/** /**
* Returns true if there are nRequired or more blocks of minVersion or above * Returns true if there are nRequired or more blocks of minVersion or above
* in the last nToCheck blocks, starting at pstart and going backwards. * in the last Params().ToCheckBlockUpgradeMajority() blocks, starting at pstart
* and going backwards.
*/ */
static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart, static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart,
unsigned int nRequired, unsigned int nToCheck); unsigned int nRequired);
std::string ToString() const std::string ToString() const
{ {