-
Notifications
You must be signed in to change notification settings - Fork 36.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consensus: Remove ISM #8391
Consensus: Remove ISM #8391
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,13 +39,13 @@ struct BIP9Deployment { | |
struct Params { | ||
uint256 hashGenesisBlock; | ||
int nSubsidyHalvingInterval; | ||
/** Used to check majorities for block version upgrade */ | ||
int nMajorityEnforceBlockUpgrade; | ||
int nMajorityRejectBlockOutdated; | ||
int nMajorityWindow; | ||
/** Block height and hash at which BIP34 becomes active */ | ||
int BIP34Height; | ||
uint256 BIP34Hash; | ||
/** Block height at which BIP65 becomes active */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can make an array with an enum, like with vDeployments. Say, vPastDeployments, vOldDeployments, vBuriedDeployments, or something of the sort. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer keeping change of logic and refactoring done in different PR. I want this PR to be easy to review, so I'm using the previous way of doing with BIP34Height. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, you can leave BIP34 as it is and put the new things in the array if you think that is less disruptive, no? |
||
int BIP65Height; | ||
/** Block height at which BIP66 becomes active */ | ||
int BIP66Height; | ||
/** | ||
* Minimum blocks including miner confirmation of the total of 2016 blocks in a retargetting period, | ||
* (nPowTargetTimespan / nPowTargetSpacing) which is also used for BIP9 deployments. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
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 | |
|
||
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Any reason not to leave version check in? The fewer differences the better, imo. (clearly this isn't a HF, just asking) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, will later make refactoring for libconsensus easier because this does not depend on Block anymore. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The IsSuperMajority call is slow.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sipa? Hm? I was just asking about nVersion check. That said, future refactoring purposes is good enough for me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, as @NicolasDorier points out the block.nVersion check can be safely removed from here because blocks with invalid versions will be rejected in ContextualCheckBlockHeader. |
||
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 | |
|
||
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 | |
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; | ||
} | ||
|
@@ -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 | ||
// 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 | |
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) | ||
{ | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it not possible to check the hash for main and test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where would that be useful? The hash is only used as an exception to BIP30 rule at https://github.com/bitcoin/bitcoin/blob/master/src/main.cpp#L2358
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, in fact, what that's doing is that if we're past BIP34Height but at BIP34Height we don't have the hardcoded block, then keep checking bip30 as if bip34 hadn't been activated.
But now in https://github.com/bitcoin/bitcoin/pull/8391/files#diff-7ec3c68a81efff79b6ca22ac1f1eabbaL3550 if we have a reorg below BIP34Height, BIP34 will be activated after BIP34Height regardless of the original activation being different, thus the optimization of not checking BIP30 if BIP34 is activated could be used as well. So BIP34Hash can go after this change, I believe.
If we have a reorg to BIP34Height things are terribly broken anyway.