mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-13 11:40:42 +02:00
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:
parent
31eaa83c55
commit
0da086b42b
@ -2759,19 +2759,9 @@ 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) {
|
|
||||||
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 {
|
|
||||||
// Non-versionbits upgrade
|
// Non-versionbits upgrade
|
||||||
static constexpr int WARNING_THRESHOLD = 100/2;
|
static constexpr int WARNING_THRESHOLD = 100/2;
|
||||||
if (++nonversionbit_count > WARNING_THRESHOLD) {
|
if (++nonversionbit_count > WARNING_THRESHOLD) {
|
||||||
@ -2781,6 +2771,15 @@ void Chainstate::UpdateTip(const CBlockIndex* pindexNew)
|
|||||||
warning_threshold_hit_int = -2;
|
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;
|
pindex = pindex->pprev;
|
||||||
|
Loading…
Reference in New Issue
Block a user