mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 06:58:57 +01:00
rpc: getdeploymentinfo: change stats to always refer to current period
On a period boundary, getdeploymentinfo (and previously getblockchaininfo) would report the status and statistics for the next block rather than the current block. Change this to always report the status/statistics of the current block, but add status-next to report the status for the next block.
This commit is contained in:
@@ -51,7 +51,7 @@ public:
|
||||
|
||||
ThresholdState GetStateFor(const CBlockIndex* pindexPrev) const { return AbstractThresholdConditionChecker::GetStateFor(pindexPrev, dummy_params, m_cache); }
|
||||
int GetStateSinceHeightFor(const CBlockIndex* pindexPrev) const { return AbstractThresholdConditionChecker::GetStateSinceHeightFor(pindexPrev, dummy_params, m_cache); }
|
||||
BIP9Stats GetStateStatisticsFor(const CBlockIndex* pindexPrev) const { return AbstractThresholdConditionChecker::GetStateStatisticsFor(pindexPrev, dummy_params); }
|
||||
BIP9Stats GetStateStatisticsFor(const CBlockIndex* pindex) const { return AbstractThresholdConditionChecker::GetStateStatisticsFor(pindex, dummy_params); }
|
||||
|
||||
bool Condition(int32_t version) const
|
||||
{
|
||||
@@ -220,7 +220,13 @@ FUZZ_TARGET_INIT(versionbits, initialize)
|
||||
CBlockIndex* prev = blocks.tip();
|
||||
const int exp_since = checker.GetStateSinceHeightFor(prev);
|
||||
const ThresholdState exp_state = checker.GetStateFor(prev);
|
||||
BIP9Stats last_stats = checker.GetStateStatisticsFor(prev);
|
||||
|
||||
// get statistics from end of previous period, then reset
|
||||
BIP9Stats last_stats;
|
||||
last_stats.period = period;
|
||||
last_stats.threshold = threshold;
|
||||
last_stats.count = last_stats.elapsed = 0;
|
||||
last_stats.possible = (period >= threshold);
|
||||
|
||||
int prev_next_height = (prev == nullptr ? 0 : prev->nHeight + 1);
|
||||
assert(exp_since <= prev_next_height);
|
||||
@@ -241,9 +247,6 @@ FUZZ_TARGET_INIT(versionbits, initialize)
|
||||
assert(state == exp_state);
|
||||
assert(since == exp_since);
|
||||
|
||||
// GetStateStatistics may crash when state is not STARTED
|
||||
if (state != ThresholdState::STARTED) continue;
|
||||
|
||||
// check that after mining this block stats change as expected
|
||||
const BIP9Stats stats = checker.GetStateStatisticsFor(current_block);
|
||||
assert(stats.period == period);
|
||||
@@ -265,14 +268,12 @@ FUZZ_TARGET_INIT(versionbits, initialize)
|
||||
CBlockIndex* current_block = blocks.mine_block(signal);
|
||||
assert(checker.Condition(current_block) == signal);
|
||||
|
||||
// GetStateStatistics is safe on a period boundary
|
||||
// and has progressed to a new period
|
||||
const BIP9Stats stats = checker.GetStateStatisticsFor(current_block);
|
||||
assert(stats.period == period);
|
||||
assert(stats.threshold == threshold);
|
||||
assert(stats.elapsed == 0);
|
||||
assert(stats.count == 0);
|
||||
assert(stats.possible == true);
|
||||
assert(stats.elapsed == period);
|
||||
assert(stats.count == blocks_sig);
|
||||
assert(stats.possible == (stats.count + period >= stats.elapsed + threshold));
|
||||
|
||||
// More interesting is whether the state changed.
|
||||
const ThresholdState state = checker.GetStateFor(current_block);
|
||||
|
||||
Reference in New Issue
Block a user