6#include <chainparams.h>
14#include <boost/test/unit_test.hpp>
41 .min_activation_height = 0,
90 for (
unsigned int i = 0; i <
vpblock.size(); i++) {
93 for (
unsigned int i = 0; i <
CHECKERS; i++) {
108 while (
vpblock.size() < height) {
112 pindex->
nTime = nTime;
128 for (
int i = 0; i <
CHECKERS; i++) {
130 BOOST_CHECK_MESSAGE(
checker[i].StateSinceHeightFor(tip) == height,
strprintf(
"Test %i for StateSinceHeight",
num));
131 BOOST_CHECK_MESSAGE(
checker_delayed[i].StateSinceHeightFor(tip) == height_delayed,
strprintf(
"Test %i for StateSinceHeight (delayed)",
num));
132 BOOST_CHECK_MESSAGE(
checker_always[i].StateSinceHeightFor(tip) == 0,
strprintf(
"Test %i for StateSinceHeight (always active)",
num));
133 BOOST_CHECK_MESSAGE(
checker_never[i].StateSinceHeightFor(tip) == 0,
strprintf(
"Test %i for StateSinceHeight (never active)",
num));
147 if (exp != exp_delayed) {
154 for (
int i = 0; i <
CHECKERS; i++) {
162 int height = pindex ==
nullptr ? 0 : pindex->
nHeight + 1;
164 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)));
189 for (
int i = 0; i < 64; i++) {
263 versionbitscache.
Clear();
266 int64_t nStartTime = params.
vDeployments[dep].nStartTime;
268 int min_activation_height = params.
vDeployments[dep].min_activation_height;
270 uint32_t threshold = params.
vDeployments[dep].threshold;
272 BOOST_REQUIRE(period > 0);
273 BOOST_REQUIRE(0 < threshold);
274 BOOST_REQUIRE(threshold < period);
293 BOOST_REQUIRE(nStartTime < nTimeout);
294 BOOST_REQUIRE(nStartTime >= 0);
296 BOOST_REQUIRE(0 <= bit && bit < 32);
299 BOOST_REQUIRE(min_activation_height >= 0);
301 BOOST_REQUIRE_EQUAL(min_activation_height % period, 0U);
308 int64_t nTime = nStartTime;
335 for (uint32_t i = 1; i < period - 4; i++) {
343 for (uint32_t i = period - 4; i <= period; i++) {
360 uint32_t blocksToMine = period * 2;
363 while (nTime < nTimeout && blocksToMine > 0) {
379 while (
nHeight % period != 0) {
388 for (uint32_t i = 0; i < period - 1; i++) {
425 if (lastBlock->
nHeight + 1 < min_activation_height) {
448 uint32_t chain_all_vbits{0};
456 const uint32_t dep_mask{uint32_t{1} << chainParams->GetConsensus().vDeployments[dep].bit};
458 chain_all_vbits |= dep_mask;
459 check_computeblockversion(vbcache, chainParams->GetConsensus(), dep);
477 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.
ThresholdState GetStateFor(const CBlockIndex *pindexPrev, ThresholdConditionCache &cache) const
Returns the state for pindex A based on parent pindexPrev B.
int GetStateSinceHeightFor(const CBlockIndex *pindexPrev, 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.
ThresholdConditionCache cache
~TestConditionChecker() override=default
int StateSinceHeightFor(const CBlockIndex *pindexPrev) const
ThresholdState StateFor(const CBlockIndex *pindexPrev) const
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.
void Clear() EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
bool IsActiveAfter(const CBlockIndex *pindexPrev, const Consensus::Params ¶ms, Consensus::DeploymentPos pos) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Get the BIP9 state for a given deployment for the block after pindexPrev.
Class to implement versionbits logic.
VersionBitsTester & TestState(ThresholdState exp, ThresholdState exp_delayed)
VersionBitsTester & TestStateSinceHeight(int height)
VersionBitsTester & TestActive()
VersionBitsTester & TestFailed()
const Deployments test_deployments
std::vector< TestConditionChecker > checker_delayed
VersionBitsTester(FastRandomContext &rng, int32_t nVersionBase=0)
VersionBitsTester & TestLockedIn()
VersionBitsTester & TestState(ThresholdState exp)
FastRandomContext & m_rng
VersionBitsTester & TestDefined()
VersionBitsTester & Mine(unsigned int height, int32_t nTime, int32_t nVersion)
VersionBitsTester & Reset()
std::vector< TestConditionChecker > checker
VersionBitsTester & TestActiveDelayed()
std::vector< TestConditionChecker > checker_never
std::vector< CBlockIndex * > vpblock
std::vector< TestConditionChecker > checker_always
VersionBitsTester & TestStarted()
const int32_t nVersionBase
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 Also checks IsActiveAfter() beh...
Struct for each individual consensus rule change using BIP9.
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.
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.
std::array< BIP9Deployment, MAX_VERSION_BITS_DEPLOYMENTS > vDeployments
std::string StateName(ThresholdState state)
Get a string with the state name.
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.
BOOST_FIXTURE_TEST_CASE(versionbits_computeblockversion, BlockVersionTest)
static int32_t TestTime(int nHeight)
BOOST_AUTO_TEST_CASE(versionbits_test)