mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-05-23 12:24:42 +02:00
Add hard fork information to getblockchaininfo RPC endpoint
This commit is contained in:
@@ -124,6 +124,7 @@ struct BlockHasher
|
||||
extern CScript COINBASE_FLAGS;
|
||||
extern CCriticalSection cs_main;
|
||||
extern CTxMemPool mempool;
|
||||
extern boost::atomic<uint32_t> sizeForkTime;
|
||||
typedef boost::unordered_map<uint256, CBlockIndex*, BlockHasher> BlockMap;
|
||||
extern BlockMap mapBlockIndex;
|
||||
extern uint64_t nLastBlockTx;
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
#include "streams.h"
|
||||
#include "sync.h"
|
||||
#include "txmempool.h"
|
||||
#include "txdb.h"
|
||||
#include "timedata.h"
|
||||
#include "util.h"
|
||||
#include "utilstrencodings.h"
|
||||
|
||||
@@ -604,6 +606,46 @@ static UniValue SoftForkDesc(const std::string &name, int version, CBlockIndex*
|
||||
return rv;
|
||||
}
|
||||
|
||||
static UniValue HardForkMajorityDesc(int minVersion, CBlockIndex* pindex, int nRequired, const Consensus::Params& consensusParams)
|
||||
{
|
||||
uint32_t forkTime = sizeForkTime.load();
|
||||
bool isHardForkActive = forkTime < std::numeric_limits<uint32_t>::max();
|
||||
int nFound = 0;
|
||||
UniValue gracePeriodEnds;
|
||||
UniValue triggeredAtBlock;
|
||||
CBlockIndex* pstart = pindex;
|
||||
if (isHardForkActive) {
|
||||
// Always report blocks found as over the threshold once the fork is active
|
||||
nFound = nRequired + 1;
|
||||
gracePeriodEnds = static_cast<uint64_t>(forkTime);
|
||||
triggeredAtBlock = pblocktree->ForkBitActivated(FORK_BIT_2MB).GetHex();
|
||||
} else {
|
||||
for (int i = 0; i < consensusParams.nMajorityWindow && pstart != NULL; i++)
|
||||
{
|
||||
if (pstart->nVersion >= minVersion)
|
||||
++nFound;
|
||||
pstart = pstart->pprev;
|
||||
}
|
||||
}
|
||||
|
||||
UniValue rv(UniValue::VOBJ);
|
||||
rv.push_back(Pair("triggeredatblock", triggeredAtBlock));
|
||||
rv.push_back(Pair("earliestforktime", gracePeriodEnds));
|
||||
rv.push_back(Pair("found", nFound));
|
||||
rv.push_back(Pair("required", nRequired));
|
||||
rv.push_back(Pair("window", consensusParams.nMajorityWindow));
|
||||
return rv;
|
||||
}
|
||||
|
||||
static UniValue HardForkDesc(const std::string &name, int version, CBlockIndex* pindex, const Consensus::Params& consensusParams)
|
||||
{
|
||||
UniValue rv(UniValue::VOBJ);
|
||||
rv.push_back(Pair("id", name));
|
||||
rv.push_back(Pair("version", version));
|
||||
rv.push_back(Pair("status", HardForkMajorityDesc(version, pindex, consensusParams.nMajorityEnforceBlockUpgrade, consensusParams)));
|
||||
return rv;
|
||||
}
|
||||
|
||||
UniValue getblockchaininfo(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 0)
|
||||
@@ -662,6 +704,10 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp)
|
||||
softforks.push_back(SoftForkDesc("bip65", 4, tip, consensusParams));
|
||||
obj.push_back(Pair("softforks", softforks));
|
||||
|
||||
UniValue hardforks(UniValue::VARR);
|
||||
hardforks.push_back(HardForkDesc("bip109", 0x01000000, tip, consensusParams));
|
||||
obj.push_back(Pair("hardforks", hardforks));
|
||||
|
||||
if (fPruneMode)
|
||||
{
|
||||
CBlockIndex *block = chainActive.Tip();
|
||||
|
||||
Reference in New Issue
Block a user