|
|
@ -107,11 +107,6 @@ map<uint256, COrphanTx> mapOrphanTransactions GUARDED_BY(cs_main); |
|
|
|
map<COutPoint, set<map<uint256, COrphanTx>::iterator, IteratorComparator>> mapOrphanTransactionsByPrev 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); |
|
|
|
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); |
|
|
|
static void CheckBlockIndex(const Consensus::Params& consensusParams); |
|
|
|
|
|
|
|
|
|
|
|
/** Constant stuff for coinbase transactions we create: */ |
|
|
|
/** Constant stuff for coinbase transactions we create: */ |
|
|
@ -2372,15 +2367,13 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin |
|
|
|
|
|
|
|
|
|
|
|
unsigned int flags = fStrictPayToScriptHash ? SCRIPT_VERIFY_P2SH : SCRIPT_VERIFY_NONE; |
|
|
|
unsigned int flags = fStrictPayToScriptHash ? SCRIPT_VERIFY_P2SH : SCRIPT_VERIFY_NONE; |
|
|
|
|
|
|
|
|
|
|
|
// Start enforcing the DERSIG (BIP66) rules, for block.nVersion=3 blocks,
|
|
|
|
// Start enforcing the DERSIG (BIP66) rule
|
|
|
|
// when 75% of the network has upgraded:
|
|
|
|
if (pindex->nHeight >= chainparams.GetConsensus().BIP66Height) { |
|
|
|
if (block.nVersion >= 3 && IsSuperMajority(3, pindex->pprev, chainparams.GetConsensus().nMajorityEnforceBlockUpgrade, chainparams.GetConsensus())) { |
|
|
|
|
|
|
|
flags |= SCRIPT_VERIFY_DERSIG; |
|
|
|
flags |= SCRIPT_VERIFY_DERSIG; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Start enforcing CHECKLOCKTIMEVERIFY, (BIP65) for block.nVersion=4
|
|
|
|
// Start enforcing CHECKLOCKTIMEVERIFY (BIP65) rule
|
|
|
|
// blocks, when 75% of the network has upgraded:
|
|
|
|
if (pindex->nHeight >= chainparams.GetConsensus().BIP65Height) { |
|
|
|
if (block.nVersion >= 4 && IsSuperMajority(4, pindex->pprev, chainparams.GetConsensus().nMajorityEnforceBlockUpgrade, chainparams.GetConsensus())) { |
|
|
|
|
|
|
|
flags |= SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY; |
|
|
|
flags |= SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -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) |
|
|
|
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
|
|
|
|
// Check proof of work
|
|
|
|
if (block.nBits != GetNextWorkRequired(pindexPrev, &block, consensusParams)) |
|
|
|
if (block.nBits != GetNextWorkRequired(pindexPrev, &block, consensusParams)) |
|
|
|
return state.DoS(100, false, REJECT_INVALID, "bad-diffbits", false, "incorrect proof of work"); |
|
|
|
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 |
|
|
|
return state.Invalid(false, REJECT_INVALID, "time-too-new", "block timestamp too far in the future"); |
|
|
|
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:
|
|
|
|
// 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
|
|
|
|
// check for version 2, 3 and 4 upgrades
|
|
|
|
if (block.nVersion < version && IsSuperMajority(version, pindexPrev, consensusParams.nMajorityRejectBlockOutdated, consensusParams)) |
|
|
|
if((block.nVersion < 2 && nHeight >= consensusParams.BIP34Height) || |
|
|
|
return state.Invalid(false, REJECT_OBSOLETE, strprintf("bad-version(0x%08x)", version - 1), |
|
|
|
(block.nVersion < 3 && nHeight >= consensusParams.BIP66Height) || |
|
|
|
strprintf("rejected nVersion=0x%08x block", version - 1)); |
|
|
|
(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; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
@ -3547,9 +3543,8 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, const CB |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Enforce block.nVersion=2 rule that the coinbase starts with serialized block height
|
|
|
|
// Enforce 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 (nHeight >= consensusParams.BIP34Height) |
|
|
|
if (block.nVersion >= 2 && IsSuperMajority(2, pindexPrev, consensusParams.nMajorityEnforceBlockUpgrade, consensusParams)) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
CScript expect = CScript() << nHeight; |
|
|
|
CScript expect = CScript() << nHeight; |
|
|
|
if (block.vtx[0].vin[0].scriptSig.size() < expect.size() || |
|
|
|
if (block.vtx[0].vin[0].scriptSig.size() < expect.size() || |
|
|
@ -3722,19 +3717,6 @@ static bool AcceptBlock(const CBlock& block, CValidationState& state, const CCha |
|
|
|
return true; |
|
|
|
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) |
|
|
|
bool ProcessNewBlock(CValidationState& state, const CChainParams& chainparams, CNode* pfrom, const CBlock* pblock, bool fForceProcessing, const CDiskBlockPos* dbp) |
|
|
|
{ |
|
|
|
{ |
|
|
|
{ |
|
|
|
{ |
|
|
|