6#include <chainparams.h>
13#include <boost/test/unit_test.hpp>
95 for (
unsigned int i = 0; i <
vpblock.size(); i++) {
98 for (
unsigned int i = 0; i <
CHECKERS; i++) {
113 while (
vpblock.size() < height) {
117 pindex->
nTime = nTime;
133 for (
int i = 0; i <
CHECKERS; i++) {
135 BOOST_CHECK_MESSAGE(
checker[i].GetStateSinceHeightFor(tip) == height,
strprintf(
"Test %i for StateSinceHeight",
num));
136 BOOST_CHECK_MESSAGE(
checker_delayed[i].GetStateSinceHeightFor(tip) == height_delayed,
strprintf(
"Test %i for StateSinceHeight (delayed)",
num));
137 BOOST_CHECK_MESSAGE(
checker_always[i].GetStateSinceHeightFor(tip) == 0,
strprintf(
"Test %i for StateSinceHeight (always active)",
num));
138 BOOST_CHECK_MESSAGE(
checker_never[i].GetStateSinceHeightFor(tip) == 0,
strprintf(
"Test %i for StateSinceHeight (never active)",
num));
152 if (exp != exp_delayed) {
159 for (
int i = 0; i <
CHECKERS; i++) {
167 int height = pindex ==
nullptr ? 0 : pindex->
nHeight + 1;
169 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)));
194 for (
int i = 0; i < 64; i++) {
267 versionbitscache.
Clear();
286 BOOST_REQUIRE(nStartTime < nTimeout);
287 BOOST_REQUIRE(nStartTime >= 0);
289 BOOST_REQUIRE(0 <= bit && bit < 32);
292 BOOST_REQUIRE(min_activation_height >= 0);
296 const uint32_t bitmask{versionbitscache.
Mask(params, dep)};
304 int64_t nTime = nStartTime;
353 while (nTime < nTimeout && blocksToMine > 0) {
408 if (lastBlock->
nHeight + 1 < min_activation_height) {
429 uint32_t chain_all_vbits{0};
437 const uint32_t dep_mask{vbcache.
Mask(chainParams->GetConsensus(), dep)};
439 chain_all_vbits |= dep_mask;
440 check_computeblockversion(vbcache, chainParams->GetConsensus(), dep);
458 args.
ForceSetArg(
"-vbparams",
"testdummy:1199145601:1230767999:403200");
std::unique_ptr< const CChainParams > CreateChainParams(const ArgsManager &args, const ChainType chain)
Creates and returns a std::unique_ptr<CChainParams> of the chosen chain.
const CChainParams & Params()
Return the currently selected parameters.
Abstract class that implements BIP9-style threshold logic, and caches results.
ThresholdState GetStateFor(const CBlockIndex *pindexPrev, const Consensus::Params ¶ms, ThresholdConditionCache &cache) const
Returns the state for pindex A based on parent pindexPrev B.
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 ...
void ForceSetArg(const std::string &strArg, const std::string &strValue)
The block chain is a tree shaped structure starting with the genesis block at the root,...
CBlockIndex * pprev
pointer to the index of the predecessor of this block
void BuildSkip()
Build the skiplist pointer for this entry.
int32_t nVersion
block header
int nHeight
height of the entry in the chain. The genesis block has height 0
uint64_t randbits(int bits) noexcept
Generate a random (bits)-bit integer.
int64_t BeginTime(const Consensus::Params ¶ms) const override
ThresholdConditionCache cache
int Threshold(const Consensus::Params ¶ms) const override
int Period(const Consensus::Params ¶ms) const override
int64_t BeginTime(const Consensus::Params ¶ms) const override
bool Condition(const CBlockIndex *pindex, const Consensus::Params ¶ms) const override
ThresholdState GetStateFor(const CBlockIndex *pindexPrev) const
int64_t EndTime(const Consensus::Params ¶ms) const override
int GetStateSinceHeightFor(const CBlockIndex *pindexPrev) const
int MinActivationHeight(const Consensus::Params ¶ms) const override
int64_t BeginTime(const Consensus::Params ¶ms) const override
BIP 9 allows multiple softforks to be deployed in parallel.
int32_t ComputeBlockVersion(const CBlockIndex *pindexPrev, const Consensus::Params ¶ms) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Determine what nVersion a new block should use.
static uint32_t Mask(const Consensus::Params ¶ms, Consensus::DeploymentPos pos)
void Clear() EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
VersionBitsTester & TestState(ThresholdState exp, ThresholdState exp_delayed)
VersionBitsTester & TestStateSinceHeight(int height)
VersionBitsTester & TestActive()
VersionBitsTester & TestFailed()
VersionBitsTester & TestLockedIn()
VersionBitsTester & TestState(ThresholdState exp)
FastRandomContext & m_rng
VersionBitsTester & TestDefined()
TestDelayedActivationConditionChecker checker_delayed[CHECKERS]
VersionBitsTester & Mine(unsigned int height, int32_t nTime, int32_t nVersion)
VersionBitsTester & Reset()
VersionBitsTester & TestActiveDelayed()
std::vector< CBlockIndex * > vpblock
TestNeverActiveConditionChecker checker_never[CHECKERS]
TestConditionChecker checker[CHECKERS]
VersionBitsTester & TestStarted()
VersionBitsTester(FastRandomContext &rng)
TestAlwaysActiveConditionChecker checker_always[CHECKERS]
VersionBitsTester & TestStateSinceHeight(int height, int height_delayed)
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
@ MAX_VERSION_BITS_DEPLOYMENTS
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
void check_computeblockversion(VersionBitsCache &versionbitscache, const Consensus::Params ¶ms, Consensus::DeploymentPos dep)
Check that ComputeBlockVersion will set the appropriate bit correctly.
int min_activation_height
If lock in occurs, delay activation until at least this block height.
int bit
Bit position to select the particular bit in nVersion.
static constexpr int64_t ALWAYS_ACTIVE
Special value for nStartTime indicating that the deployment is always active.
static constexpr int64_t NEVER_ACTIVE
Special value for nStartTime indicating that the deployment is never active.
int64_t nTimeout
Timeout/expiry MedianTime for the deployment attempt.
static constexpr int64_t NO_TIMEOUT
Constant for nTimeout very far in the future.
int64_t nStartTime
Start MedianTime for version bits miner confirmation.
Parameters that influence chain consensus.
uint32_t nMinerConfirmationWindow
BIP9Deployment vDeployments[MAX_VERSION_BITS_DEPLOYMENTS]
std::map< const CBlockIndex *, ThresholdState > ThresholdConditionCache
static const int32_t VERSIONBITS_TOP_BITS
What bits to set in version for versionbits blocks.
static const int32_t VERSIONBITS_LAST_OLD_BLOCK_VERSION
What block version to use for new blocks (pre versionbits)
static const int32_t VERSIONBITS_TOP_MASK
What bitmask determines whether versionbits is in use.
ThresholdState
BIP 9 defines a finite-state-machine to deploy a softfork in multiple stages.
static const Consensus::Params paramsDummy
static std::string StateName(ThresholdState state)
BOOST_FIXTURE_TEST_CASE(versionbits_computeblockversion, BlockVersionTest)
static int32_t TestTime(int nHeight)
BOOST_AUTO_TEST_CASE(versionbits_test)