Skip to content

Commit

Permalink
Show BIP65 soft-fork progress in getblockchaininfo
Browse files Browse the repository at this point in the history
Signed-off-by: observerdev <dev@obsr.org>
  • Loading branch information
Fuzzbawls authored and observerdev committed Dec 6, 2018
1 parent 280c955 commit 62c5406
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/rpc/blockchain.cpp
Expand Up @@ -579,6 +579,34 @@ UniValue verifychain(const UniValue& params, bool fHelp)
return fVerified;
}

/** Implementation of IsSuperMajority with better feedback */
static UniValue SoftForkMajorityDesc(int minVersion, CBlockIndex* pindex, int nRequired)
{
int nFound = 0;
CBlockIndex* pstart = pindex;
for (int i = 0; i < Params().ToCheckBlockUpgradeMajority() && 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", Params().ToCheckBlockUpgradeMajority()));
return rv;
}
static UniValue SoftForkDesc(const std::string &name, int version, CBlockIndex* pindex)
{
UniValue rv(UniValue::VOBJ);
rv.push_back(Pair("id", name));
rv.push_back(Pair("version", version));
rv.push_back(Pair("enforce", SoftForkMajorityDesc(version, pindex, Params().EnforceBlockUpgradeMajority())));
rv.push_back(Pair("reject", SoftForkMajorityDesc(version, pindex, Params().RejectBlockOutdatedMajority())));
return rv;
}

UniValue getblockchaininfo(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() != 0)
Expand All @@ -595,6 +623,19 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp)
" \"difficulty\": xxxxxx, (numeric) the current difficulty\n"
" \"verificationprogress\": xxxx, (numeric) estimate of verification progress [0..1]\n"
" \"chainwork\": \"xxxx\" (string) total amount of work in active chain, in hexadecimal\n"
" \"softforks\": [ (array) status of softforks in progress\n"
" {\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"
" \"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"

"\nExamples:\n" +
Expand All @@ -610,6 +651,10 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp)
obj.push_back(Pair("difficulty", (double)GetDifficulty()));
obj.push_back(Pair("verificationprogress", Checkpoints::GuessVerificationProgress(chainActive.Tip())));
obj.push_back(Pair("chainwork", chainActive.Tip()->nChainWork.GetHex()));
CBlockIndex* tip = chainActive.Tip();
UniValue softforks(UniValue::VARR);
softforks.push_back(SoftForkDesc("bip65", 5, tip));
obj.push_back(Pair("softforks", softforks));
return obj;
}

Expand Down

0 comments on commit 62c5406

Please sign in to comment.