@@ -268,6 +268,12 @@ void check_computeblockversion(VersionBitsCache& versionbitscache, const Consens
268
268
int64_t nStartTime = params.vDeployments [dep].nStartTime ;
269
269
int64_t nTimeout = params.vDeployments [dep].nTimeout ;
270
270
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
271
277
272
278
// should not be any signalling for first block
273
279
BOOST_CHECK_EQUAL (versionbitscache.ComputeBlockVersion (nullptr , params), VERSIONBITS_TOP_BITS);
@@ -289,7 +295,7 @@ void check_computeblockversion(VersionBitsCache& versionbitscache, const Consens
289
295
BOOST_REQUIRE (((1 << bit) & VERSIONBITS_TOP_MASK) == 0 );
290
296
BOOST_REQUIRE (min_activation_height >= 0 );
291
297
// 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 );
293
299
294
300
const uint32_t bitmask{versionbitscache.Mask (params, dep)};
295
301
BOOST_CHECK_EQUAL (bitmask, uint32_t {1 } << bit);
@@ -309,44 +315,44 @@ void check_computeblockversion(VersionBitsCache& versionbitscache, const Consens
309
315
// since CBlockIndex::nTime is uint32_t we can't represent any
310
316
// earlier time, so will transition from DEFINED to STARTED at the
311
317
// 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 ();
313
319
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 ();
315
321
BOOST_CHECK ((versionbitscache.ComputeBlockVersion (lastBlock, params) & (1 << bit)) != 0 );
316
322
// then we'll keep mining at nStartTime...
317
323
} else {
318
324
// use a time 1s earlier than start time to check we stay DEFINED
319
325
--nTime;
320
326
321
327
// 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 ();
323
329
BOOST_CHECK_EQUAL (versionbitscache.ComputeBlockVersion (lastBlock, params) & (1 << bit), 0 );
324
330
325
331
// 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 ();
328
334
BOOST_CHECK_EQUAL (versionbitscache.ComputeBlockVersion (lastBlock, params) & (1 << bit), 0 );
329
335
}
330
336
// Now mine 5 more blocks at the start time -- MTP should not have passed yet, so
331
337
// CBV should still not yet set the bit.
332
338
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 ();
335
341
BOOST_CHECK_EQUAL (versionbitscache.ComputeBlockVersion (lastBlock, params) & (1 << bit), 0 );
336
342
}
337
343
// Next we will advance to the next period and transition to STARTED,
338
344
}
339
345
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 ();
341
347
// so ComputeBlockVersion should now set the bit,
342
348
BOOST_CHECK ((versionbitscache.ComputeBlockVersion (lastBlock, params) & (1 << bit)) != 0 );
343
349
// and should also be using the VERSIONBITS_TOP_BITS.
344
350
BOOST_CHECK_EQUAL (versionbitscache.ComputeBlockVersion (lastBlock, params) & VERSIONBITS_TOP_MASK, VERSIONBITS_TOP_BITS);
345
351
346
352
// Check that ComputeBlockVersion will set the bit until nTimeout
347
353
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 ;
350
356
// These blocks are all before nTimeout is reached.
351
357
while (nTime < nTimeout && blocksToMine > 0 ) {
352
358
lastBlock = firstChain.Mine (nHeight+1 , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
@@ -363,15 +369,15 @@ void check_computeblockversion(VersionBitsCache& versionbitscache, const Consens
363
369
nTime = nTimeout;
364
370
365
371
// finish the last period before we start timing out
366
- while (nHeight % params. nMinerConfirmationWindow != 0 ) {
372
+ while (nHeight % period != 0 ) {
367
373
lastBlock = firstChain.Mine (nHeight+1 , nTime - 1 , VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
368
374
BOOST_CHECK ((versionbitscache.ComputeBlockVersion (lastBlock, params) & (1 << bit)) != 0 );
369
375
nHeight += 1 ;
370
376
}
371
377
372
378
// FAILED is only triggered at the end of a period, so CBV should be setting
373
379
// 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++) {
375
381
lastBlock = firstChain.Mine (nHeight+1 , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
376
382
BOOST_CHECK ((versionbitscache.ComputeBlockVersion (lastBlock, params) & (1 << bit)) != 0 );
377
383
nHeight += 1 ;
@@ -388,20 +394,20 @@ void check_computeblockversion(VersionBitsCache& versionbitscache, const Consens
388
394
389
395
// Mine one period worth of blocks, and check that the bit will be on for the
390
396
// 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 ();
392
398
BOOST_CHECK ((versionbitscache.ComputeBlockVersion (lastBlock, params) & (1 << bit)) != 0 );
393
399
394
400
// 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 ();
396
402
// After one period of setting the bit on each block, it should have locked in.
397
403
// We keep setting the bit for one more period though, until activation.
398
404
BOOST_CHECK ((versionbitscache.ComputeBlockVersion (lastBlock, params) & (1 << bit)) != 0 );
399
405
400
406
// Now check that we keep mining the block until the end of this period, and
401
407
// 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 ();
403
409
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 ();
405
411
406
412
if (lastBlock->nHeight + 1 < min_activation_height) {
407
413
// check signalling continues while min_activation_height is not reached
0 commit comments