6 #include <chainparams.h>
12 #include <boost/test/unit_test.hpp>
91 for (
unsigned int i = 0; i <
vpblock.size(); i++) {
94 for (
unsigned int i = 0; i <
CHECKERS; i++) {
109 while (
vpblock.size() < height) {
113 pindex->
nTime = nTime;
129 for (
int i = 0; i <
CHECKERS; i++) {
131 BOOST_CHECK_MESSAGE(
checker[i].GetStateSinceHeightFor(tip) == height,
strprintf(
"Test %i for StateSinceHeight",
num));
132 BOOST_CHECK_MESSAGE(
checker_delayed[i].GetStateSinceHeightFor(tip) == height_delayed,
strprintf(
"Test %i for StateSinceHeight (delayed)",
num));
133 BOOST_CHECK_MESSAGE(
checker_always[i].GetStateSinceHeightFor(tip) == 0,
strprintf(
"Test %i for StateSinceHeight (always active)",
num));
134 BOOST_CHECK_MESSAGE(
checker_never[i].GetStateSinceHeightFor(tip) == 0,
strprintf(
"Test %i for StateSinceHeight (never active)",
num));
148 if (exp != exp_delayed) {
155 for (
int i = 0; i <
CHECKERS; i++) {
163 int height = pindex ==
nullptr ? 0 : pindex->
nHeight + 1;
165 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)));
190 for (
int i = 0; i < 64; i++) {
262 versionbitscache.
Clear();
281 BOOST_REQUIRE(nStartTime < nTimeout);
282 BOOST_REQUIRE(nStartTime >= 0);
284 BOOST_REQUIRE(0 <= bit && bit < 32);
287 BOOST_REQUIRE(min_activation_height >= 0);
291 const uint32_t bitmask{versionbitscache.
Mask(params, dep)};
299 int64_t nTime = nStartTime;
348 while (nTime < nTimeout && blocksToMine > 0) {
403 if (lastBlock->
nHeight + 1 < min_activation_height) {
423 uint32_t chain_all_vbits{0};
431 const uint32_t dep_mask{vbcache.
Mask(chainParams->GetConsensus(), dep)};
433 chain_all_vbits |= dep_mask;
452 args.
ForceSetArg(
"-vbparams",
"testdummy:1199145601:1230767999:403200");
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.
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)
static const std::string REGTEST
static const std::string TESTNET
static const std::string SIGNET
static const std::string MAIN
Chain name strings.
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
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 & TestStateSinceHeight(int height, int height_delayed)
VersionBitsTester & TestFailed()
VersionBitsTester & TestStarted()
VersionBitsTester & TestDefined()
VersionBitsTester & TestState(ThresholdState exp, ThresholdState exp_delayed)
VersionBitsTester & TestActiveDelayed()
VersionBitsTester & TestStateSinceHeight(int height)
VersionBitsTester & Reset()
TestDelayedActivationConditionChecker checker_delayed[CHECKERS]
VersionBitsTester & TestState(ThresholdState exp)
VersionBitsTester & TestLockedIn()
std::vector< CBlockIndex * > vpblock
TestNeverActiveConditionChecker checker_never[CHECKERS]
TestConditionChecker checker[CHECKERS]
TestAlwaysActiveConditionChecker checker_always[CHECKERS]
VersionBitsTester & Mine(unsigned int height, int32_t nTime, int32_t nVersion)
VersionBitsTester & TestActive()
BOOST_AUTO_TEST_SUITE_END()
@ MAX_VERSION_BITS_DEPLOYMENTS
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
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]
static uint64_t InsecureRandBits(int bits)
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)
static int32_t TestTime(int nHeight)
static void check_computeblockversion(VersionBitsCache &versionbitscache, const Consensus::Params ¶ms, Consensus::DeploymentPos dep)
Check that ComputeBlockVersion will set the appropriate bit correctly.
BOOST_AUTO_TEST_CASE(versionbits_test)