Browse Source

Softfork status report in RPC

0.13
Pieter Wuille 9 years ago
parent
commit
d23f6c6a0d
  1. 6
      src/main.cpp
  2. 4
      src/main.h
  3. 22
      src/rpc/blockchain.cpp

6
src/main.cpp

@ -5859,7 +5859,11 @@ bool SendMessages(CNode* pto)
return strprintf("CBlockFileInfo(blocks=%u, size=%u, heights=%u...%u, time=%s...%s)", nBlocks, nSize, nHeightFirst, nHeightLast, DateTimeStrFormat("%Y-%m-%d", nTimeFirst), DateTimeStrFormat("%Y-%m-%d", nTimeLast)); return strprintf("CBlockFileInfo(blocks=%u, size=%u, heights=%u...%u, time=%s...%s)", nBlocks, nSize, nHeightFirst, nHeightLast, DateTimeStrFormat("%Y-%m-%d", nTimeFirst), DateTimeStrFormat("%Y-%m-%d", nTimeLast));
} }
ThresholdState VersionBitsTipState(const Consensus::Params& params, Consensus::DeploymentPos pos)
{
LOCK(cs_main);
return VersionBitsState(chainActive.Tip(), params, pos, versionbitscache);
}
class CMainCleanup class CMainCleanup
{ {

4
src/main.h

@ -16,6 +16,7 @@
#include "net.h" #include "net.h"
#include "script/script_error.h" #include "script/script_error.h"
#include "sync.h" #include "sync.h"
#include "versionbits.h"
#include <algorithm> #include <algorithm>
#include <exception> #include <exception>
@ -289,6 +290,9 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
/** Convert CValidationState to a human-readable message for logging */ /** Convert CValidationState to a human-readable message for logging */
std::string FormatStateMessage(const CValidationState &state); std::string FormatStateMessage(const CValidationState &state);
/** Get the BIP9 state for a given deployment at the current tip. */
ThresholdState VersionBitsTipState(const Consensus::Params& params, Consensus::DeploymentPos pos);
struct CNodeStateStats { struct CNodeStateStats {
int nMisbehavior; int nMisbehavior;
int nSyncHeight; int nSyncHeight;

22
src/rpc/blockchain.cpp

@ -604,6 +604,20 @@ static UniValue SoftForkDesc(const std::string &name, int version, CBlockIndex*
return rv; return rv;
} }
static UniValue BIP9SoftForkDesc(const std::string& name, const Consensus::Params& consensusParams, Consensus::DeploymentPos id)
{
UniValue rv(UniValue::VOBJ);
rv.push_back(Pair("id", name));
switch (VersionBitsTipState(consensusParams, id)) {
case THRESHOLD_DEFINED: rv.push_back(Pair("status", "defined")); break;
case THRESHOLD_STARTED: rv.push_back(Pair("status", "started")); break;
case THRESHOLD_LOCKED_IN: rv.push_back(Pair("status", "locked_in")); break;
case THRESHOLD_ACTIVE: rv.push_back(Pair("status", "active")); break;
case THRESHOLD_FAILED: rv.push_back(Pair("status", "failed")); break;
}
return rv;
}
UniValue getblockchaininfo(const UniValue& params, bool fHelp) UniValue getblockchaininfo(const UniValue& params, bool fHelp)
{ {
if (fHelp || params.size() != 0) if (fHelp || params.size() != 0)
@ -634,6 +648,12 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp)
" },\n" " },\n"
" \"reject\": { ... } (object) progress toward rejecting pre-softfork blocks (same fields as \"enforce\")\n" " \"reject\": { ... } (object) progress toward rejecting pre-softfork blocks (same fields as \"enforce\")\n"
" }, ...\n" " }, ...\n"
" ],\n"
" \"bip9_softforks\": [ (array) status of BIP9 softforks in progress\n"
" {\n"
" \"id\": \"xxxx\", (string) name of the softfork\n"
" \"status\": \"xxxx\", (string) one of \"defined\", \"started\", \"lockedin\", \"active\", \"failed\"\n"
" }\n"
" ]\n" " ]\n"
"}\n" "}\n"
"\nExamples:\n" "\nExamples:\n"
@ -657,10 +677,12 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp)
const Consensus::Params& consensusParams = Params().GetConsensus(); const Consensus::Params& consensusParams = Params().GetConsensus();
CBlockIndex* tip = chainActive.Tip(); CBlockIndex* tip = chainActive.Tip();
UniValue softforks(UniValue::VARR); UniValue softforks(UniValue::VARR);
UniValue bip9_softforks(UniValue::VARR);
softforks.push_back(SoftForkDesc("bip34", 2, tip, consensusParams)); softforks.push_back(SoftForkDesc("bip34", 2, tip, consensusParams));
softforks.push_back(SoftForkDesc("bip66", 3, tip, consensusParams)); softforks.push_back(SoftForkDesc("bip66", 3, tip, consensusParams));
softforks.push_back(SoftForkDesc("bip65", 4, tip, consensusParams)); softforks.push_back(SoftForkDesc("bip65", 4, tip, consensusParams));
obj.push_back(Pair("softforks", softforks)); obj.push_back(Pair("softforks", softforks));
obj.push_back(Pair("bip9_softforks", bip9_softforks));
if (fPruneMode) if (fPruneMode)
{ {

Loading…
Cancel
Save