Refactor N/100 blocks signalling warning to detect edge case

Previously, it would have skipped the non-vb check if the set top bits were cleared
This commit is contained in:
Luke Dashjr 2024-03-26 02:25:31 +00:00
parent 31eaa83c55
commit 0da086b42b

View File

@ -2759,26 +2759,25 @@ void Chainstate::UpdateTip(const CBlockIndex* pindexNew)
for (int i = 0; i < 100 && pindex != nullptr; i++) for (int i = 0; i < 100 && pindex != nullptr; i++)
{ {
int32_t nExpectedVersion = m_chainman.m_versionbitscache.ComputeBlockVersion(pindex->pprev, params.GetConsensus()); int32_t nExpectedVersion = m_chainman.m_versionbitscache.ComputeBlockVersion(pindex->pprev, params.GetConsensus());
if (pindex->nVersion > VERSIONBITS_LAST_OLD_BLOCK_VERSION && (pindex->nVersion & ~nExpectedVersion) != 0) if (pindex->nVersion <= VERSIONBITS_LAST_OLD_BLOCK_VERSION) {
{ // We don't care
if ((pindex->nVersion & VERSIONBITS_TOP_MASK) == VERSIONBITS_TOP_BITS) { } else if ((pindex->nVersion & VERSIONBITS_TOP_MASK) != VERSIONBITS_TOP_BITS) {
for (int bit = 0; bit < VERSIONBITS_NUM_BITS; ++bit) { // Non-versionbits upgrade
const int32_t mask = 1 << bit; static constexpr int WARNING_THRESHOLD = 100/2;
if ((pindex->nVersion & mask) && !(nExpectedVersion & mask)) { if (++nonversionbit_count > WARNING_THRESHOLD) {
const int warning_threshold = (bit > 12 ? 75 : 50); if (warning_threshold_hit_int == -1) {
if (++unexpected_bit_count[bit] > warning_threshold) { warning_threshold_hit_int = pindex->nVersion;
warning_threshold_hit_bits.insert(bit); } else if (warning_threshold_hit_int != pindex->nVersion) {
} warning_threshold_hit_int = -2;
}
} }
} else { }
// Non-versionbits upgrade } else if ((pindex->nVersion & ~nExpectedVersion) != 0) {
static constexpr int WARNING_THRESHOLD = 100/2; for (int bit = 0; bit < VERSIONBITS_NUM_BITS; ++bit) {
if (++nonversionbit_count > WARNING_THRESHOLD) { const int32_t mask = 1 << bit;
if (warning_threshold_hit_int == -1) { if ((pindex->nVersion & mask) && !(nExpectedVersion & mask)) {
warning_threshold_hit_int = pindex->nVersion; const int warning_threshold = (bit > 12 ? 75 : 50);
} else if (warning_threshold_hit_int != pindex->nVersion) { if (++unexpected_bit_count[bit] > warning_threshold) {
warning_threshold_hit_int = -2; warning_threshold_hit_bits.insert(bit);
} }
} }
} }