Skip to content

Commit f0043c2

Browse files
committed
Merge pull request #5968
51aa249 Chainparams: Refactor: Decouple IsSuperMajority from Params() (Jorge Timón)
2 parents 6fb90d8 + 51aa249 commit f0043c2

File tree

2 files changed

+9
-17
lines changed

2 files changed

+9
-17
lines changed

src/chainparams.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ class CChainParams
5050
const std::vector<unsigned char>& AlertKey() const { return vAlertPubKey; }
5151
int GetDefaultPort() const { return nDefaultPort; }
5252
int SubsidyHalvingInterval() const { return consensus.nSubsidyHalvingInterval; }
53-
int EnforceBlockUpgradeMajority() const { return consensus.nMajorityEnforceBlockUpgrade; }
54-
int RejectBlockOutdatedMajority() const { return consensus.nMajorityRejectBlockOutdated; }
55-
int ToCheckBlockUpgradeMajority() const { return consensus.nMajorityWindow; }
5653

5754
/** Used if GenerateBitcoins is called with a negative number of threads */
5855
int DefaultMinerThreads() const { return nMinerThreads; }

src/main.cpp

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,9 @@ void EraseOrphansFor(NodeId peer);
7575

7676
/**
7777
* Returns true if there are nRequired or more blocks of minVersion or above
78-
* in the last Params().ToCheckBlockUpgradeMajority() blocks, starting at pstart
79-
* and going backwards.
78+
* in the last Consensus::Params::nMajorityWindow blocks, starting at pstart and going backwards.
8079
*/
81-
static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned int nRequired);
80+
static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned nRequired, const Consensus::Params& consensusParams);
8281
static void CheckBlockIndex();
8382

8483
/** Constant stuff for coinbase transactions we create: */
@@ -1747,7 +1746,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
17471746
unsigned int flags = fStrictPayToScriptHash ? SCRIPT_VERIFY_P2SH : SCRIPT_VERIFY_NONE;
17481747

17491748
// Start enforcing the DERSIG (BIP66) rules, for block.nVersion=3 blocks, when 75% of the network has upgraded:
1750-
if (block.nVersion >= 3 && IsSuperMajority(3, pindex->pprev, Params().EnforceBlockUpgradeMajority())) {
1749+
if (block.nVersion >= 3 && IsSuperMajority(3, pindex->pprev, chainparams.GetConsensus().nMajorityEnforceBlockUpgrade, chainparams.GetConsensus())) {
17511750
flags |= SCRIPT_VERIFY_DERSIG;
17521751
}
17531752

@@ -2672,25 +2671,22 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta
26722671
}
26732672

26742673
// Reject block.nVersion=1 blocks when 95% (75% on testnet) of the network has upgraded:
2675-
if (block.nVersion < 2 && IsSuperMajority(2, pindexPrev, consensusParams.nMajorityRejectBlockOutdated))
2676-
{
2674+
if (block.nVersion < 2 && IsSuperMajority(2, pindexPrev, consensusParams.nMajorityRejectBlockOutdated, consensusParams))
26772675
return state.Invalid(error("%s: rejected nVersion=1 block", __func__),
26782676
REJECT_OBSOLETE, "bad-version");
2679-
}
26802677

26812678
// Reject block.nVersion=2 blocks when 95% (75% on testnet) of the network has upgraded:
2682-
if (block.nVersion < 3 && IsSuperMajority(3, pindexPrev, consensusParams.nMajorityRejectBlockOutdated))
2683-
{
2679+
if (block.nVersion < 3 && IsSuperMajority(3, pindexPrev, consensusParams.nMajorityRejectBlockOutdated, consensusParams))
26842680
return state.Invalid(error("%s : rejected nVersion=2 block", __func__),
26852681
REJECT_OBSOLETE, "bad-version");
2686-
}
26872682

26882683
return true;
26892684
}
26902685

26912686
bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIndex * const pindexPrev)
26922687
{
26932688
const int nHeight = pindexPrev == NULL ? 0 : pindexPrev->nHeight + 1;
2689+
const Consensus::Params& consensusParams = Params().GetConsensus();
26942690

26952691
// Check that all transactions are finalized
26962692
BOOST_FOREACH(const CTransaction& tx, block.vtx)
@@ -2700,7 +2696,7 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn
27002696

27012697
// Enforce block.nVersion=2 rule that the coinbase starts with serialized block height
27022698
// if 750 of the last 1,000 blocks are version 2 or greater (51/100 if testnet):
2703-
if (block.nVersion >= 2 && IsSuperMajority(2, pindexPrev, Params().EnforceBlockUpgradeMajority()))
2699+
if (block.nVersion >= 2 && IsSuperMajority(2, pindexPrev, consensusParams.nMajorityEnforceBlockUpgrade, consensusParams))
27042700
{
27052701
CScript expect = CScript() << nHeight;
27062702
if (block.vtx[0].vin[0].scriptSig.size() < expect.size() ||
@@ -2807,11 +2803,10 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex,
28072803
return true;
28082804
}
28092805

2810-
static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned int nRequired)
2806+
static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned nRequired, const Consensus::Params& consensusParams)
28112807
{
2812-
unsigned int nToCheck = Params().ToCheckBlockUpgradeMajority();
28132808
unsigned int nFound = 0;
2814-
for (unsigned int i = 0; i < nToCheck && nFound < nRequired && pstart != NULL; i++)
2809+
for (int i = 0; i < consensusParams.nMajorityWindow && nFound < nRequired && pstart != NULL; i++)
28152810
{
28162811
if (pstart->nVersion >= minVersion)
28172812
++nFound;

0 commit comments

Comments
 (0)