|
|
|
@ -106,11 +106,6 @@ map<uint256, COrphanTx> mapOrphanTransactions GUARDED_BY(cs_main);
@@ -106,11 +106,6 @@ map<uint256, COrphanTx> mapOrphanTransactions GUARDED_BY(cs_main);
|
|
|
|
|
map<COutPoint, set<map<uint256, COrphanTx>::iterator, IteratorComparator>> mapOrphanTransactionsByPrev GUARDED_BY(cs_main); |
|
|
|
|
void EraseOrphansFor(NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(cs_main); |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns true if there are nRequired or more blocks of minVersion or above |
|
|
|
|
* in the last Consensus::Params::nMajorityWindow blocks, starting at pstart and going backwards. |
|
|
|
|
*/ |
|
|
|
|
static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned nRequired, const Consensus::Params& consensusParams); |
|
|
|
|
static void CheckBlockIndex(const Consensus::Params& consensusParams); |
|
|
|
|
|
|
|
|
|
/** Constant stuff for coinbase transactions we create: */ |
|
|
|
@ -2372,15 +2367,13 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
@@ -2372,15 +2367,13 @@ 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, chainparams.GetConsensus().nMajorityEnforceBlockUpgrade, chainparams.GetConsensus())) { |
|
|
|
|
// Start enforcing the DERSIG (BIP66) rule
|
|
|
|
|
if (pindex->nHeight >= chainparams.GetConsensus().BIP66Height) { |
|
|
|
|
flags |= SCRIPT_VERIFY_DERSIG; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Start enforcing CHECKLOCKTIMEVERIFY, (BIP65) for block.nVersion=4
|
|
|
|
|
// blocks, when 75% of the network has upgraded:
|
|
|
|
|
if (block.nVersion >= 4 && IsSuperMajority(4, pindex->pprev, chainparams.GetConsensus().nMajorityEnforceBlockUpgrade, chainparams.GetConsensus())) { |
|
|
|
|
// Start enforcing CHECKLOCKTIMEVERIFY (BIP65) rule
|
|
|
|
|
if (pindex->nHeight >= chainparams.GetConsensus().BIP65Height) { |
|
|
|
|
flags |= SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -3504,6 +3497,7 @@ std::vector<unsigned char> GenerateCoinbaseCommitment(CBlock& block, const CBloc
@@ -3504,6 +3497,7 @@ std::vector<unsigned char> GenerateCoinbaseCommitment(CBlock& block, const CBloc
|
|
|
|
|
|
|
|
|
|
bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& state, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev, int64_t nAdjustedTime) |
|
|
|
|
{ |
|
|
|
|
const int nHeight = pindexPrev == NULL ? 0 : pindexPrev->nHeight + 1; |
|
|
|
|
// Check proof of work
|
|
|
|
|
if (block.nBits != GetNextWorkRequired(pindexPrev, &block, consensusParams)) |
|
|
|
|
return state.DoS(100, false, REJECT_INVALID, "bad-diffbits", false, "incorrect proof of work"); |
|
|
|
@ -3517,10 +3511,12 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta
@@ -3517,10 +3511,12 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta
|
|
|
|
|
return state.Invalid(false, REJECT_INVALID, "time-too-new", "block timestamp too far in the future"); |
|
|
|
|
|
|
|
|
|
// Reject outdated version blocks when 95% (75% on testnet) of the network has upgraded:
|
|
|
|
|
for (int32_t version = 2; version < 5; ++version) // check for version 2, 3 and 4 upgrades
|
|
|
|
|
if (block.nVersion < version && IsSuperMajority(version, pindexPrev, consensusParams.nMajorityRejectBlockOutdated, consensusParams)) |
|
|
|
|
return state.Invalid(false, REJECT_OBSOLETE, strprintf("bad-version(0x%08x)", version - 1), |
|
|
|
|
strprintf("rejected nVersion=0x%08x block", version - 1)); |
|
|
|
|
// check for version 2, 3 and 4 upgrades
|
|
|
|
|
if((block.nVersion < 2 && nHeight >= consensusParams.BIP34Height) || |
|
|
|
|
(block.nVersion < 3 && nHeight >= consensusParams.BIP66Height) || |
|
|
|
|
(block.nVersion < 4 && nHeight >= consensusParams.BIP65Height)) |
|
|
|
|
return state.Invalid(false, REJECT_OBSOLETE, strprintf("bad-version(0x%08x)", block.nVersion), |
|
|
|
|
strprintf("rejected nVersion=0x%08x block", block.nVersion)); |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
@ -3546,9 +3542,8 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, const Co
@@ -3546,9 +3542,8 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, const Co
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 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, consensusParams.nMajorityEnforceBlockUpgrade, consensusParams)) |
|
|
|
|
// Enforce rule that the coinbase starts with serialized block height
|
|
|
|
|
if (nHeight >= consensusParams.BIP34Height) |
|
|
|
|
{ |
|
|
|
|
CScript expect = CScript() << nHeight; |
|
|
|
|
if (block.vtx[0].vin[0].scriptSig.size() < expect.size() || |
|
|
|
@ -3722,19 +3717,6 @@ static bool AcceptBlock(const CBlock& block, CValidationState& state, const CCha
@@ -3722,19 +3717,6 @@ static bool AcceptBlock(const CBlock& block, CValidationState& state, const CCha
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned nRequired, const Consensus::Params& consensusParams) |
|
|
|
|
{ |
|
|
|
|
unsigned int nFound = 0; |
|
|
|
|
for (int i = 0; i < consensusParams.nMajorityWindow && nFound < nRequired && pstart != NULL; i++) |
|
|
|
|
{ |
|
|
|
|
if (pstart->nVersion >= minVersion) |
|
|
|
|
++nFound; |
|
|
|
|
pstart = pstart->pprev; |
|
|
|
|
} |
|
|
|
|
return (nFound >= nRequired); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool ProcessNewBlock(CValidationState& state, const CChainParams& chainparams, CNode* pfrom, const CBlock* pblock, bool fForceProcessing, const CDiskBlockPos* dbp) |
|
|
|
|
{ |
|
|
|
|
{ |
|
|
|
|