aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/chainparams.cpp9
-rw-r--r--src/chainparams.h8
-rw-r--r--src/main.cpp34
-rw-r--r--src/main.h5
4 files changed, 34 insertions, 22 deletions
diff --git a/src/chainparams.cpp b/src/chainparams.cpp
index 75a14c6013..86d80629eb 100644
--- a/src/chainparams.cpp
+++ b/src/chainparams.cpp
@@ -112,6 +112,9 @@ public:
nRPCPort = 8332;
bnProofOfWorkLimit = ~uint256(0) >> 32;
nSubsidyHalvingInterval = 210000;
+ nEnforceBlockUpgradeMajority = 750;
+ nRejectBlockOutdatedMajority = 950;
+ nToCheckBlockUpgradeMajority = 1000;
nMinerThreads = 0;
// Build the genesis block. Note that the output of the genesis coinbase cannot
@@ -199,6 +202,9 @@ public:
vAlertPubKey = ParseHex("04302390343f91cc401d56d68b123028bf52e5fca1939df127f63c6467cdf9c8e2c14b61104cf817d0b780da337893ecc4aaff1309e536162dabbdb45200ca2b0a");
nDefaultPort = 18333;
nRPCPort = 18332;
+ nEnforceBlockUpgradeMajority = 51;
+ nRejectBlockOutdatedMajority = 75;
+ nToCheckBlockUpgradeMajority = 100;
strDataDir = "testnet3";
// Modify the testnet genesis block so the timestamp is valid for a later start.
@@ -234,6 +240,9 @@ public:
pchMessageStart[2] = 0xb5;
pchMessageStart[3] = 0xda;
nSubsidyHalvingInterval = 150;
+ nEnforceBlockUpgradeMajority = 750;
+ nRejectBlockOutdatedMajority = 950;
+ nToCheckBlockUpgradeMajority = 1000;
nMinerThreads = 1;
bnProofOfWorkLimit = ~uint256(0) >> 1;
genesis.nTime = 1296688602;
diff --git a/src/chainparams.h b/src/chainparams.h
index f0c90bf50f..f400907d73 100644
--- a/src/chainparams.h
+++ b/src/chainparams.h
@@ -57,6 +57,11 @@ public:
int GetDefaultPort() const { return nDefaultPort; }
const uint256& ProofOfWorkLimit() const { return bnProofOfWorkLimit; }
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 */
int DefaultMinerThreads() const { return nMinerThreads; }
virtual const CBlock& GenesisBlock() const = 0;
@@ -85,6 +90,9 @@ protected:
int nRPCPort;
uint256 bnProofOfWorkLimit;
int nSubsidyHalvingInterval;
+ int nEnforceBlockUpgradeMajority;
+ int nRejectBlockOutdatedMajority;
+ int nToCheckBlockUpgradeMajority;
string strDataDir;
int nMinerThreads;
vector<CDNSSeedData> vSeeds;
diff --git a/src/main.cpp b/src/main.cpp
index 30fa9c6d70..e6519864d8 100644
--- a/src/main.cpp
+++ b/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));
// 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"),
- 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
- 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):
- if ((!TestNet() && CBlockIndex::IsSuperMajority(2, pindex->pprev, 750, 1000)) ||
- (TestNet() && CBlockIndex::IsSuperMajority(2, pindex->pprev, 51, 100)))
- {
- CScript expect = CScript() << nHeight;
- 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");
- }
+ CScript expect = CScript() << nHeight;
+ 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;
}
-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;
for (unsigned int i = 0; i < nToCheck && nFound < nRequired && pstart != NULL; i++)
{
diff --git a/src/main.h b/src/main.h
index 42cf4a0861..58515b44b9 100644
--- a/src/main.h
+++ b/src/main.h
@@ -848,10 +848,11 @@ public:
/**
* 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,
- unsigned int nRequired, unsigned int nToCheck);
+ unsigned int nRequired);
std::string ToString() const
{