|
|
|
@ -75,10 +75,9 @@ void EraseOrphansFor(NodeId peer);
@@ -75,10 +75,9 @@ void EraseOrphansFor(NodeId peer);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns true if there are nRequired or more blocks of minVersion or above |
|
|
|
|
* in the last Params().ToCheckBlockUpgradeMajority() blocks, starting at pstart |
|
|
|
|
* and going backwards. |
|
|
|
|
* in the last Consensus::Params::nMajorityWindow blocks, starting at pstart and going backwards. |
|
|
|
|
*/ |
|
|
|
|
static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned int nRequired); |
|
|
|
|
static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned nRequired, const Consensus::Params& consensusParams); |
|
|
|
|
static void CheckBlockIndex(); |
|
|
|
|
|
|
|
|
|
/** Constant stuff for coinbase transactions we create: */ |
|
|
|
@ -1747,7 +1746,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
@@ -1747,7 +1746,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
|
|
|
|
|
unsigned int flags = fStrictPayToScriptHash ? SCRIPT_VERIFY_P2SH : SCRIPT_VERIFY_NONE; |
|
|
|
|
|
|
|
|
|
// Start enforcing the DERSIG (BIP66) rules, for block.nVersion=3 blocks, when 75% of the network has upgraded:
|
|
|
|
|
if (block.nVersion >= 3 && IsSuperMajority(3, pindex->pprev, Params().EnforceBlockUpgradeMajority())) { |
|
|
|
|
if (block.nVersion >= 3 && IsSuperMajority(3, pindex->pprev, chainparams.GetConsensus().nMajorityEnforceBlockUpgrade, chainparams.GetConsensus())) { |
|
|
|
|
flags |= SCRIPT_VERIFY_DERSIG; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -2644,18 +2643,14 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta
@@ -2644,18 +2643,14 @@ 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)) |
|
|
|
|
{ |
|
|
|
|
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)) |
|
|
|
|
{ |
|
|
|
|
if (block.nVersion < 3 && IsSuperMajority(3, pindexPrev, consensusParams.nMajorityRejectBlockOutdated, consensusParams)) |
|
|
|
|
return state.Invalid(error("%s : rejected nVersion=2 block", __func__), |
|
|
|
|
REJECT_OBSOLETE, "bad-version"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
@ -2663,6 +2658,7 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta
@@ -2663,6 +2658,7 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta
|
|
|
|
|
bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIndex * const pindexPrev) |
|
|
|
|
{ |
|
|
|
|
const int nHeight = pindexPrev == NULL ? 0 : pindexPrev->nHeight + 1; |
|
|
|
|
const Consensus::Params& consensusParams = Params().GetConsensus(); |
|
|
|
|
|
|
|
|
|
// Check that all transactions are finalized
|
|
|
|
|
BOOST_FOREACH(const CTransaction& tx, block.vtx) |
|
|
|
@ -2672,7 +2668,7 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn
@@ -2672,7 +2668,7 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn
|
|
|
|
|
|
|
|
|
|
// Enforce block.nVersion=2 rule that the coinbase starts with serialized block height
|
|
|
|
|
// if 750 of the last 1,000 blocks are version 2 or greater (51/100 if testnet):
|
|
|
|
|
if (block.nVersion >= 2 && IsSuperMajority(2, pindexPrev, Params().EnforceBlockUpgradeMajority())) |
|
|
|
|
if (block.nVersion >= 2 && IsSuperMajority(2, pindexPrev, consensusParams.nMajorityEnforceBlockUpgrade, consensusParams)) |
|
|
|
|
{ |
|
|
|
|
CScript expect = CScript() << nHeight; |
|
|
|
|
if (block.vtx[0].vin[0].scriptSig.size() < expect.size() || |
|
|
|
@ -2779,11 +2775,10 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex,
@@ -2779,11 +2775,10 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex,
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned int nRequired) |
|
|
|
|
static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned nRequired, const Consensus::Params& consensusParams) |
|
|
|
|
{ |
|
|
|
|
unsigned int nToCheck = Params().ToCheckBlockUpgradeMajority(); |
|
|
|
|
unsigned int nFound = 0; |
|
|
|
|
for (unsigned int i = 0; i < nToCheck && nFound < nRequired && pstart != NULL; i++) |
|
|
|
|
for (int i = 0; i < consensusParams.nMajorityWindow && nFound < nRequired && pstart != NULL; i++) |
|
|
|
|
{ |
|
|
|
|
if (pstart->nVersion >= minVersion) |
|
|
|
|
++nFound; |
|
|
|
|