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