@@ -81,11 +81,9 @@ class VersionBitsTester
81
81
TestNeverActiveConditionChecker checker_never[CHECKERS];
82
82
83
83
// Test counter (to identify failures)
84
- int num;
84
+ int num{ 1000 } ;
85
85
86
86
public:
87
- VersionBitsTester () : num(1000 ) {}
88
-
89
87
VersionBitsTester& Reset () {
90
88
// Have each group of tests be counted by the 1000s part, starting at 1000
91
89
num = num - (num % 1000 ) + 1000 ;
@@ -257,39 +255,6 @@ BOOST_AUTO_TEST_CASE(versionbits_test)
257
255
}
258
256
}
259
257
260
- BOOST_AUTO_TEST_CASE (versionbits_sanity)
261
- {
262
- // Sanity checks of version bit deployments
263
- const auto chainParams = CreateChainParams (*m_node.args , CBaseChainParams::MAIN);
264
- const Consensus::Params &mainnetParams = chainParams->GetConsensus ();
265
- for (int i=0 ; i<(int ) Consensus::MAX_VERSION_BITS_DEPLOYMENTS; i++) {
266
- uint32_t bitmask = VersionBitsMask (mainnetParams, static_cast <Consensus::DeploymentPos>(i));
267
- // Make sure that no deployment tries to set an invalid bit.
268
- BOOST_CHECK_EQUAL (bitmask & ~(uint32_t )VERSIONBITS_TOP_MASK, bitmask);
269
-
270
- // Check min_activation_height is on a retarget boundary
271
- BOOST_CHECK_EQUAL (mainnetParams.vDeployments [i].min_activation_height % mainnetParams.nMinerConfirmationWindow , 0 );
272
- // Check min_activation_height is 0 for ALWAYS_ACTIVE and never active deployments
273
- if (mainnetParams.vDeployments [i].nStartTime == Consensus::BIP9Deployment::ALWAYS_ACTIVE || mainnetParams.vDeployments [i].nStartTime == Consensus::BIP9Deployment::NEVER_ACTIVE) {
274
- BOOST_CHECK_EQUAL (mainnetParams.vDeployments [i].min_activation_height , 0 );
275
- }
276
-
277
- // Verify that the deployment windows of different deployment using the
278
- // same bit are disjoint.
279
- // This test may need modification at such time as a new deployment
280
- // is proposed that reuses the bit of an activated soft fork, before the
281
- // end time of that soft fork. (Alternatively, the end time of that
282
- // activated soft fork could be later changed to be earlier to avoid
283
- // overlap.)
284
- for (int j=i+1 ; j<(int ) Consensus::MAX_VERSION_BITS_DEPLOYMENTS; j++) {
285
- if (VersionBitsMask (mainnetParams, static_cast <Consensus::DeploymentPos>(j)) == bitmask) {
286
- BOOST_CHECK (mainnetParams.vDeployments [j].nStartTime > mainnetParams.vDeployments [i].nTimeout ||
287
- mainnetParams.vDeployments [i].nStartTime > mainnetParams.vDeployments [j].nTimeout );
288
- }
289
- }
290
- }
291
- }
292
-
293
258
/* * Check that ComputeBlockVersion will set the appropriate bit correctly */
294
259
static void check_computeblockversion (const Consensus::Params& params, Consensus::DeploymentPos dep)
295
260
{
@@ -305,16 +270,25 @@ static void check_computeblockversion(const Consensus::Params& params, Consensus
305
270
BOOST_CHECK_EQUAL (ComputeBlockVersion (nullptr , params), VERSIONBITS_TOP_BITS);
306
271
307
272
// always/never active deployments shouldn't need to be tested further
308
- if (nStartTime == Consensus::BIP9Deployment::ALWAYS_ACTIVE) return ;
309
- if (nStartTime == Consensus::BIP9Deployment::NEVER_ACTIVE) return ;
273
+ if (nStartTime == Consensus::BIP9Deployment::ALWAYS_ACTIVE ||
274
+ nStartTime == Consensus::BIP9Deployment::NEVER_ACTIVE)
275
+ {
276
+ BOOST_CHECK_EQUAL (min_activation_height, 0 );
277
+ return ;
278
+ }
310
279
311
280
BOOST_REQUIRE (nStartTime < nTimeout);
312
281
BOOST_REQUIRE (nStartTime >= 0 );
313
282
BOOST_REQUIRE (nTimeout <= std::numeric_limits<uint32_t >::max () || nTimeout == Consensus::BIP9Deployment::NO_TIMEOUT);
314
283
BOOST_REQUIRE (0 <= bit && bit < 32 );
284
+ // Make sure that no deployment tries to set an invalid bit.
315
285
BOOST_REQUIRE (((1 << bit) & VERSIONBITS_TOP_MASK) == 0 );
316
286
BOOST_REQUIRE (min_activation_height >= 0 );
317
- BOOST_REQUIRE_EQUAL (min_activation_height % params.nMinerConfirmationWindow , 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{VersionBitsMask (params, dep)};
291
+ BOOST_CHECK_EQUAL (bitmask, uint32_t {1 } << bit);
318
292
319
293
// In the first chain, test that the bit is set by CBV until it has failed.
320
294
// In the second chain, test the bit is set by CBV while STARTED and
@@ -443,8 +417,18 @@ BOOST_AUTO_TEST_CASE(versionbits_computeblockversion)
443
417
// ACTIVE and FAILED states in roughly the way we expect
444
418
for (const auto & chain_name : {CBaseChainParams::MAIN, CBaseChainParams::TESTNET, CBaseChainParams::SIGNET, CBaseChainParams::REGTEST}) {
445
419
const auto chainParams = CreateChainParams (*m_node.args , chain_name);
420
+ uint32_t chain_all_vbits{0 };
446
421
for (int i = 0 ; i < (int )Consensus::MAX_VERSION_BITS_DEPLOYMENTS; ++i) {
447
- check_computeblockversion (chainParams->GetConsensus (), static_cast <Consensus::DeploymentPos>(i));
422
+ const auto dep = static_cast <Consensus::DeploymentPos>(i);
423
+ // Check that no bits are re-used (within the same chain). This is
424
+ // disallowed because the transition to FAILED (on timeout) does
425
+ // not take precedence over STARTED/LOCKED_IN. So all softforks on
426
+ // the same bit might overlap, even when non-overlapping start-end
427
+ // times are picked.
428
+ const uint32_t dep_mask{VersionBitsMask (chainParams->GetConsensus (), dep)};
429
+ BOOST_CHECK (!(chain_all_vbits & dep_mask));
430
+ chain_all_vbits |= dep_mask;
431
+ check_computeblockversion (chainParams->GetConsensus (), dep);
448
432
}
449
433
}
450
434
0 commit comments