@@ -75,10 +75,9 @@ void EraseOrphansFor(NodeId peer);
75
75
76
76
/* *
77
77
* 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.
80
79
*/
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 );
82
81
static void CheckBlockIndex ();
83
82
84
83
/* * Constant stuff for coinbase transactions we create: */
@@ -1747,7 +1746,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
1747
1746
unsigned int flags = fStrictPayToScriptHash ? SCRIPT_VERIFY_P2SH : SCRIPT_VERIFY_NONE;
1748
1747
1749
1748
// 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 ())) {
1751
1750
flags |= SCRIPT_VERIFY_DERSIG;
1752
1751
}
1753
1752
@@ -2672,25 +2671,22 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta
2672
2671
}
2673
2672
2674
2673
// 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))
2677
2675
return state.Invalid (error (" %s: rejected nVersion=1 block" , __func__),
2678
2676
REJECT_OBSOLETE, " bad-version" );
2679
- }
2680
2677
2681
2678
// 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))
2684
2680
return state.Invalid (error (" %s : rejected nVersion=2 block" , __func__),
2685
2681
REJECT_OBSOLETE, " bad-version" );
2686
- }
2687
2682
2688
2683
return true ;
2689
2684
}
2690
2685
2691
2686
bool ContextualCheckBlock (const CBlock& block, CValidationState& state, CBlockIndex * const pindexPrev)
2692
2687
{
2693
2688
const int nHeight = pindexPrev == NULL ? 0 : pindexPrev->nHeight + 1 ;
2689
+ const Consensus::Params& consensusParams = Params ().GetConsensus ();
2694
2690
2695
2691
// Check that all transactions are finalized
2696
2692
BOOST_FOREACH (const CTransaction& tx, block.vtx )
@@ -2700,7 +2696,7 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn
2700
2696
2701
2697
// Enforce block.nVersion=2 rule that the coinbase starts with serialized block height
2702
2698
// 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 ))
2704
2700
{
2705
2701
CScript expect = CScript () << nHeight;
2706
2702
if (block.vtx [0 ].vin [0 ].scriptSig .size () < expect.size () ||
@@ -2807,11 +2803,10 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex,
2807
2803
return true ;
2808
2804
}
2809
2805
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 )
2811
2807
{
2812
- unsigned int nToCheck = Params ().ToCheckBlockUpgradeMajority ();
2813
2808
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++)
2815
2810
{
2816
2811
if (pstart->nVersion >= minVersion)
2817
2812
++nFound;
0 commit comments