Skip to content

Commit fad4167

Browse files
author
MarcoFalke
committed
test: Check that no versionbits are re-used
This allows to remove check that windows for the same bit are disjoint This addresses bitcoin/bitcoin#21377 (comment)
1 parent 8e69370 commit fad4167

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

src/test/versionbits_tests.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -273,20 +273,6 @@ BOOST_AUTO_TEST_CASE(versionbits_sanity)
273273
if (mainnetParams.vDeployments[i].nStartTime == Consensus::BIP9Deployment::ALWAYS_ACTIVE || mainnetParams.vDeployments[i].nStartTime == Consensus::BIP9Deployment::NEVER_ACTIVE) {
274274
BOOST_CHECK_EQUAL(mainnetParams.vDeployments[i].min_activation_height, 0);
275275
}
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-
}
290276
}
291277
}
292278

@@ -443,8 +429,18 @@ BOOST_AUTO_TEST_CASE(versionbits_computeblockversion)
443429
// ACTIVE and FAILED states in roughly the way we expect
444430
for (const auto& chain_name : {CBaseChainParams::MAIN, CBaseChainParams::TESTNET, CBaseChainParams::SIGNET, CBaseChainParams::REGTEST}) {
445431
const auto chainParams = CreateChainParams(*m_node.args, chain_name);
432+
uint32_t chain_all_vbits{0};
446433
for (int i = 0; i < (int)Consensus::MAX_VERSION_BITS_DEPLOYMENTS; ++i) {
447-
check_computeblockversion(chainParams->GetConsensus(), static_cast<Consensus::DeploymentPos>(i));
434+
const auto dep = static_cast<Consensus::DeploymentPos>(i);
435+
// Check that no bits are re-used (within the same chain). This is
436+
// disallowed because the transition to FAILED (on timeout) does
437+
// not take precedence over STARTED/LOCKED_IN. So all softforks on
438+
// the same bit might overlap, even when non-overlapping start-end
439+
// times are picked.
440+
const uint32_t dep_mask{VersionBitsMask(chainParams->GetConsensus(), dep)};
441+
BOOST_CHECK(!(chain_all_vbits & dep_mask));
442+
chain_all_vbits |= dep_mask;
443+
check_computeblockversion(chainParams->GetConsensus(), dep);
448444
}
449445
}
450446

0 commit comments

Comments
 (0)