mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 23:03:45 +01:00
versionbits: Move WarningBits logic from validation to versionbits
This commit is contained in:
@@ -2364,44 +2364,6 @@ DisconnectResult Chainstate::DisconnectBlock(const CBlock& block, const CBlockIn
|
||||
return fClean ? DISCONNECT_OK : DISCONNECT_UNCLEAN;
|
||||
}
|
||||
|
||||
/**
|
||||
* Threshold condition checker that triggers when unknown versionbits are seen on the network.
|
||||
*/
|
||||
class WarningBitsConditionChecker : public AbstractThresholdConditionChecker
|
||||
{
|
||||
private:
|
||||
const ChainstateManager& m_chainman;
|
||||
int m_bit;
|
||||
|
||||
public:
|
||||
explicit WarningBitsConditionChecker(const ChainstateManager& chainman, int bit) : m_chainman{chainman}, m_bit(bit) {}
|
||||
|
||||
int64_t BeginTime() const override { return 0; }
|
||||
int64_t EndTime() const override { return std::numeric_limits<int64_t>::max(); }
|
||||
int Period() const override {
|
||||
if (m_chainman.GetParams().IsTestChain()) {
|
||||
return m_chainman.GetConsensus().DifficultyAdjustmentInterval();
|
||||
} else {
|
||||
return 2016;
|
||||
}
|
||||
}
|
||||
int Threshold() const override {
|
||||
if (m_chainman.GetParams().IsTestChain()) {
|
||||
return m_chainman.GetConsensus().DifficultyAdjustmentInterval() * 3 / 4; // 75% for test nets per BIP9 suggestion
|
||||
} else {
|
||||
return 1815; // 90% threshold used in BIP 341
|
||||
}
|
||||
}
|
||||
|
||||
bool Condition(const CBlockIndex* pindex) const override
|
||||
{
|
||||
return pindex->nHeight >= m_chainman.GetConsensus().MinBIP9WarningHeight &&
|
||||
((pindex->nVersion & VERSIONBITS_TOP_MASK) == VERSIONBITS_TOP_BITS) &&
|
||||
((pindex->nVersion >> m_bit) & 1) != 0 &&
|
||||
((m_chainman.m_versionbitscache.ComputeBlockVersion(pindex->pprev, m_chainman.GetConsensus()) >> m_bit) & 1) == 0;
|
||||
}
|
||||
};
|
||||
|
||||
static unsigned int GetBlockScriptFlags(const CBlockIndex& block_index, const ChainstateManager& chainman)
|
||||
{
|
||||
const Consensus::Params& consensusparams = chainman.GetConsensus();
|
||||
@@ -3038,17 +3000,13 @@ void Chainstate::UpdateTip(const CBlockIndex* pindexNew)
|
||||
|
||||
std::vector<bilingual_str> warning_messages;
|
||||
if (!m_chainman.IsInitialBlockDownload()) {
|
||||
const CBlockIndex* pindex = pindexNew;
|
||||
for (int bit = 0; bit < VERSIONBITS_NUM_BITS; bit++) {
|
||||
WarningBitsConditionChecker checker(m_chainman, bit);
|
||||
ThresholdState state = checker.GetStateFor(pindex, m_chainman.m_warningcache.at(bit));
|
||||
if (state == ThresholdState::ACTIVE || state == ThresholdState::LOCKED_IN) {
|
||||
const bilingual_str warning = strprintf(_("Unknown new rules activated (versionbit %i)"), bit);
|
||||
if (state == ThresholdState::ACTIVE) {
|
||||
m_chainman.GetNotifications().warningSet(kernel::Warning::UNKNOWN_NEW_RULES_ACTIVATED, warning);
|
||||
} else {
|
||||
warning_messages.push_back(warning);
|
||||
}
|
||||
auto bits = m_chainman.m_versionbitscache.CheckUnknownActivations(pindexNew, m_chainman.GetParams());
|
||||
for (auto [bit, active] : bits) {
|
||||
const bilingual_str warning = strprintf(_("Unknown new rules activated (versionbit %i)"), bit);
|
||||
if (active) {
|
||||
m_chainman.GetNotifications().warningSet(kernel::Warning::UNKNOWN_NEW_RULES_ACTIVATED, warning);
|
||||
} else {
|
||||
warning_messages.push_back(warning);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user