mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-13 14:14:00 +01:00
Merge bitcoin/bitcoin#23508: Add getdeploymentinfo RPC
a380922891Release notes for getdeploymentinfo rpc (Anthony Towns)240cad09barpc: getdeploymentinfo: include signalling info (Anthony Towns)376c0c6daerpc: getdeploymentinfo: include block hash/height (Anthony Towns)a7469bcd35rpc: getdeploymentinfo: change stats to always refer to current period (Anthony Towns)7f15c1841brpc: getdeploymentinfo: allow specifying a blockhash other than tip (Anthony Towns)fd826130a0rpc: move softfork info from getblockchaininfo to getdeploymentinfo (Anthony Towns) Pull request description: The aim of this PR is to improve the ability to monitor soft fork status. It first moves the softfork section from getblockchaininfo into a new RPC named getdeploymentinfo, which is then also able to query the status of forks at an arbitrary block rather than only at the tip. In addition, bip9 status is changed to indicate the status of the given block, rather than just for the next block, and an additional field is included to indicate whether each block in the signalling period signaled. ACKs for top commit: laanwj: Code review and lightly tested ACKa380922891Sjors: tACKa380922891fjahr: tACKa380922891Tree-SHA512: 7417d733b47629f229c5128586569909250481a3e94356c52fe67a03fd42cd81745246e384b98c4115fb61587714c879e4bc3e5f5c74407d9f8f6773472a33cb
This commit is contained in:
@@ -98,29 +98,38 @@ ThresholdState AbstractThresholdConditionChecker::GetStateFor(const CBlockIndex*
|
||||
return state;
|
||||
}
|
||||
|
||||
BIP9Stats AbstractThresholdConditionChecker::GetStateStatisticsFor(const CBlockIndex* pindex, const Consensus::Params& params) const
|
||||
BIP9Stats AbstractThresholdConditionChecker::GetStateStatisticsFor(const CBlockIndex* pindex, const Consensus::Params& params, std::vector<bool>* signalling_blocks) const
|
||||
{
|
||||
BIP9Stats stats = {};
|
||||
|
||||
stats.period = Period(params);
|
||||
stats.threshold = Threshold(params);
|
||||
|
||||
if (pindex == nullptr)
|
||||
return stats;
|
||||
if (pindex == nullptr) return stats;
|
||||
|
||||
// Find beginning of period
|
||||
const CBlockIndex* pindexEndOfPrevPeriod = pindex->GetAncestor(pindex->nHeight - ((pindex->nHeight + 1) % stats.period));
|
||||
stats.elapsed = pindex->nHeight - pindexEndOfPrevPeriod->nHeight;
|
||||
int blocks_in_period = 1 + (pindex->nHeight % stats.period);
|
||||
|
||||
// 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;
|
||||
// Reset signalling_blocks
|
||||
if (signalling_blocks) {
|
||||
signalling_blocks->assign(blocks_in_period, false);
|
||||
}
|
||||
|
||||
// Count from current block to beginning of period
|
||||
int elapsed = 0;
|
||||
int count = 0;
|
||||
const CBlockIndex* currentIndex = pindex;
|
||||
do {
|
||||
++elapsed;
|
||||
--blocks_in_period;
|
||||
if (Condition(currentIndex, params)) {
|
||||
++count;
|
||||
if (signalling_blocks) signalling_blocks->at(blocks_in_period) = true;
|
||||
}
|
||||
currentIndex = currentIndex->pprev;
|
||||
} while(blocks_in_period > 0);
|
||||
|
||||
stats.elapsed = elapsed;
|
||||
stats.count = count;
|
||||
stats.possible = (stats.period - stats.threshold ) >= (stats.elapsed - count);
|
||||
|
||||
@@ -196,9 +205,9 @@ ThresholdState VersionBitsCache::State(const CBlockIndex* pindexPrev, const Cons
|
||||
return VersionBitsConditionChecker(pos).GetStateFor(pindexPrev, params, m_caches[pos]);
|
||||
}
|
||||
|
||||
BIP9Stats VersionBitsCache::Statistics(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos)
|
||||
BIP9Stats VersionBitsCache::Statistics(const CBlockIndex* pindex, const Consensus::Params& params, Consensus::DeploymentPos pos, std::vector<bool>* signalling_blocks)
|
||||
{
|
||||
return VersionBitsConditionChecker(pos).GetStateStatisticsFor(pindexPrev, params);
|
||||
return VersionBitsConditionChecker(pos).GetStateStatisticsFor(pindex, params, signalling_blocks);
|
||||
}
|
||||
|
||||
int VersionBitsCache::StateSinceHeight(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos)
|
||||
|
||||
Reference in New Issue
Block a user