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,19 +2759,9 @@ void Chainstate::UpdateTip(const CBlockIndex* pindexNew)
for (int i = 0; i < 100 && pindex != nullptr; i++)
{
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_TOP_MASK) == VERSIONBITS_TOP_BITS) {
for (int bit = 0; bit < VERSIONBITS_NUM_BITS; ++bit) {
const int32_t mask = 1 << bit;
if ((pindex->nVersion & mask) && !(nExpectedVersion & mask)) {
const int warning_threshold = (bit > 12 ? 75 : 50);
if (++unexpected_bit_count[bit] > warning_threshold) {
warning_threshold_hit_bits.insert(bit);
}
}
}
} else {
if (pindex->nVersion <= VERSIONBITS_LAST_OLD_BLOCK_VERSION) {
// We don't care
} else if ((pindex->nVersion & VERSIONBITS_TOP_MASK) != VERSIONBITS_TOP_BITS) {
// Non-versionbits upgrade
static constexpr int WARNING_THRESHOLD = 100/2;
if (++nonversionbit_count > WARNING_THRESHOLD) {
@ -2781,6 +2771,15 @@ void Chainstate::UpdateTip(const CBlockIndex* pindexNew)
warning_threshold_hit_int = -2;
}
}
} else if ((pindex->nVersion & ~nExpectedVersion) != 0) {
for (int bit = 0; bit < VERSIONBITS_NUM_BITS; ++bit) {
const int32_t mask = 1 << bit;
if ((pindex->nVersion & mask) && !(nExpectedVersion & mask)) {
const int warning_threshold = (bit > 12 ? 75 : 50);
if (++unexpected_bit_count[bit] > warning_threshold) {
warning_threshold_hit_bits.insert(bit);
}
}
}
}
pindex = pindex->pprev;