Bitcoin Core  24.1.0
P2P Digital Currency
versionbits_tests.cpp
Go to the documentation of this file.
1 // Copyright (c) 2014-2021 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include <chain.h>
6 #include <chainparams.h>
7 #include <consensus/params.h>
9 #include <versionbits.h>
10 
11 #include <boost/test/unit_test.hpp>
12 
13 /* Define a virtual block time, one block per 10 minutes after Nov 14 2014, 0:55:36am */
14 static int32_t TestTime(int nHeight) { return 1415926536 + 600 * nHeight; }
15 
16 static const std::string StateName(ThresholdState state)
17 {
18  switch (state) {
19  case ThresholdState::DEFINED: return "DEFINED";
20  case ThresholdState::STARTED: return "STARTED";
21  case ThresholdState::LOCKED_IN: return "LOCKED_IN";
22  case ThresholdState::ACTIVE: return "ACTIVE";
23  case ThresholdState::FAILED: return "FAILED";
24  } // no default case, so the compiler can warn about missing cases
25  return "";
26 }
27 
29 
31 {
32 private:
34 
35 public:
36  int64_t BeginTime(const Consensus::Params& params) const override { return TestTime(10000); }
37  int64_t EndTime(const Consensus::Params& params) const override { return TestTime(20000); }
38  int Period(const Consensus::Params& params) const override { return 1000; }
39  int Threshold(const Consensus::Params& params) const override { return 900; }
40  bool Condition(const CBlockIndex* pindex, const Consensus::Params& params) const override { return (pindex->nVersion & 0x100); }
41 
42  ThresholdState GetStateFor(const CBlockIndex* pindexPrev) const { return AbstractThresholdConditionChecker::GetStateFor(pindexPrev, paramsDummy, cache); }
44 };
45 
47 {
48 public:
49  int MinActivationHeight(const Consensus::Params& params) const override { return 15000; }
50 };
51 
53 {
54 public:
55  int64_t BeginTime(const Consensus::Params& params) const override { return Consensus::BIP9Deployment::ALWAYS_ACTIVE; }
56 };
57 
59 {
60 public:
61  int64_t BeginTime(const Consensus::Params& params) const override { return Consensus::BIP9Deployment::NEVER_ACTIVE; }
62 };
63 
64 #define CHECKERS 6
65 
67 {
68  // A fake blockchain
69  std::vector<CBlockIndex*> vpblock;
70 
71  // 6 independent checkers for the same bit.
72  // The first one performs all checks, the second only 50%, the third only 25%, etc...
73  // This is to test whether lack of cached information leads to the same results.
75  // Another 6 that assume delayed activation
77  // Another 6 that assume always active activation
79  // Another 6 that assume never active activation
81 
82  // Test counter (to identify failures)
83  int num{1000};
84 
85 public:
87  // Have each group of tests be counted by the 1000s part, starting at 1000
88  num = num - (num % 1000) + 1000;
89 
90  for (unsigned int i = 0; i < vpblock.size(); i++) {
91  delete vpblock[i];
92  }
93  for (unsigned int i = 0; i < CHECKERS; i++) {
98  }
99  vpblock.clear();
100  return *this;
101  }
102 
104  Reset();
105  }
106 
107  VersionBitsTester& Mine(unsigned int height, int32_t nTime, int32_t nVersion) {
108  while (vpblock.size() < height) {
109  CBlockIndex* pindex = new CBlockIndex();
110  pindex->nHeight = vpblock.size();
111  pindex->pprev = Tip();
112  pindex->nTime = nTime;
113  pindex->nVersion = nVersion;
114  pindex->BuildSkip();
115  vpblock.push_back(pindex);
116  }
117  return *this;
118  }
119 
121  {
122  return TestStateSinceHeight(height, height);
123  }
124 
125  VersionBitsTester& TestStateSinceHeight(int height, int height_delayed)
126  {
127  const CBlockIndex* tip = Tip();
128  for (int i = 0; i < CHECKERS; i++) {
129  if (InsecureRandBits(i) == 0) {
130  BOOST_CHECK_MESSAGE(checker[i].GetStateSinceHeightFor(tip) == height, strprintf("Test %i for StateSinceHeight", num));
131  BOOST_CHECK_MESSAGE(checker_delayed[i].GetStateSinceHeightFor(tip) == height_delayed, strprintf("Test %i for StateSinceHeight (delayed)", num));
132  BOOST_CHECK_MESSAGE(checker_always[i].GetStateSinceHeightFor(tip) == 0, strprintf("Test %i for StateSinceHeight (always active)", num));
133  BOOST_CHECK_MESSAGE(checker_never[i].GetStateSinceHeightFor(tip) == 0, strprintf("Test %i for StateSinceHeight (never active)", num));
134  }
135  }
136  num++;
137  return *this;
138  }
139 
141  {
142  return TestState(exp, exp);
143  }
144 
146  {
147  if (exp != exp_delayed) {
148  // only expected differences are that delayed stays in locked_in longer
151  }
152 
153  const CBlockIndex* pindex = Tip();
154  for (int i = 0; i < CHECKERS; i++) {
155  if (InsecureRandBits(i) == 0) {
156  ThresholdState got = checker[i].GetStateFor(pindex);
157  ThresholdState got_delayed = checker_delayed[i].GetStateFor(pindex);
158  ThresholdState got_always = checker_always[i].GetStateFor(pindex);
159  ThresholdState got_never = checker_never[i].GetStateFor(pindex);
160  // nHeight of the next block. If vpblock is empty, the next (ie first)
161  // block should be the genesis block with nHeight == 0.
162  int height = pindex == nullptr ? 0 : pindex->nHeight + 1;
163  BOOST_CHECK_MESSAGE(got == exp, strprintf("Test %i for %s height %d (got %s)", num, StateName(exp), height, StateName(got)));
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)));
165  BOOST_CHECK_MESSAGE(got_always == ThresholdState::ACTIVE, strprintf("Test %i for ACTIVE height %d (got %s; always active case)", num, height, StateName(got_always)));
166  BOOST_CHECK_MESSAGE(got_never == ThresholdState::FAILED, strprintf("Test %i for FAILED height %d (got %s; never active case)", num, height, StateName(got_never)));
167  }
168  }
169  num++;
170  return *this;
171  }
172 
178 
179  // non-delayed should be active; delayed should still be locked in
181 
182  CBlockIndex* Tip() { return vpblock.empty() ? nullptr : vpblock.back(); }
183 };
184 
185 BOOST_FIXTURE_TEST_SUITE(versionbits_tests, BasicTestingSetup)
186 
187 BOOST_AUTO_TEST_CASE(versionbits_test)
188 {
189  for (int i = 0; i < 64; i++) {
190  // DEFINED -> STARTED after timeout reached -> FAILED
192  .Mine(1, TestTime(1), 0x100).TestDefined().TestStateSinceHeight(0)
193  .Mine(11, TestTime(11), 0x100).TestDefined().TestStateSinceHeight(0)
194  .Mine(989, TestTime(989), 0x100).TestDefined().TestStateSinceHeight(0)
195  .Mine(999, TestTime(20000), 0x100).TestDefined().TestStateSinceHeight(0) // Timeout and start time reached simultaneously
196  .Mine(1000, TestTime(20000), 0).TestStarted().TestStateSinceHeight(1000) // Hit started, stop signalling
197  .Mine(1999, TestTime(30001), 0).TestStarted().TestStateSinceHeight(1000)
198  .Mine(2000, TestTime(30002), 0x100).TestFailed().TestStateSinceHeight(2000) // Hit failed, start signalling again
199  .Mine(2001, TestTime(30003), 0x100).TestFailed().TestStateSinceHeight(2000)
200  .Mine(2999, TestTime(30004), 0x100).TestFailed().TestStateSinceHeight(2000)
201  .Mine(3000, TestTime(30005), 0x100).TestFailed().TestStateSinceHeight(2000)
202  .Mine(4000, TestTime(30006), 0x100).TestFailed().TestStateSinceHeight(2000)
203 
204  // DEFINED -> STARTED -> FAILED
207  .Mine(1000, TestTime(10000) - 1, 0x100).TestDefined().TestStateSinceHeight(0) // One second more and it would be defined
208  .Mine(2000, TestTime(10000), 0x100).TestStarted().TestStateSinceHeight(2000) // So that's what happens the next period
209  .Mine(2051, TestTime(10010), 0).TestStarted().TestStateSinceHeight(2000) // 51 old blocks
210  .Mine(2950, TestTime(10020), 0x100).TestStarted().TestStateSinceHeight(2000) // 899 new blocks
211  .Mine(3000, TestTime(20000), 0).TestFailed().TestStateSinceHeight(3000) // 50 old blocks (so 899 out of the past 1000)
212  .Mine(4000, TestTime(20010), 0x100).TestFailed().TestStateSinceHeight(3000)
213 
214  // DEFINED -> STARTED -> LOCKEDIN after timeout reached -> ACTIVE
217  .Mine(1000, TestTime(10000) - 1, 0x101).TestDefined().TestStateSinceHeight(0) // One second more and it would be defined
218  .Mine(2000, TestTime(10000), 0x101).TestStarted().TestStateSinceHeight(2000) // So that's what happens the next period
219  .Mine(2999, TestTime(30000), 0x100).TestStarted().TestStateSinceHeight(2000) // 999 new blocks
220  .Mine(3000, TestTime(30000), 0x100).TestLockedIn().TestStateSinceHeight(3000) // 1 new block (so 1000 out of the past 1000 are new)
221  .Mine(3999, TestTime(30001), 0).TestLockedIn().TestStateSinceHeight(3000)
222  .Mine(4000, TestTime(30002), 0).TestActiveDelayed().TestStateSinceHeight(4000, 3000)
223  .Mine(14333, TestTime(30003), 0).TestActiveDelayed().TestStateSinceHeight(4000, 3000)
224  .Mine(24000, TestTime(40000), 0).TestActive().TestStateSinceHeight(4000, 15000)
225 
226  // DEFINED -> STARTED -> LOCKEDIN before timeout -> ACTIVE
227  .Reset().TestDefined()
229  .Mine(1000, TestTime(10000) - 1, 0x101).TestDefined().TestStateSinceHeight(0) // One second more and it would be defined
230  .Mine(2000, TestTime(10000), 0x101).TestStarted().TestStateSinceHeight(2000) // So that's what happens the next period
231  .Mine(2050, TestTime(10010), 0x200).TestStarted().TestStateSinceHeight(2000) // 50 old blocks
232  .Mine(2950, TestTime(10020), 0x100).TestStarted().TestStateSinceHeight(2000) // 900 new blocks
233  .Mine(2999, TestTime(19999), 0x200).TestStarted().TestStateSinceHeight(2000) // 49 old blocks
234  .Mine(3000, TestTime(29999), 0x200).TestLockedIn().TestStateSinceHeight(3000) // 1 old block (so 900 out of the past 1000)
235  .Mine(3999, TestTime(30001), 0).TestLockedIn().TestStateSinceHeight(3000)
236  .Mine(4000, TestTime(30002), 0).TestActiveDelayed().TestStateSinceHeight(4000, 3000) // delayed will not become active until height=15000
237  .Mine(14333, TestTime(30003), 0).TestActiveDelayed().TestStateSinceHeight(4000, 3000)
238  .Mine(15000, TestTime(40000), 0).TestActive().TestStateSinceHeight(4000, 15000)
239  .Mine(24000, TestTime(40000), 0).TestActive().TestStateSinceHeight(4000, 15000)
240 
241  // DEFINED multiple periods -> STARTED multiple periods -> FAILED
243  .Mine(999, TestTime(999), 0).TestDefined().TestStateSinceHeight(0)
244  .Mine(1000, TestTime(1000), 0).TestDefined().TestStateSinceHeight(0)
245  .Mine(2000, TestTime(2000), 0).TestDefined().TestStateSinceHeight(0)
246  .Mine(3000, TestTime(10000), 0).TestStarted().TestStateSinceHeight(3000)
247  .Mine(4000, TestTime(10000), 0).TestStarted().TestStateSinceHeight(3000)
248  .Mine(5000, TestTime(10000), 0).TestStarted().TestStateSinceHeight(3000)
249  .Mine(5999, TestTime(20000), 0).TestStarted().TestStateSinceHeight(3000)
250  .Mine(6000, TestTime(20000), 0).TestFailed().TestStateSinceHeight(6000)
251  .Mine(7000, TestTime(20000), 0x100).TestFailed().TestStateSinceHeight(6000)
252  .Mine(24000, TestTime(20000), 0x100).TestFailed().TestStateSinceHeight(6000) // stay in FAILED no matter how much we signal
253  ;
254  }
255 }
256 
259 {
260  // Clear the cache every time
261  versionbitscache.Clear();
262 
263  int64_t bit = params.vDeployments[dep].bit;
264  int64_t nStartTime = params.vDeployments[dep].nStartTime;
265  int64_t nTimeout = params.vDeployments[dep].nTimeout;
266  int min_activation_height = params.vDeployments[dep].min_activation_height;
267 
268  // should not be any signalling for first block
269  BOOST_CHECK_EQUAL(versionbitscache.ComputeBlockVersion(nullptr, params), VERSIONBITS_TOP_BITS);
270 
271  // always/never active deployments shouldn't need to be tested further
272  if (nStartTime == Consensus::BIP9Deployment::ALWAYS_ACTIVE ||
274  {
275  BOOST_CHECK_EQUAL(min_activation_height, 0);
277  return;
278  }
279 
280  BOOST_REQUIRE(nStartTime < nTimeout);
281  BOOST_REQUIRE(nStartTime >= 0);
282  BOOST_REQUIRE(nTimeout <= std::numeric_limits<uint32_t>::max() || nTimeout == Consensus::BIP9Deployment::NO_TIMEOUT);
283  BOOST_REQUIRE(0 <= bit && bit < 32);
284  // Make sure that no deployment tries to set an invalid bit.
285  BOOST_REQUIRE(((1 << bit) & VERSIONBITS_TOP_MASK) == 0);
286  BOOST_REQUIRE(min_activation_height >= 0);
287  // Check min_activation_height is on a retarget boundary
288  BOOST_REQUIRE_EQUAL(min_activation_height % params.nMinerConfirmationWindow, 0U);
289 
290  const uint32_t bitmask{versionbitscache.Mask(params, dep)};
291  BOOST_CHECK_EQUAL(bitmask, uint32_t{1} << bit);
292 
293  // In the first chain, test that the bit is set by CBV until it has failed.
294  // In the second chain, test the bit is set by CBV while STARTED and
295  // LOCKED-IN, and then no longer set while ACTIVE.
296  VersionBitsTester firstChain, secondChain;
297 
298  int64_t nTime = nStartTime;
299 
300  const CBlockIndex *lastBlock = nullptr;
301 
302  // Before MedianTimePast of the chain has crossed nStartTime, the bit
303  // should not be set.
304  if (nTime == 0) {
305  // since CBlockIndex::nTime is uint32_t we can't represent any
306  // earlier time, so will transition from DEFINED to STARTED at the
307  // end of the first period by mining blocks at nTime == 0
308  lastBlock = firstChain.Mine(params.nMinerConfirmationWindow - 1, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip();
309  BOOST_CHECK_EQUAL(versionbitscache.ComputeBlockVersion(lastBlock, params) & (1 << bit), 0);
310  lastBlock = firstChain.Mine(params.nMinerConfirmationWindow, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip();
311  BOOST_CHECK((versionbitscache.ComputeBlockVersion(lastBlock, params) & (1 << bit)) != 0);
312  // then we'll keep mining at nStartTime...
313  } else {
314  // use a time 1s earlier than start time to check we stay DEFINED
315  --nTime;
316 
317  // Start generating blocks before nStartTime
318  lastBlock = firstChain.Mine(params.nMinerConfirmationWindow, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip();
319  BOOST_CHECK_EQUAL(versionbitscache.ComputeBlockVersion(lastBlock, params) & (1 << bit), 0);
320 
321  // Mine more blocks (4 less than the adjustment period) at the old time, and check that CBV isn't setting the bit yet.
322  for (uint32_t i = 1; i < params.nMinerConfirmationWindow - 4; i++) {
323  lastBlock = firstChain.Mine(params.nMinerConfirmationWindow + i, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip();
324  BOOST_CHECK_EQUAL(versionbitscache.ComputeBlockVersion(lastBlock, params) & (1 << bit), 0);
325  }
326  // Now mine 5 more blocks at the start time -- MTP should not have passed yet, so
327  // CBV should still not yet set the bit.
328  nTime = nStartTime;
329  for (uint32_t i = params.nMinerConfirmationWindow - 4; i <= params.nMinerConfirmationWindow; i++) {
330  lastBlock = firstChain.Mine(params.nMinerConfirmationWindow + i, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip();
331  BOOST_CHECK_EQUAL(versionbitscache.ComputeBlockVersion(lastBlock, params) & (1 << bit), 0);
332  }
333  // Next we will advance to the next period and transition to STARTED,
334  }
335 
336  lastBlock = firstChain.Mine(params.nMinerConfirmationWindow * 3, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip();
337  // so ComputeBlockVersion should now set the bit,
338  BOOST_CHECK((versionbitscache.ComputeBlockVersion(lastBlock, params) & (1 << bit)) != 0);
339  // and should also be using the VERSIONBITS_TOP_BITS.
340  BOOST_CHECK_EQUAL(versionbitscache.ComputeBlockVersion(lastBlock, params) & VERSIONBITS_TOP_MASK, VERSIONBITS_TOP_BITS);
341 
342  // Check that ComputeBlockVersion will set the bit until nTimeout
343  nTime += 600;
344  uint32_t blocksToMine = params.nMinerConfirmationWindow * 2; // test blocks for up to 2 time periods
345  uint32_t nHeight = params.nMinerConfirmationWindow * 3;
346  // These blocks are all before nTimeout is reached.
347  while (nTime < nTimeout && blocksToMine > 0) {
348  lastBlock = firstChain.Mine(nHeight+1, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip();
349  BOOST_CHECK((versionbitscache.ComputeBlockVersion(lastBlock, params) & (1 << bit)) != 0);
350  BOOST_CHECK_EQUAL(versionbitscache.ComputeBlockVersion(lastBlock, params) & VERSIONBITS_TOP_MASK, VERSIONBITS_TOP_BITS);
351  blocksToMine--;
352  nTime += 600;
353  nHeight += 1;
354  }
355 
356  if (nTimeout != Consensus::BIP9Deployment::NO_TIMEOUT) {
357  // can reach any nTimeout other than NO_TIMEOUT due to earlier BOOST_REQUIRE
358 
359  nTime = nTimeout;
360 
361  // finish the last period before we start timing out
362  while (nHeight % params.nMinerConfirmationWindow != 0) {
363  lastBlock = firstChain.Mine(nHeight+1, nTime - 1, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip();
364  BOOST_CHECK((versionbitscache.ComputeBlockVersion(lastBlock, params) & (1 << bit)) != 0);
365  nHeight += 1;
366  }
367 
368  // FAILED is only triggered at the end of a period, so CBV should be setting
369  // the bit until the period transition.
370  for (uint32_t i = 0; i < params.nMinerConfirmationWindow - 1; i++) {
371  lastBlock = firstChain.Mine(nHeight+1, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip();
372  BOOST_CHECK((versionbitscache.ComputeBlockVersion(lastBlock, params) & (1 << bit)) != 0);
373  nHeight += 1;
374  }
375  // The next block should trigger no longer setting the bit.
376  lastBlock = firstChain.Mine(nHeight+1, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip();
377  BOOST_CHECK_EQUAL(versionbitscache.ComputeBlockVersion(lastBlock, params) & (1 << bit), 0);
378  }
379 
380  // On a new chain:
381  // verify that the bit will be set after lock-in, and then stop being set
382  // after activation.
383  nTime = nStartTime;
384 
385  // Mine one period worth of blocks, and check that the bit will be on for the
386  // next period.
387  lastBlock = secondChain.Mine(params.nMinerConfirmationWindow, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip();
388  BOOST_CHECK((versionbitscache.ComputeBlockVersion(lastBlock, params) & (1 << bit)) != 0);
389 
390  // Mine another period worth of blocks, signaling the new bit.
391  lastBlock = secondChain.Mine(params.nMinerConfirmationWindow * 2, nTime, VERSIONBITS_TOP_BITS | (1<<bit)).Tip();
392  // After one period of setting the bit on each block, it should have locked in.
393  // We keep setting the bit for one more period though, until activation.
394  BOOST_CHECK((versionbitscache.ComputeBlockVersion(lastBlock, params) & (1 << bit)) != 0);
395 
396  // Now check that we keep mining the block until the end of this period, and
397  // then stop at the beginning of the next period.
398  lastBlock = secondChain.Mine((params.nMinerConfirmationWindow * 3) - 1, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip();
399  BOOST_CHECK((versionbitscache.ComputeBlockVersion(lastBlock, params) & (1 << bit)) != 0);
400  lastBlock = secondChain.Mine(params.nMinerConfirmationWindow * 3, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip();
401 
402  if (lastBlock->nHeight + 1 < min_activation_height) {
403  // check signalling continues while min_activation_height is not reached
404  lastBlock = secondChain.Mine(min_activation_height - 1, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip();
405  BOOST_CHECK((versionbitscache.ComputeBlockVersion(lastBlock, params) & (1 << bit)) != 0);
406  // then reach min_activation_height, which was already REQUIRE'd to start a new period
407  lastBlock = secondChain.Mine(min_activation_height, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip();
408  }
409 
410  // Check that we don't signal after activation
411  BOOST_CHECK_EQUAL(versionbitscache.ComputeBlockVersion(lastBlock, params) & (1 << bit), 0);
412 }
413 
414 BOOST_AUTO_TEST_CASE(versionbits_computeblockversion)
415 {
416  VersionBitsCache vbcache;
417 
418  // check that any deployment on any chain can conceivably reach both
419  // ACTIVE and FAILED states in roughly the way we expect
421  const auto chainParams = CreateChainParams(*m_node.args, chain_name);
422  uint32_t chain_all_vbits{0};
423  for (int i = 0; i < (int)Consensus::MAX_VERSION_BITS_DEPLOYMENTS; ++i) {
424  const auto dep = static_cast<Consensus::DeploymentPos>(i);
425  // Check that no bits are re-used (within the same chain). This is
426  // disallowed because the transition to FAILED (on timeout) does
427  // not take precedence over STARTED/LOCKED_IN. So all softforks on
428  // the same bit might overlap, even when non-overlapping start-end
429  // times are picked.
430  const uint32_t dep_mask{vbcache.Mask(chainParams->GetConsensus(), dep)};
431  BOOST_CHECK(!(chain_all_vbits & dep_mask));
432  chain_all_vbits |= dep_mask;
433  check_computeblockversion(vbcache, chainParams->GetConsensus(), dep);
434  }
435  }
436 
437  {
438  // Use regtest/testdummy to ensure we always exercise some
439  // deployment that's not always/never active
441  args.ForceSetArg("-vbparams", "testdummy:1199145601:1230767999"); // January 1, 2008 - December 31, 2008
442  const auto chainParams = CreateChainParams(args, CBaseChainParams::REGTEST);
443  check_computeblockversion(vbcache, chainParams->GetConsensus(), Consensus::DEPLOYMENT_TESTDUMMY);
444  }
445 
446  {
447  // Use regtest/testdummy to ensure we always exercise the
448  // min_activation_height test, even if we're not using that in a
449  // live deployment
451  args.ForceSetArg("-vbparams", "testdummy:1199145601:1230767999:403200"); // January 1, 2008 - December 31, 2008, min act height 403200
452  const auto chainParams = CreateChainParams(args, CBaseChainParams::REGTEST);
453  check_computeblockversion(vbcache, chainParams->GetConsensus(), Consensus::DEPLOYMENT_TESTDUMMY);
454  }
455 }
456 
static constexpr int64_t NO_TIMEOUT
Constant for nTimeout very far in the future.
Definition: params.h:56
int min_activation_height
If lock in occurs, delay activation until at least this block height.
Definition: params.h:53
#define CHECKERS
int Threshold(const Consensus::Params &params) const override
VersionBitsTester & TestFailed()
CBlockIndex * pprev
pointer to the index of the predecessor of this block
Definition: chain.h:158
VersionBitsTester & TestState(ThresholdState exp)
static void check_computeblockversion(VersionBitsCache &versionbitscache, const Consensus::Params &params, Consensus::DeploymentPos dep)
Check that ComputeBlockVersion will set the appropriate bit correctly.
int GetStateSinceHeightFor(const CBlockIndex *pindexPrev, const Consensus::Params &params, ThresholdConditionCache &cache) const
Returns the height since when the ThresholdState has started for pindex A based on parent pindexPrev ...
static const std::string REGTEST
VersionBitsTester & TestActive()
bool Condition(const CBlockIndex *pindex, const Consensus::Params &params) const override
node::NodeContext m_node
Definition: bitcoin-gui.cpp:37
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1164
VersionBitsTester & TestStateSinceHeight(int height)
DeploymentPos
Definition: params.h:31
static const int32_t VERSIONBITS_TOP_MASK
What bitmask determines whether versionbits is in use.
Definition: versionbits.h:18
unsigned int nHeight
int GetStateSinceHeightFor(const CBlockIndex *pindexPrev) const
static constexpr int64_t ALWAYS_ACTIVE
Special value for nStartTime indicating that the deployment is always active.
Definition: params.h:62
int Period(const Consensus::Params &params) const override
VersionBitsTester & TestState(ThresholdState exp, ThresholdState exp_delayed)
void Clear() EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
uint32_t nTime
Definition: chain.h:206
ThresholdState
BIP 9 defines a finite-state-machine to deploy a softfork in multiple stages.
Definition: versionbits.h:27
void ForceSetArg(const std::string &strArg, const std::string &strValue)
Definition: system.cpp:693
ArgsManager args
static uint32_t Mask(const Consensus::Params &params, Consensus::DeploymentPos pos)
ThresholdConditionCache cache
VersionBitsTester & TestDefined()
Basic testing setup.
Definition: setup_common.h:83
static const std::string MAIN
Chain name strings.
TestConditionChecker checker[CHECKERS]
static const std::string StateName(ThresholdState state)
int64_t BeginTime(const Consensus::Params &params) const override
TestDelayedActivationConditionChecker checker_delayed[CHECKERS]
VersionBitsTester & Mine(unsigned int height, int32_t nTime, int32_t nVersion)
ArgsManager * args
Definition: context.h:56
std::vector< CBlockIndex * > vpblock
BOOST_AUTO_TEST_SUITE_END()
int64_t nStartTime
Start MedianTime for version bits miner confirmation.
Definition: params.h:46
static const Consensus::Params paramsDummy
Abstract class that implements BIP9-style threshold logic, and caches results.
Definition: versionbits.h:57
TestNeverActiveConditionChecker checker_never[CHECKERS]
int64_t BeginTime(const Consensus::Params &params) const override
static constexpr int64_t NEVER_ACTIVE
Special value for nStartTime indicating that the deployment is never active.
Definition: params.h:67
void BuildSkip()
Build the skiplist pointer for this entry.
Definition: chain.cpp:125
static uint64_t InsecureRandBits(int bits)
Definition: setup_common.h:74
uint32_t nMinerConfirmationWindow
Definition: params.h:105
Parameters that influence chain consensus.
Definition: params.h:73
int32_t ComputeBlockVersion(const CBlockIndex *pindexPrev, const Consensus::Params &params) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Determine what nVersion a new block should use.
std::map< const CBlockIndex *, ThresholdState > ThresholdConditionCache
Definition: versionbits.h:38
BIP 9 allows multiple softforks to be deployed in parallel.
Definition: versionbits.h:80
static int32_t TestTime(int nHeight)
int32_t nVersion
block header
Definition: chain.h:204
int64_t nTimeout
Timeout/expiry MedianTime for the deployment attempt.
Definition: params.h:48
ThresholdState GetStateFor(const CBlockIndex *pindexPrev, const Consensus::Params &params, ThresholdConditionCache &cache) const
Returns the state for pindex A based on parent pindexPrev B.
Definition: versionbits.cpp:9
#define BOOST_CHECK_EQUAL(v1, v2)
Definition: object.cpp:17
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:151
const CChainParams & Params()
Return the currently selected parameters.
static const int32_t VERSIONBITS_LAST_OLD_BLOCK_VERSION
What block version to use for new blocks (pre versionbits)
Definition: versionbits.h:14
BOOST_AUTO_TEST_CASE(versionbits_test)
static const int32_t VERSIONBITS_TOP_BITS
What bits to set in version for versionbits blocks.
Definition: versionbits.h:16
VersionBitsTester & TestStarted()
int MinActivationHeight(const Consensus::Params &params) const override
TestAlwaysActiveConditionChecker checker_always[CHECKERS]
static const std::string TESTNET
VersionBitsTester & Reset()
VersionBitsTester & TestActiveDelayed()
int nHeight
height of the entry in the chain. The genesis block has height 0
Definition: chain.h:164
int bit
Bit position to select the particular bit in nVersion.
Definition: params.h:44
VersionBitsTester & TestStateSinceHeight(int height, int height_delayed)
int64_t EndTime(const Consensus::Params &params) const override
VersionBitsTester & TestLockedIn()
static const std::string SIGNET
BIP9Deployment vDeployments[MAX_VERSION_BITS_DEPLOYMENTS]
Definition: params.h:106
#define BOOST_CHECK(expr)
Definition: object.cpp:16
ThresholdState GetStateFor(const CBlockIndex *pindexPrev) const
int64_t BeginTime(const Consensus::Params &params) const override
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.