Skip to content

Commit 9dcd524

Browse files
committed
Make IsSuperMajority a standalone function
1 parent 3bb29a3 commit 9dcd524

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

src/chain.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,6 @@ class CBlockIndex
236236
return pbegin[(pend - pbegin)/2];
237237
}
238238

239-
/**
240-
* Returns true if there are nRequired or more blocks of minVersion or above
241-
* in the last Params().ToCheckBlockUpgradeMajority() blocks, starting at pstart
242-
* and going backwards.
243-
*/
244-
static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart,
245-
unsigned int nRequired);
246-
247239
std::string ToString() const
248240
{
249241
return strprintf("CBlockIndex(pprev=%p, nHeight=%d, merkle=%s, hashBlock=%s)",

src/main.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ map<uint256, COrphanTx> mapOrphanTransactions;
6767
map<uint256, set<uint256> > mapOrphanTransactionsByPrev;
6868
void EraseOrphansFor(NodeId peer);
6969

70+
/**
71+
* Returns true if there are nRequired or more blocks of minVersion or above
72+
* in the last Params().ToCheckBlockUpgradeMajority() blocks, starting at pstart
73+
* and going backwards.
74+
*/
75+
static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned int nRequired);
76+
7077
/** Constant stuff for coinbase transactions we create: */
7178
CScript COINBASE_FLAGS;
7279

@@ -2479,8 +2486,7 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta
24792486
return state.DoS(100, error("%s : forked chain older than last checkpoint (height %d)", __func__, nHeight));
24802487

24812488
// Reject block.nVersion=1 blocks when 95% (75% on testnet) of the network has upgraded:
2482-
if (block.nVersion < 2 &&
2483-
CBlockIndex::IsSuperMajority(2, pindexPrev, Params().RejectBlockOutdatedMajority()))
2489+
if (block.nVersion < 2 && IsSuperMajority(2, pindexPrev, Params().RejectBlockOutdatedMajority()))
24842490
{
24852491
return state.Invalid(error("%s : rejected nVersion=1 block", __func__),
24862492
REJECT_OBSOLETE, "bad-version");
@@ -2501,8 +2507,7 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn
25012507

25022508
// Enforce block.nVersion=2 rule that the coinbase starts with serialized block height
25032509
// if 750 of the last 1,000 blocks are version 2 or greater (51/100 if testnet):
2504-
if (block.nVersion >= 2 &&
2505-
CBlockIndex::IsSuperMajority(2, pindexPrev, Params().EnforceBlockUpgradeMajority()))
2510+
if (block.nVersion >= 2 && IsSuperMajority(2, pindexPrev, Params().EnforceBlockUpgradeMajority()))
25062511
{
25072512
CScript expect = CScript() << nHeight;
25082513
if (block.vtx[0].vin[0].scriptSig.size() < expect.size() ||
@@ -2600,7 +2605,7 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex,
26002605
return true;
26012606
}
26022607

2603-
bool CBlockIndex::IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned int nRequired)
2608+
static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned int nRequired)
26042609
{
26052610
unsigned int nToCheck = Params().ToCheckBlockUpgradeMajority();
26062611
unsigned int nFound = 0;

0 commit comments

Comments
 (0)