@@ -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
@@ -2644,25 +2643,22 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta
2644
2643
}
2645
2644
2646
2645
// Reject block.nVersion=1 blocks when 95% (75% on testnet) of the network has upgraded:
2647
- if (block.nVersion < 2 && IsSuperMajority (2 , pindexPrev, consensusParams.nMajorityRejectBlockOutdated ))
2648
- {
2646
+ if (block.nVersion < 2 && IsSuperMajority (2 , pindexPrev, consensusParams.nMajorityRejectBlockOutdated , consensusParams))
2649
2647
return state.Invalid (error (" %s: rejected nVersion=1 block" , __func__),
2650
2648
REJECT_OBSOLETE, " bad-version" );
2651
- }
2652
2649
2653
2650
// Reject block.nVersion=2 blocks when 95% (75% on testnet) of the network has upgraded:
2654
- if (block.nVersion < 3 && IsSuperMajority (3 , pindexPrev, consensusParams.nMajorityRejectBlockOutdated ))
2655
- {
2651
+ if (block.nVersion < 3 && IsSuperMajority (3 , pindexPrev, consensusParams.nMajorityRejectBlockOutdated , consensusParams))
2656
2652
return state.Invalid (error (" %s : rejected nVersion=2 block" , __func__),
2657
2653
REJECT_OBSOLETE, " bad-version" );
2658
- }
2659
2654
2660
2655
return true ;
2661
2656
}
2662
2657
2663
2658
bool ContextualCheckBlock (const CBlock& block, CValidationState& state, CBlockIndex * const pindexPrev)
2664
2659
{
2665
2660
const int nHeight = pindexPrev == NULL ? 0 : pindexPrev->nHeight + 1 ;
2661
+ const Consensus::Params& consensusParams = Params ().GetConsensus ();
2666
2662
2667
2663
// Check that all transactions are finalized
2668
2664
BOOST_FOREACH (const CTransaction& tx, block.vtx )
@@ -2672,7 +2668,7 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn
2672
2668
2673
2669
// Enforce block.nVersion=2 rule that the coinbase starts with serialized block height
2674
2670
// if 750 of the last 1,000 blocks are version 2 or greater (51/100 if testnet):
2675
- if (block.nVersion >= 2 && IsSuperMajority (2 , pindexPrev, Params (). EnforceBlockUpgradeMajority () ))
2671
+ if (block.nVersion >= 2 && IsSuperMajority (2 , pindexPrev, consensusParams. nMajorityEnforceBlockUpgrade , consensusParams ))
2676
2672
{
2677
2673
CScript expect = CScript () << nHeight;
2678
2674
if (block.vtx [0 ].vin [0 ].scriptSig .size () < expect.size () ||
@@ -2779,11 +2775,10 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex,
2779
2775
return true ;
2780
2776
}
2781
2777
2782
- static bool IsSuperMajority (int minVersion, const CBlockIndex* pstart, unsigned int nRequired)
2778
+ static bool IsSuperMajority (int minVersion, const CBlockIndex* pstart, unsigned nRequired, const Consensus::Params& consensusParams )
2783
2779
{
2784
- unsigned int nToCheck = Params ().ToCheckBlockUpgradeMajority ();
2785
2780
unsigned int nFound = 0 ;
2786
- for (unsigned int i = 0 ; i < nToCheck && nFound < nRequired && pstart != NULL ; i++)
2781
+ for (int i = 0 ; i < consensusParams. nMajorityWindow && nFound < nRequired && pstart != NULL ; i++)
2787
2782
{
2788
2783
if (pstart->nVersion >= minVersion)
2789
2784
++nFound;
0 commit comments