Browse Source

Move majority constants to chainparams

0.10
jtimon 10 years ago
parent
commit
d754f34e8d
  1. 9
      src/chainparams.cpp
  2. 8
      src/chainparams.h
  3. 34
      src/main.cpp
  4. 5
      src/main.h

9
src/chainparams.cpp

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

8
src/chainparams.h

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

34
src/main.cpp

@ -2469,14 +2469,11 @@ 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)) || return state.Invalid(error("AcceptBlock() : rejected nVersion=1 block"),
(TestNet() && CBlockIndex::IsSuperMajority(2, pindexPrev, 75, 100))) REJECT_OBSOLETE, "bad-version");
{
return state.Invalid(error("AcceptBlock() : rejected nVersion=1 block"),
REJECT_OBSOLETE, "bad-version");
}
} }
} }
@ -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 (block.nVersion >= 2 &&
CBlockIndex::IsSuperMajority(2, pindex->pprev, Params().EnforceBlockUpgradeMajority()))
{ {
// if 750 of the last 1,000 blocks are version 2 or greater (51/100 if testnet): CScript expect = CScript() << nHeight;
if ((!TestNet() && CBlockIndex::IsSuperMajority(2, pindex->pprev, 750, 1000)) || if (block.vtx[0].vin[0].scriptSig.size() < expect.size() ||
(TestNet() && CBlockIndex::IsSuperMajority(2, pindex->pprev, 51, 100))) !std::equal(expect.begin(), expect.end(), block.vtx[0].vin[0].scriptSig.begin())) {
{ pindex->nStatus |= BLOCK_FAILED_VALID;
CScript expect = CScript() << nHeight; return state.DoS(100, error("AcceptBlock() : block height mismatch in coinbase"), REJECT_INVALID, "bad-cb-height");
if (block.vtx[0].vin[0].scriptSig.size() < expect.size() ||
!std::equal(expect.begin(), expect.end(), block.vtx[0].vin[0].scriptSig.begin())) {
pindex->nStatus |= BLOCK_FAILED_VALID;
return state.DoS(100, error("AcceptBlock() : block height mismatch in coinbase"),
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++)
{ {

5
src/main.h

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

Loading…
Cancel
Save