Skip to content

Commit

Permalink
[Core] Remove IsSuperMajority
Browse files Browse the repository at this point in the history
  • Loading branch information
random-zebra committed Mar 16, 2020
1 parent 9cd2f81 commit 596902f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 60 deletions.
7 changes: 0 additions & 7 deletions src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,6 @@ class CBlockIndex
CBlockIndex* GetAncestor(int height);
const CBlockIndex* GetAncestor(int height) const;

/**
* Returns true if there are nRequired or more blocks of minVersion or above
* in the last Params().consensus.nToCheckBlockUpgradeMajority blocks, starting at pstart
* and going backwards.
*/
static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned int nRequired);

// Legacy Zerocoin
int64_t GetZerocoinSupply() const;
int64_t GetZcMints(libzerocoin::CoinDenomination denom) const;
Expand Down
15 changes: 0 additions & 15 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,6 @@ class CMainParams : public CChainParams
consensus.nTime_EnforceNewSporkKey = 1566860400; //!> August 26, 2019 11:00:00 PM GMT
consensus.nTime_RejectOldSporkKey = 1569538800; //!> September 26, 2019 11:00:00 PM GMT

// majorities for block version upgrades
consensus.nEnforceBlockUpgradeMajority = 8100; // 75%
consensus.nRejectBlockOutdatedMajority = 10260; // 95%
consensus.nToCheckBlockUpgradeMajority = 10800; // Approximate expected amount of blocks in 7 days (1440*7.5)

// height-based activations
consensus.height_last_PoW = 259200;
consensus.height_last_ZC_AccumCheckpoint = 1686240;
Expand Down Expand Up @@ -294,11 +289,6 @@ class CTestNetParams : public CMainParams
consensus.nTime_EnforceNewSporkKey = 1566860400; //!> August 26, 2019 11:00:00 PM GMT
consensus.nTime_RejectOldSporkKey = 1569538800; //!> September 26, 2019 11:00:00 PM GMT

// majorities for block version upgrades
consensus.nEnforceBlockUpgradeMajority = 4320; // 75%
consensus.nRejectBlockOutdatedMajority = 5472; // 95%
consensus.nToCheckBlockUpgradeMajority = 5760; // 4 days

// height based activations
consensus.height_last_PoW = 200;
consensus.height_last_ZC_AccumCheckpoint = 1106090;
Expand Down Expand Up @@ -421,11 +411,6 @@ class CRegTestParams : public CTestNetParams
consensus.nTime_EnforceNewSporkKey = 0;
consensus.nTime_RejectOldSporkKey = 0;

// majorities for block version upgrades
consensus.nEnforceBlockUpgradeMajority = 750;
consensus.nRejectBlockOutdatedMajority = 950;
consensus.nToCheckBlockUpgradeMajority = 1000;

// height based activations
consensus.height_last_PoW = 250;
consensus.height_last_ZC_AccumCheckpoint = 310; // no checkpoints on regtest
Expand Down
5 changes: 0 additions & 5 deletions src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ struct Params {
int64_t nTime_EnforceNewSporkKey;
int64_t nTime_RejectOldSporkKey;

// majorities for block version upgrades
int nEnforceBlockUpgradeMajority;
int nRejectBlockOutdatedMajority;
int nToCheckBlockUpgradeMajority;

// height-based activations
int height_last_PoW;
int height_last_ZC_AccumCheckpoint;
Expand Down
12 changes: 0 additions & 12 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4348,18 +4348,6 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex,
return true;
}

bool CBlockIndex::IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned int nRequired)
{
const int nToCheck = Params().GetConsensus().nToCheckBlockUpgradeMajority;
unsigned int nFound = 0;
for (int i = 0; i < nToCheck && nFound < nRequired && pstart != NULL; i++) {
if (pstart->nVersion >= minVersion)
++nFound;
pstart = pstart->pprev;
}
return (nFound >= nRequired);
}

/** Turn the lowest '1' bit in the binary representation of a number into a '0'. */
int static inline InvertLowestOne(int n) { return n & (n - 1); }

Expand Down
45 changes: 24 additions & 21 deletions src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -763,22 +763,30 @@ UniValue verifychain(const UniValue& params, bool fHelp)
}

/** Implementation of IsSuperMajority with better feedback */
static UniValue SoftForkMajorityDesc(int minVersion, CBlockIndex* pindex, int nRequired)
static UniValue SoftForkMajorityDesc(int version, CBlockIndex* pindex, const Consensus::Params& consensusParams)
{
int nFound = 0;
CBlockIndex* pstart = pindex;
const int nToCheck = Params().GetConsensus().nToCheckBlockUpgradeMajority;
for (int i = 0; i < nToCheck && pstart != NULL; i++)
{
if (pstart->nVersion >= minVersion)
++nFound;
pstart = pstart->pprev;
}
UniValue rv(UniValue::VOBJ);
rv.push_back(Pair("status", nFound >= nRequired));
rv.push_back(Pair("found", nFound));
rv.push_back(Pair("required", nRequired));
rv.push_back(Pair("window", nToCheck));
bool activated = false;
switch(version) {
case 1:
case 2:
case 3:
activated = pindex->nHeight >= 1;
break;
case 4:
activated = pindex->nHeight >= consensusParams.height_start_ZC;
break;
case 5:
activated = pindex->nHeight >= consensusParams.height_start_BIP65;
break;
case 6:
activated = pindex->nHeight >= consensusParams.height_start_StakeModifierV2;
break;
case 7:
activated = pindex->nHeight >= consensusParams.height_start_TimeProtoV2;
break;
}
rv.push_back(Pair("status", activated));
return rv;
}
static UniValue SoftForkDesc(const std::string &name, int version, CBlockIndex* pindex)
Expand All @@ -787,8 +795,7 @@ static UniValue SoftForkDesc(const std::string &name, int version, CBlockIndex*
UniValue rv(UniValue::VOBJ);
rv.push_back(Pair("id", name));
rv.push_back(Pair("version", version));
rv.push_back(Pair("enforce", SoftForkMajorityDesc(version, pindex, consensus.nEnforceBlockUpgradeMajority)));
rv.push_back(Pair("reject", SoftForkMajorityDesc(version, pindex, consensus.nRejectBlockOutdatedMajority)));
rv.push_back(Pair("reject", SoftForkMajorityDesc(version, pindex, consensus)));
return rv;
}

Expand All @@ -812,13 +819,9 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp)
" {\n"
" \"id\": \"xxxx\", (string) name of softfork\n"
" \"version\": xx, (numeric) block version\n"
" \"enforce\": { (object) progress toward enforcing the softfork rules for new-version blocks\n"
" \"reject\": { (object) progress toward rejecting pre-softfork blocks\n"
" \"status\": xx, (boolean) true if threshold reached\n"
" \"found\": xx, (numeric) number of blocks with the new version found\n"
" \"required\": xx, (numeric) number of blocks required to trigger\n"
" \"window\": xx, (numeric) maximum size of examined window of recent blocks\n"
" },\n"
" \"reject\": { ... } (object) progress toward rejecting pre-softfork blocks (same fields as \"enforce\")\n"
" }, ...\n"
" ]\n"
"}\n"
Expand Down

0 comments on commit 596902f

Please sign in to comment.