mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-04 18:22:57 +02:00
versionbits: Limit live activation params and activation warnings per BIP323
Test bits are conserved. This only has an effect on the warnings. Co-Authored-By: Antoine Poinsot <mail@antoinep.com>
This commit is contained in:
committed by
Antoine Poinsot
parent
d3056bc149
commit
f802edf57c
@@ -14,6 +14,7 @@
|
||||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <test/fuzz/util.h>
|
||||
#include <test/util/versionbits.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
@@ -31,7 +32,7 @@ public:
|
||||
{
|
||||
assert(dep.period > 0);
|
||||
assert(dep.threshold <= dep.period);
|
||||
assert(0 <= dep.bit && dep.bit < 32 && dep.bit < VERSIONBITS_NUM_BITS);
|
||||
assert(0 <= dep.bit && dep.bit < 32 && dep.bit < VERSIONBITS_MAX_NUM_BITS);
|
||||
assert(0 <= dep.min_activation_height);
|
||||
}
|
||||
|
||||
@@ -126,7 +127,7 @@ FUZZ_TARGET(versionbits, .init = initialize)
|
||||
assert(0 < dep.threshold && dep.threshold <= dep.period); // must be able to both pass and fail threshold!
|
||||
|
||||
// select deployment parameters: bit, start time, timeout
|
||||
dep.bit = fuzzed_data_provider.ConsumeIntegralInRange<int>(0, VERSIONBITS_NUM_BITS - 1);
|
||||
dep.bit = fuzzed_data_provider.ConsumeIntegralInRange<int>(0, VERSIONBITS_MAX_NUM_BITS - 1);
|
||||
|
||||
if (always_active_test) {
|
||||
dep.nStartTime = Consensus::BIP9Deployment::ALWAYS_ACTIVE;
|
||||
|
||||
13
src/test/util/versionbits.h
Normal file
13
src/test/util/versionbits.h
Normal file
@@ -0,0 +1,13 @@
|
||||
// Copyright (c) 2026-present The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef BITCOIN_TEST_UTIL_VERSIONBITS_H
|
||||
#define BITCOIN_TEST_UTIL_VERSIONBITS_H
|
||||
|
||||
#include <versionbits.h>
|
||||
|
||||
/** Total possible bits available for versionbits per original BIP 9 specification */
|
||||
static constexpr int VERSIONBITS_MAX_NUM_BITS{29};
|
||||
|
||||
#endif // BITCOIN_TEST_UTIL_VERSIONBITS_H
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <test/util/random.h>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <test/util/versionbits.h>
|
||||
#include <util/chaintype.h>
|
||||
#include <versionbits.h>
|
||||
#include <versionbits_impl.h>
|
||||
@@ -454,9 +455,19 @@ BOOST_FIXTURE_TEST_CASE(versionbits_computeblockversion, BlockVersionTest)
|
||||
// not take precedence over STARTED/LOCKED_IN. So all softforks on
|
||||
// the same bit might overlap, even when non-overlapping start-end
|
||||
// times are picked.
|
||||
const uint32_t dep_mask{uint32_t{1} << chainParams->GetConsensus().vDeployments[dep].bit};
|
||||
const auto& dep_info = chainParams->GetConsensus().vDeployments[dep];
|
||||
const uint32_t dep_mask{uint32_t{1} << dep_info.bit};
|
||||
BOOST_CHECK(!(chain_all_vbits & dep_mask));
|
||||
chain_all_vbits |= dep_mask;
|
||||
BOOST_CHECK(0 <= dep_info.bit && dep_info.bit < VERSIONBITS_MAX_NUM_BITS);
|
||||
if (chain_type != ChainType::REGTEST) {
|
||||
if (dep == Consensus::DEPLOYMENT_TESTDUMMY) {
|
||||
BOOST_CHECK_EQUAL(dep_info.nStartTime, Consensus::BIP9Deployment::NEVER_ACTIVE);
|
||||
BOOST_CHECK_EQUAL(dep_info.nTimeout, Consensus::BIP9Deployment::NO_TIMEOUT);
|
||||
} else {
|
||||
BOOST_CHECK(dep_info.bit < VERSIONBITS_NUM_BITS);
|
||||
}
|
||||
}
|
||||
check_computeblockversion(vbcache, chainParams->GetConsensus(), dep);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ static const int32_t VERSIONBITS_LAST_OLD_BLOCK_VERSION = 4;
|
||||
static const int32_t VERSIONBITS_TOP_BITS = 0x20000000UL;
|
||||
/** What bitmask determines whether versionbits is in use */
|
||||
static const int32_t VERSIONBITS_TOP_MASK = 0xE0000000UL;
|
||||
/** Total bits available for versionbits */
|
||||
static const int32_t VERSIONBITS_NUM_BITS = 29;
|
||||
/** Total bits available for versionbits (BIP 323) */
|
||||
static const int32_t VERSIONBITS_NUM_BITS = 5;
|
||||
|
||||
/** Opaque type for BIP9 state. See versionbits_impl.h for details. */
|
||||
enum class ThresholdState : uint8_t;
|
||||
|
||||
@@ -18,7 +18,7 @@ from test_framework.test_framework import BitcoinTestFramework
|
||||
VB_PERIOD = 144 # versionbits period length for regtest
|
||||
VB_THRESHOLD = 108 # versionbits activation threshold for regtest
|
||||
VB_TOP_BITS = 0x20000000
|
||||
VB_UNKNOWN_BIT = 27 # Choose a bit unassigned to any deployment
|
||||
VB_UNKNOWN_BIT = 3 # Choose a bit unassigned to any deployment
|
||||
VB_UNKNOWN_VERSION = VB_TOP_BITS | (1 << VB_UNKNOWN_BIT)
|
||||
|
||||
WARN_UNKNOWN_RULES_ACTIVE = f"Unknown new rules activated (versionbit {VB_UNKNOWN_BIT})"
|
||||
|
||||
Reference in New Issue
Block a user