Skip to content

Commit de77cbc

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#21691: test: Check that no versionbits are re-used
fa8eaee test: Run versionbits_sanity for all chains (MarcoFalke) faec1e9 test: Address outstanding versionbits_test feedback (MarcoFalke) fad4167 test: Check that no versionbits are re-used (MarcoFalke) Pull request description: ACKs for top commit: jnewbery: Code review ACK fa8eaee ajtowns: ACK fa8eaee code review only Tree-SHA512: e99ffcca8970921fd07fa9e04cf1ea2515a317409865d34ddfd70be0f0b0616b29d1fad58262d96a3c3418c0cf7018a6a955802a178b8f78f6ecfaa30a37d91c
2 parents a839303 + fa8eaee commit de77cbc

File tree

1 file changed

+24
-40
lines changed

1 file changed

+24
-40
lines changed

src/test/versionbits_tests.cpp

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,9 @@ class VersionBitsTester
8181
TestNeverActiveConditionChecker checker_never[CHECKERS];
8282

8383
// Test counter (to identify failures)
84-
int num;
84+
int num{1000};
8585

8686
public:
87-
VersionBitsTester() : num(1000) {}
88-
8987
VersionBitsTester& Reset() {
9088
// Have each group of tests be counted by the 1000s part, starting at 1000
9189
num = num - (num % 1000) + 1000;
@@ -257,39 +255,6 @@ BOOST_AUTO_TEST_CASE(versionbits_test)
257255
}
258256
}
259257

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-
293258
/** Check that ComputeBlockVersion will set the appropriate bit correctly */
294259
static void check_computeblockversion(const Consensus::Params& params, Consensus::DeploymentPos dep)
295260
{
@@ -305,16 +270,25 @@ static void check_computeblockversion(const Consensus::Params& params, Consensus
305270
BOOST_CHECK_EQUAL(ComputeBlockVersion(nullptr, params), VERSIONBITS_TOP_BITS);
306271

307272
// 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+
}
310279

311280
BOOST_REQUIRE(nStartTime < nTimeout);
312281
BOOST_REQUIRE(nStartTime >= 0);
313282
BOOST_REQUIRE(nTimeout <= std::numeric_limits<uint32_t>::max() || nTimeout == Consensus::BIP9Deployment::NO_TIMEOUT);
314283
BOOST_REQUIRE(0 <= bit && bit < 32);
284+
// Make sure that no deployment tries to set an invalid bit.
315285
BOOST_REQUIRE(((1 << bit) & VERSIONBITS_TOP_MASK) == 0);
316286
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);
318292

319293
// In the first chain, test that the bit is set by CBV until it has failed.
320294
// In the second chain, test the bit is set by CBV while STARTED and
@@ -443,8 +417,18 @@ BOOST_AUTO_TEST_CASE(versionbits_computeblockversion)
443417
// ACTIVE and FAILED states in roughly the way we expect
444418
for (const auto& chain_name : {CBaseChainParams::MAIN, CBaseChainParams::TESTNET, CBaseChainParams::SIGNET, CBaseChainParams::REGTEST}) {
445419
const auto chainParams = CreateChainParams(*m_node.args, chain_name);
420+
uint32_t chain_all_vbits{0};
446421
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);
448432
}
449433
}
450434

0 commit comments

Comments
 (0)