Added verbose BIP9 details
This commit is contained in:
parent
5a8b402c59
commit
b1a973ed76
|
@ -4136,6 +4136,12 @@ ThresholdState VersionBitsTipState(const Consensus::Params& params, Consensus::D
|
||||||
return VersionBitsState(chainActive.Tip(), params, pos, versionbitscache);
|
return VersionBitsState(chainActive.Tip(), params, pos, versionbitscache);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BIP9Stats VersionBitsTipStatistics(const Consensus::Params& params, Consensus::DeploymentPos pos)
|
||||||
|
{
|
||||||
|
LOCK(cs_main);
|
||||||
|
return VersionBitsStatistics(chainActive.Tip(), params, pos);
|
||||||
|
}
|
||||||
|
|
||||||
int VersionBitsTipStateSinceHeight(const Consensus::Params& params, Consensus::DeploymentPos pos)
|
int VersionBitsTipStateSinceHeight(const Consensus::Params& params, Consensus::DeploymentPos pos)
|
||||||
{
|
{
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
|
|
|
@ -258,6 +258,9 @@ ThresholdState VersionBitsTipState(const Consensus::Params& params, Consensus::D
|
||||||
/** Get the block height at which the BIP9 deployment switched into the state for the block building on the current tip. */
|
/** Get the block height at which the BIP9 deployment switched into the state for the block building on the current tip. */
|
||||||
int VersionBitsTipStateSinceHeight(const Consensus::Params& params, Consensus::DeploymentPos pos);
|
int VersionBitsTipStateSinceHeight(const Consensus::Params& params, Consensus::DeploymentPos pos);
|
||||||
|
|
||||||
|
/** Get the numerical statistics for the BIP9 state for a given deployment at the current tip. */
|
||||||
|
BIP9Stats VersionBitsTipStatistics(const Consensus::Params& params, Consensus::DeploymentPos pos);
|
||||||
|
|
||||||
struct CNodeStateStats {
|
struct CNodeStateStats {
|
||||||
int nMisbehavior;
|
int nMisbehavior;
|
||||||
int nSyncHeight;
|
int nSyncHeight;
|
||||||
|
|
|
@ -651,6 +651,18 @@ static UniValue BIP9SoftForkDesc(const Consensus::Params& consensusParams, Conse
|
||||||
}
|
}
|
||||||
rv.push_back(Pair("startTime", consensusParams.vDeployments[id].nStartTime));
|
rv.push_back(Pair("startTime", consensusParams.vDeployments[id].nStartTime));
|
||||||
rv.push_back(Pair("timeout", consensusParams.vDeployments[id].nTimeout));
|
rv.push_back(Pair("timeout", consensusParams.vDeployments[id].nTimeout));
|
||||||
|
rv.push_back(Pair("since", VersionBitsTipStateSinceHeight(consensusParams, id)));
|
||||||
|
if (THRESHOLD_STARTED == thresholdState)
|
||||||
|
{
|
||||||
|
UniValue statsUV(UniValue::VOBJ);
|
||||||
|
BIP9Stats statsStruct = VersionBitsTipStatistics(consensusParams, id);
|
||||||
|
statsUV.push_back(Pair("period", statsStruct.period));
|
||||||
|
statsUV.push_back(Pair("threshold", statsStruct.threshold));
|
||||||
|
statsUV.push_back(Pair("elapsed", statsStruct.elapsed));
|
||||||
|
statsUV.push_back(Pair("count", statsStruct.count));
|
||||||
|
statsUV.push_back(Pair("possible", statsStruct.possible));
|
||||||
|
rv.push_back(Pair("statistics", statsUV));
|
||||||
|
}
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -690,6 +702,13 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp)
|
||||||
" \"bit\": xx, (numeric) the bit, 0-28, in the block version field used to signal this soft fork\n"
|
" \"bit\": xx, (numeric) the bit, 0-28, in the block version field used to signal this soft fork\n"
|
||||||
" \"startTime\": xx, (numeric) the minimum median time past of a block at which the bit gains its meaning\n"
|
" \"startTime\": xx, (numeric) the minimum median time past of a block at which the bit gains its meaning\n"
|
||||||
" \"timeout\": xx (numeric) the median time past of a block at which the deployment is considered failed if not yet locked in\n"
|
" \"timeout\": xx (numeric) the median time past of a block at which the deployment is considered failed if not yet locked in\n"
|
||||||
|
" \"since\": xx, (numeric) height of the first block to which the status applies\n"
|
||||||
|
" \"statistics\": { (object) numeric statistics about BIP9 signalling for a softfork (only for \"started\" status)\n"
|
||||||
|
" \"period\": xx, (numeric) the length in blocks of the BIP9 signalling period \n"
|
||||||
|
" \"threshold\": xx, (numeric) the number of blocks with the version bit set required to activate the feature \n"
|
||||||
|
" \"elapsed\": xx, (numeric) the number of blocks elapsed since the beginning of the current period \n"
|
||||||
|
" \"count\": xx, (numeric) the number of blocks with the version bit set in the current period \n"
|
||||||
|
" \"possible\": xx (boolean) returns false if there are not enough blocks left in this period to pass activation threshold \n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"\nExamples:\n"
|
"\nExamples:\n"
|
||||||
+ HelpExampleCli("getblockchaininfo", "")
|
+ HelpExampleCli("getblockchaininfo", "")
|
||||||
|
|
|
@ -13,6 +13,36 @@ const struct BIP9DeploymentInfo VersionBitsDeploymentInfo[Consensus::MAX_VERSION
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// return the numerical statistics of blocks signalling the specified BIP9 condition in this current period
|
||||||
|
BIP9Stats AbstractThresholdConditionChecker::GetStateStatisticsFor(const CBlockIndex* pindex, const Consensus::Params& params) const
|
||||||
|
{
|
||||||
|
BIP9Stats stats;
|
||||||
|
|
||||||
|
stats.period = Period(params);
|
||||||
|
stats.threshold = Threshold(params);
|
||||||
|
|
||||||
|
if (pindex == NULL)
|
||||||
|
return stats;
|
||||||
|
|
||||||
|
// Find beginning of period
|
||||||
|
const CBlockIndex* pindexEndOfPrevPeriod = pindex->GetAncestor(pindex->nHeight - ((pindex->nHeight + 1) % stats.period));
|
||||||
|
stats.elapsed = pindex->nHeight - pindexEndOfPrevPeriod->nHeight;
|
||||||
|
|
||||||
|
// Count from current block to beginning of period
|
||||||
|
int count = 0;
|
||||||
|
const CBlockIndex* currentIndex = pindex;
|
||||||
|
while (pindexEndOfPrevPeriod->nHeight != currentIndex->nHeight){
|
||||||
|
if (Condition(currentIndex, params))
|
||||||
|
count++;
|
||||||
|
currentIndex = currentIndex->pprev;
|
||||||
|
}
|
||||||
|
|
||||||
|
stats.count = count;
|
||||||
|
stats.possible = (stats.period - stats.threshold ) >= (stats.elapsed - count);
|
||||||
|
|
||||||
|
return stats;
|
||||||
|
}
|
||||||
|
|
||||||
ThresholdState AbstractThresholdConditionChecker::GetStateFor(const CBlockIndex* pindexPrev, const Consensus::Params& params, ThresholdConditionCache& cache) const
|
ThresholdState AbstractThresholdConditionChecker::GetStateFor(const CBlockIndex* pindexPrev, const Consensus::Params& params, ThresholdConditionCache& cache) const
|
||||||
{
|
{
|
||||||
int nPeriod = Period(params);
|
int nPeriod = Period(params);
|
||||||
|
@ -159,6 +189,12 @@ ThresholdState VersionBitsState(const CBlockIndex* pindexPrev, const Consensus::
|
||||||
return VersionBitsConditionChecker(pos).GetStateFor(pindexPrev, params, cache.caches[pos]);
|
return VersionBitsConditionChecker(pos).GetStateFor(pindexPrev, params, cache.caches[pos]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BIP9Stats VersionBitsStatistics(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos)
|
||||||
|
{
|
||||||
|
return VersionBitsConditionChecker(pos).GetStateStatisticsFor(pindexPrev, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int VersionBitsStateSinceHeight(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos, VersionBitsCache& cache)
|
int VersionBitsStateSinceHeight(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos, VersionBitsCache& cache)
|
||||||
{
|
{
|
||||||
return VersionBitsConditionChecker(pos).GetStateSinceHeightFor(pindexPrev, params, cache.caches[pos]);
|
return VersionBitsConditionChecker(pos).GetStateSinceHeightFor(pindexPrev, params, cache.caches[pos]);
|
||||||
|
|
|
@ -37,6 +37,14 @@ struct BIP9DeploymentInfo {
|
||||||
bool gbt_force;
|
bool gbt_force;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct BIP9Stats {
|
||||||
|
int period;
|
||||||
|
int threshold;
|
||||||
|
int elapsed;
|
||||||
|
int count;
|
||||||
|
bool possible;
|
||||||
|
};
|
||||||
|
|
||||||
extern const struct BIP9DeploymentInfo VersionBitsDeploymentInfo[];
|
extern const struct BIP9DeploymentInfo VersionBitsDeploymentInfo[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -51,6 +59,7 @@ protected:
|
||||||
virtual int Threshold(const Consensus::Params& params) const =0;
|
virtual int Threshold(const Consensus::Params& params) const =0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
BIP9Stats GetStateStatisticsFor(const CBlockIndex* pindex, const Consensus::Params& params) const;
|
||||||
// Note that the functions below take a pindexPrev as input: they compute information for block B based on its parent.
|
// Note that the functions below take a pindexPrev as input: they compute information for block B based on its parent.
|
||||||
ThresholdState GetStateFor(const CBlockIndex* pindexPrev, const Consensus::Params& params, ThresholdConditionCache& cache) const;
|
ThresholdState GetStateFor(const CBlockIndex* pindexPrev, const Consensus::Params& params, ThresholdConditionCache& cache) const;
|
||||||
int GetStateSinceHeightFor(const CBlockIndex* pindexPrev, const Consensus::Params& params, ThresholdConditionCache& cache) const;
|
int GetStateSinceHeightFor(const CBlockIndex* pindexPrev, const Consensus::Params& params, ThresholdConditionCache& cache) const;
|
||||||
|
@ -64,6 +73,7 @@ struct VersionBitsCache
|
||||||
};
|
};
|
||||||
|
|
||||||
ThresholdState VersionBitsState(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos, VersionBitsCache& cache);
|
ThresholdState VersionBitsState(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos, VersionBitsCache& cache);
|
||||||
|
BIP9Stats VersionBitsStatistics(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos);
|
||||||
int VersionBitsStateSinceHeight(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos, VersionBitsCache& cache);
|
int VersionBitsStateSinceHeight(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos, VersionBitsCache& cache);
|
||||||
uint32_t VersionBitsMask(const Consensus::Params& params, Consensus::DeploymentPos pos);
|
uint32_t VersionBitsMask(const Consensus::Params& params, Consensus::DeploymentPos pos);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue