 |
Bitcoin Core
22.99.0
P2P Digital Currency
|
Go to the documentation of this file.
10 #include <validation.h>
13 #include <boost/test/unit_test.hpp>
92 for (
unsigned int i = 0; i <
vpblock.size(); i++) {
95 for (
unsigned int i = 0; i <
CHECKERS; i++) {
110 while (
vpblock.size() < height) {
114 pindex->
nTime = nTime;
130 for (
int i = 0; i <
CHECKERS; i++) {
132 BOOST_CHECK_MESSAGE(
checker[i].GetStateSinceHeightFor(tip) == height,
strprintf(
"Test %i for StateSinceHeight",
num));
133 BOOST_CHECK_MESSAGE(
checker_delayed[i].GetStateSinceHeightFor(tip) == height_delayed,
strprintf(
"Test %i for StateSinceHeight (delayed)",
num));
134 BOOST_CHECK_MESSAGE(
checker_always[i].GetStateSinceHeightFor(tip) == 0,
strprintf(
"Test %i for StateSinceHeight (always active)",
num));
135 BOOST_CHECK_MESSAGE(
checker_never[i].GetStateSinceHeightFor(tip) == 0,
strprintf(
"Test %i for StateSinceHeight (never active)",
num));
149 if (exp != exp_delayed) {
156 for (
int i = 0; i <
CHECKERS; i++) {
164 int height = pindex ==
nullptr ? 0 : pindex->
nHeight + 1;
166 BOOST_CHECK_MESSAGE(got_delayed == exp_delayed,
strprintf(
"Test %i for %s height %d (got %s; delayed case)",
num,
StateName(exp_delayed), height,
StateName(got_delayed)));
191 for (
int i = 0; i < 64; i++) {
281 BOOST_REQUIRE(nStartTime < nTimeout);
282 BOOST_REQUIRE(nStartTime >= 0);
284 BOOST_REQUIRE(0 <= bit && bit < 32);
287 BOOST_REQUIRE(min_activation_height >= 0);
299 int64_t nTime = nStartTime;
348 while (nTime < nTimeout && blocksToMine > 0) {
403 if (lastBlock->
nHeight + 1 < min_activation_height) {
421 uint32_t chain_all_vbits{0};
431 chain_all_vbits |= dep_mask;
450 args.
ForceSetArg(
"-vbparams",
"testdummy:1199145601:1230767999:403200");
int64_t nStartTime
Start MedianTime for version bits miner confirmation.
VersionBitsTester & Reset()
static const int32_t VERSIONBITS_TOP_MASK
What bitmask determines whether versionbits is in use.
int GetStateSinceHeightFor(const CBlockIndex *pindexPrev) const
bool Condition(const CBlockIndex *pindex, const Consensus::Params ¶ms) const override
int bit
Bit position to select the particular bit in nVersion.
int32_t ComputeBlockVersion(const CBlockIndex *pindexPrev, const Consensus::Params ¶ms)
Determine what nVersion a new block should use.
@ MAX_VERSION_BITS_DEPLOYMENTS
int Threshold(const Consensus::Params ¶ms) const override
ThresholdState GetStateFor(const CBlockIndex *pindexPrev) const
CBlockIndex * pprev
pointer to the index of the predecessor of this block
int64_t nTimeout
Timeout/expiry MedianTime for the deployment attempt.
int nHeight
height of the entry in the chain. The genesis block has height 0
ThresholdConditionCache cache
static const std::string TESTNET
static constexpr int64_t NO_TIMEOUT
Constant for nTimeout very far in the future.
ThresholdState GetStateFor(const CBlockIndex *pindexPrev, const Consensus::Params ¶ms, ThresholdConditionCache &cache) const
Returns the state for pindex A based on parent pindexPrev B.
uint32_t nMinerConfirmationWindow
static void check_computeblockversion(const Consensus::Params ¶ms, Consensus::DeploymentPos dep)
Check that ComputeBlockVersion will set the appropriate bit correctly.
static const int32_t VERSIONBITS_TOP_BITS
What bits to set in version for versionbits blocks.
#define BOOST_FIXTURE_TEST_SUITE(a, b)
std::map< const CBlockIndex *, ThresholdState > ThresholdConditionCache
BOOST_AUTO_TEST_SUITE_END()
int Period(const Consensus::Params ¶ms) const override
VersionBitsTester & TestState(ThresholdState exp, ThresholdState exp_delayed)
Parameters that influence chain consensus.
VersionBitsCache g_versionbitscache
Global cache for versionbits deployment status.
VersionBitsTester & TestDefined()
int GetStateSinceHeightFor(const CBlockIndex *pindexPrev, const Consensus::Params ¶ms, ThresholdConditionCache &cache) const
Returns the height since when the ThresholdState has started for pindex A based on parent pindexPrev ...
int64_t BeginTime(const Consensus::Params ¶ms) const override
int32_t nVersion
block header
static uint32_t Mask(const Consensus::Params ¶ms, Consensus::DeploymentPos pos)
static const std::string REGTEST
TestAlwaysActiveConditionChecker checker_always[CHECKERS]
void ForceSetArg(const std::string &strArg, const std::string &strValue)
static constexpr int64_t NEVER_ACTIVE
Special value for nStartTime indicating that the deployment is never active.
TestConditionChecker checker[CHECKERS]
int MinActivationHeight(const Consensus::Params ¶ms) const override
TestNeverActiveConditionChecker checker_never[CHECKERS]
VersionBitsTester & TestStateSinceHeight(int height, int height_delayed)
VersionBitsTester & TestActiveDelayed()
Abstract class that implements BIP9-style threshold logic, and caches results.
int64_t BeginTime(const Consensus::Params ¶ms) const override
std::vector< CBlockIndex * > vpblock
static const std::string MAIN
Chain name strings.
int min_activation_height
If lock in occurs, delay activation until at least this block height.
VersionBitsTester & TestStarted()
static const Consensus::Params paramsDummy
VersionBitsTester & Mine(unsigned int height, int32_t nTime, int32_t nVersion)
static const std::string StateName(ThresholdState state)
BIP9Deployment vDeployments[MAX_VERSION_BITS_DEPLOYMENTS]
VersionBitsTester & TestLockedIn()
void BuildSkip()
Build the skiplist pointer for this entry.
int64_t EndTime(const Consensus::Params ¶ms) const override
TestDelayedActivationConditionChecker checker_delayed[CHECKERS]
static int32_t TestTime(int nHeight)
const CChainParams & Params()
Return the currently selected parameters.
Testing setup that configures a complete environment.
static uint64_t InsecureRandBits(int bits)
static const int32_t VERSIONBITS_LAST_OLD_BLOCK_VERSION
What block version to use for new blocks (pre versionbits)
ThresholdState
BIP 9 defines a finite-state-machine to deploy a softfork in multiple stages.
The block chain is a tree shaped structure starting with the genesis block at the root,...
BOOST_AUTO_TEST_CASE(versionbits_test)
VersionBitsTester & TestFailed()
VersionBitsTester & TestStateSinceHeight(int height)
VersionBitsTester & TestState(ThresholdState exp)
std::unique_ptr< const CChainParams > CreateChainParams(const ArgsManager &args, const std::string &chain)
Creates and returns a std::unique_ptr<CChainParams> of the chosen chain.
VersionBitsTester & TestActive()
int64_t BeginTime(const Consensus::Params ¶ms) const override
#define BOOST_CHECK(expr)
#define BOOST_CHECK_EQUAL(v1, v2)
static const std::string SIGNET
static constexpr int64_t ALWAYS_ACTIVE
Special value for nStartTime indicating that the deployment is always active.