|
|
|
@ -2469,16 +2469,13 @@ bool AcceptBlockHeader(CBlockHeader& block, CValidationState& state, CBlockIndex
@@ -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)); |
|
|
|
|
|
|
|
|
|
// Reject block.nVersion=1 blocks when 95% (75% on testnet) of the network has upgraded:
|
|
|
|
|
if (block.nVersion < 2) |
|
|
|
|
{ |
|
|
|
|
if ((!TestNet() && CBlockIndex::IsSuperMajority(2, pindexPrev, 950, 1000)) || |
|
|
|
|
(TestNet() && CBlockIndex::IsSuperMajority(2, pindexPrev, 75, 100))) |
|
|
|
|
if (block.nVersion < 2 && |
|
|
|
|
CBlockIndex::IsSuperMajority(2, pindexPrev, Params().RejectBlockOutdatedMajority())) |
|
|
|
|
{ |
|
|
|
|
return state.Invalid(error("AcceptBlock() : rejected nVersion=1 block"), |
|
|
|
|
REJECT_OBSOLETE, "bad-version"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (pindex == NULL) |
|
|
|
|
pindex = AddToBlockIndex(block); |
|
|
|
@ -2517,19 +2514,15 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex,
@@ -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 ((!TestNet() && CBlockIndex::IsSuperMajority(2, pindex->pprev, 750, 1000)) || |
|
|
|
|
(TestNet() && CBlockIndex::IsSuperMajority(2, pindex->pprev, 51, 100))) |
|
|
|
|
if (block.nVersion >= 2 && |
|
|
|
|
CBlockIndex::IsSuperMajority(2, pindex->pprev, Params().EnforceBlockUpgradeMajority())) |
|
|
|
|
{ |
|
|
|
|
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"); |
|
|
|
|
} |
|
|
|
|
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,
@@ -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++) |
|
|
|
|
{ |
|
|
|
|