@@ -268,6 +268,12 @@ void check_computeblockversion(VersionBitsCache& versionbitscache, const Consens
268268 int64_t nStartTime = params.vDeployments [dep].nStartTime ;
269269 int64_t nTimeout = params.vDeployments [dep].nTimeout ;
270270 int min_activation_height = params.vDeployments [dep].min_activation_height ;
271+ uint32_t period = params.vDeployments [dep].period ;
272+ uint32_t threshold = params.vDeployments [dep].threshold ;
273+
274+ BOOST_REQUIRE (period > 0 ); // no division by zero, thankyou
275+ BOOST_REQUIRE (0 < threshold); // must be able to have a window that doesn't activate
276+ BOOST_REQUIRE (threshold < period); // must be able to have a window that does activate
271277
272278 // should not be any signalling for first block
273279 BOOST_CHECK_EQUAL (versionbitscache.ComputeBlockVersion (nullptr , params), VERSIONBITS_TOP_BITS);
@@ -289,7 +295,7 @@ void check_computeblockversion(VersionBitsCache& versionbitscache, const Consens
289295 BOOST_REQUIRE (((1 << bit) & VERSIONBITS_TOP_MASK) == 0 );
290296 BOOST_REQUIRE (min_activation_height >= 0 );
291297 // Check min_activation_height is on a retarget boundary
292- BOOST_REQUIRE_EQUAL (min_activation_height % params. nMinerConfirmationWindow , 0U );
298+ BOOST_REQUIRE_EQUAL (min_activation_height % period , 0U );
293299
294300 const uint32_t bitmask{versionbitscache.Mask (params, dep)};
295301 BOOST_CHECK_EQUAL (bitmask, uint32_t {1 } << bit);
@@ -309,44 +315,44 @@ void check_computeblockversion(VersionBitsCache& versionbitscache, const Consens
309315 // since CBlockIndex::nTime is uint32_t we can't represent any
310316 // earlier time, so will transition from DEFINED to STARTED at the
311317 // end of the first period by mining blocks at nTime == 0
312- lastBlock = firstChain.Mine (params. nMinerConfirmationWindow - 1 , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
318+ lastBlock = firstChain.Mine (period - 1 , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
313319 BOOST_CHECK_EQUAL (versionbitscache.ComputeBlockVersion (lastBlock, params) & (1 << bit), 0 );
314- lastBlock = firstChain.Mine (params. nMinerConfirmationWindow , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
320+ lastBlock = firstChain.Mine (period , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
315321 BOOST_CHECK ((versionbitscache.ComputeBlockVersion (lastBlock, params) & (1 << bit)) != 0 );
316322 // then we'll keep mining at nStartTime...
317323 } else {
318324 // use a time 1s earlier than start time to check we stay DEFINED
319325 --nTime;
320326
321327 // Start generating blocks before nStartTime
322- lastBlock = firstChain.Mine (params. nMinerConfirmationWindow , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
328+ lastBlock = firstChain.Mine (period , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
323329 BOOST_CHECK_EQUAL (versionbitscache.ComputeBlockVersion (lastBlock, params) & (1 << bit), 0 );
324330
325331 // Mine more blocks (4 less than the adjustment period) at the old time, and check that CBV isn't setting the bit yet.
326- for (uint32_t i = 1 ; i < params. nMinerConfirmationWindow - 4 ; i++) {
327- lastBlock = firstChain.Mine (params. nMinerConfirmationWindow + i, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
332+ for (uint32_t i = 1 ; i < period - 4 ; i++) {
333+ lastBlock = firstChain.Mine (period + i, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
328334 BOOST_CHECK_EQUAL (versionbitscache.ComputeBlockVersion (lastBlock, params) & (1 << bit), 0 );
329335 }
330336 // Now mine 5 more blocks at the start time -- MTP should not have passed yet, so
331337 // CBV should still not yet set the bit.
332338 nTime = nStartTime;
333- for (uint32_t i = params. nMinerConfirmationWindow - 4 ; i <= params. nMinerConfirmationWindow ; i++) {
334- lastBlock = firstChain.Mine (params. nMinerConfirmationWindow + i, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
339+ for (uint32_t i = period - 4 ; i <= period ; i++) {
340+ lastBlock = firstChain.Mine (period + i, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
335341 BOOST_CHECK_EQUAL (versionbitscache.ComputeBlockVersion (lastBlock, params) & (1 << bit), 0 );
336342 }
337343 // Next we will advance to the next period and transition to STARTED,
338344 }
339345
340- lastBlock = firstChain.Mine (params. nMinerConfirmationWindow * 3 , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
346+ lastBlock = firstChain.Mine (period * 3 , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
341347 // so ComputeBlockVersion should now set the bit,
342348 BOOST_CHECK ((versionbitscache.ComputeBlockVersion (lastBlock, params) & (1 << bit)) != 0 );
343349 // and should also be using the VERSIONBITS_TOP_BITS.
344350 BOOST_CHECK_EQUAL (versionbitscache.ComputeBlockVersion (lastBlock, params) & VERSIONBITS_TOP_MASK, VERSIONBITS_TOP_BITS);
345351
346352 // Check that ComputeBlockVersion will set the bit until nTimeout
347353 nTime += 600 ;
348- uint32_t blocksToMine = params. nMinerConfirmationWindow * 2 ; // test blocks for up to 2 time periods
349- uint32_t nHeight = params. nMinerConfirmationWindow * 3 ;
354+ uint32_t blocksToMine = period * 2 ; // test blocks for up to 2 time periods
355+ uint32_t nHeight = period * 3 ;
350356 // These blocks are all before nTimeout is reached.
351357 while (nTime < nTimeout && blocksToMine > 0 ) {
352358 lastBlock = firstChain.Mine (nHeight+1 , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
@@ -363,15 +369,15 @@ void check_computeblockversion(VersionBitsCache& versionbitscache, const Consens
363369 nTime = nTimeout;
364370
365371 // finish the last period before we start timing out
366- while (nHeight % params. nMinerConfirmationWindow != 0 ) {
372+ while (nHeight % period != 0 ) {
367373 lastBlock = firstChain.Mine (nHeight+1 , nTime - 1 , VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
368374 BOOST_CHECK ((versionbitscache.ComputeBlockVersion (lastBlock, params) & (1 << bit)) != 0 );
369375 nHeight += 1 ;
370376 }
371377
372378 // FAILED is only triggered at the end of a period, so CBV should be setting
373379 // the bit until the period transition.
374- for (uint32_t i = 0 ; i < params. nMinerConfirmationWindow - 1 ; i++) {
380+ for (uint32_t i = 0 ; i < period - 1 ; i++) {
375381 lastBlock = firstChain.Mine (nHeight+1 , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
376382 BOOST_CHECK ((versionbitscache.ComputeBlockVersion (lastBlock, params) & (1 << bit)) != 0 );
377383 nHeight += 1 ;
@@ -388,20 +394,20 @@ void check_computeblockversion(VersionBitsCache& versionbitscache, const Consens
388394
389395 // Mine one period worth of blocks, and check that the bit will be on for the
390396 // next period.
391- lastBlock = secondChain.Mine (params. nMinerConfirmationWindow , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
397+ lastBlock = secondChain.Mine (period , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
392398 BOOST_CHECK ((versionbitscache.ComputeBlockVersion (lastBlock, params) & (1 << bit)) != 0 );
393399
394400 // Mine another period worth of blocks, signaling the new bit.
395- lastBlock = secondChain.Mine (params. nMinerConfirmationWindow * 2 , nTime, VERSIONBITS_TOP_BITS | (1 <<bit)).Tip ();
401+ lastBlock = secondChain.Mine (period * 2 , nTime, VERSIONBITS_TOP_BITS | (1 <<bit)).Tip ();
396402 // After one period of setting the bit on each block, it should have locked in.
397403 // We keep setting the bit for one more period though, until activation.
398404 BOOST_CHECK ((versionbitscache.ComputeBlockVersion (lastBlock, params) & (1 << bit)) != 0 );
399405
400406 // Now check that we keep mining the block until the end of this period, and
401407 // then stop at the beginning of the next period.
402- lastBlock = secondChain.Mine ((params. nMinerConfirmationWindow * 3 ) - 1 , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
408+ lastBlock = secondChain.Mine ((period * 3 ) - 1 , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
403409 BOOST_CHECK ((versionbitscache.ComputeBlockVersion (lastBlock, params) & (1 << bit)) != 0 );
404- lastBlock = secondChain.Mine (params. nMinerConfirmationWindow * 3 , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
410+ lastBlock = secondChain.Mine (period * 3 , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
405411
406412 if (lastBlock->nHeight + 1 < min_activation_height) {
407413 // check signalling continues while min_activation_height is not reached
0 commit comments