@@ -255,7 +255,8 @@ BOOST_AUTO_TEST_CASE(versionbits_test)
255
255
}
256
256
257
257
struct BlockVersionTest : BasicTestingSetup {
258
- /* * Check that ComputeBlockVersion will set the appropriate bit correctly */
258
+ /* * Check that ComputeBlockVersion will set the appropriate bit correctly
259
+ * Also checks IsActiveAfter() behaviour */
259
260
void check_computeblockversion (VersionBitsCache& versionbitscache, const Consensus::Params& params, Consensus::DeploymentPos dep)
260
261
{
261
262
// Clear the cache every time
@@ -279,6 +280,11 @@ void check_computeblockversion(VersionBitsCache& versionbitscache, const Consens
279
280
if (nStartTime == Consensus::BIP9Deployment::ALWAYS_ACTIVE ||
280
281
nStartTime == Consensus::BIP9Deployment::NEVER_ACTIVE)
281
282
{
283
+ if (nStartTime == Consensus::BIP9Deployment::ALWAYS_ACTIVE) {
284
+ BOOST_CHECK (versionbitscache.IsActiveAfter (nullptr , params, dep));
285
+ } else {
286
+ BOOST_CHECK (!versionbitscache.IsActiveAfter (nullptr , params, dep));
287
+ }
282
288
BOOST_CHECK_EQUAL (min_activation_height, 0 );
283
289
BOOST_CHECK_EQUAL (nTimeout, Consensus::BIP9Deployment::NO_TIMEOUT);
284
290
return ;
@@ -311,8 +317,10 @@ void check_computeblockversion(VersionBitsCache& versionbitscache, const Consens
311
317
// end of the first period by mining blocks at nTime == 0
312
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 );
320
+ BOOST_CHECK (!versionbitscache.IsActiveAfter (lastBlock, params, dep));
314
321
lastBlock = firstChain.Mine (period, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
315
322
BOOST_CHECK ((versionbitscache.ComputeBlockVersion (lastBlock, params) & (1 << bit)) != 0 );
323
+ BOOST_CHECK (!versionbitscache.IsActiveAfter (lastBlock, params, dep));
316
324
// then we'll keep mining at nStartTime...
317
325
} else {
318
326
// use a time 1s earlier than start time to check we stay DEFINED
@@ -321,18 +329,21 @@ void check_computeblockversion(VersionBitsCache& versionbitscache, const Consens
321
329
// Start generating blocks before nStartTime
322
330
lastBlock = firstChain.Mine (period, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
323
331
BOOST_CHECK_EQUAL (versionbitscache.ComputeBlockVersion (lastBlock, params) & (1 << bit), 0 );
332
+ BOOST_CHECK (!versionbitscache.IsActiveAfter (lastBlock, params, dep));
324
333
325
334
// Mine more blocks (4 less than the adjustment period) at the old time, and check that CBV isn't setting the bit yet.
326
335
for (uint32_t i = 1 ; i < period - 4 ; i++) {
327
336
lastBlock = firstChain.Mine (period + i, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
328
337
BOOST_CHECK_EQUAL (versionbitscache.ComputeBlockVersion (lastBlock, params) & (1 << bit), 0 );
338
+ BOOST_CHECK (!versionbitscache.IsActiveAfter (lastBlock, params, dep));
329
339
}
330
340
// Now mine 5 more blocks at the start time -- MTP should not have passed yet, so
331
341
// CBV should still not yet set the bit.
332
342
nTime = nStartTime;
333
343
for (uint32_t i = period - 4 ; i <= period; i++) {
334
344
lastBlock = firstChain.Mine (period + i, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
335
345
BOOST_CHECK_EQUAL (versionbitscache.ComputeBlockVersion (lastBlock, params) & (1 << bit), 0 );
346
+ BOOST_CHECK (!versionbitscache.IsActiveAfter (lastBlock, params, dep));
336
347
}
337
348
// Next we will advance to the next period and transition to STARTED,
338
349
}
@@ -342,6 +353,7 @@ void check_computeblockversion(VersionBitsCache& versionbitscache, const Consens
342
353
BOOST_CHECK ((versionbitscache.ComputeBlockVersion (lastBlock, params) & (1 << bit)) != 0 );
343
354
// and should also be using the VERSIONBITS_TOP_BITS.
344
355
BOOST_CHECK_EQUAL (versionbitscache.ComputeBlockVersion (lastBlock, params) & VERSIONBITS_TOP_MASK, VERSIONBITS_TOP_BITS);
356
+ BOOST_CHECK (!versionbitscache.IsActiveAfter (lastBlock, params, dep));
345
357
346
358
// Check that ComputeBlockVersion will set the bit until nTimeout
347
359
nTime += 600 ;
@@ -352,6 +364,7 @@ void check_computeblockversion(VersionBitsCache& versionbitscache, const Consens
352
364
lastBlock = firstChain.Mine (nHeight+1 , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
353
365
BOOST_CHECK ((versionbitscache.ComputeBlockVersion (lastBlock, params) & (1 << bit)) != 0 );
354
366
BOOST_CHECK_EQUAL (versionbitscache.ComputeBlockVersion (lastBlock, params) & VERSIONBITS_TOP_MASK, VERSIONBITS_TOP_BITS);
367
+ BOOST_CHECK (!versionbitscache.IsActiveAfter (lastBlock, params, dep));
355
368
blocksToMine--;
356
369
nTime += 600 ;
357
370
nHeight += 1 ;
@@ -366,6 +379,7 @@ void check_computeblockversion(VersionBitsCache& versionbitscache, const Consens
366
379
while (nHeight % period != 0 ) {
367
380
lastBlock = firstChain.Mine (nHeight+1 , nTime - 1 , VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
368
381
BOOST_CHECK ((versionbitscache.ComputeBlockVersion (lastBlock, params) & (1 << bit)) != 0 );
382
+ BOOST_CHECK (!versionbitscache.IsActiveAfter (lastBlock, params, dep));
369
383
nHeight += 1 ;
370
384
}
371
385
@@ -374,11 +388,13 @@ void check_computeblockversion(VersionBitsCache& versionbitscache, const Consens
374
388
for (uint32_t i = 0 ; i < period - 1 ; i++) {
375
389
lastBlock = firstChain.Mine (nHeight+1 , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
376
390
BOOST_CHECK ((versionbitscache.ComputeBlockVersion (lastBlock, params) & (1 << bit)) != 0 );
391
+ BOOST_CHECK (!versionbitscache.IsActiveAfter (lastBlock, params, dep));
377
392
nHeight += 1 ;
378
393
}
379
394
// The next block should trigger no longer setting the bit.
380
395
lastBlock = firstChain.Mine (nHeight+1 , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
381
396
BOOST_CHECK_EQUAL (versionbitscache.ComputeBlockVersion (lastBlock, params) & (1 << bit), 0 );
397
+ BOOST_CHECK (!versionbitscache.IsActiveAfter (lastBlock, params, dep));
382
398
}
383
399
384
400
// On a new chain:
@@ -390,29 +406,34 @@ void check_computeblockversion(VersionBitsCache& versionbitscache, const Consens
390
406
// next period.
391
407
lastBlock = secondChain.Mine (period, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
392
408
BOOST_CHECK ((versionbitscache.ComputeBlockVersion (lastBlock, params) & (1 << bit)) != 0 );
409
+ BOOST_CHECK (!versionbitscache.IsActiveAfter (lastBlock, params, dep));
393
410
394
411
// Mine another period worth of blocks, signaling the new bit.
395
412
lastBlock = secondChain.Mine (period * 2 , nTime, VERSIONBITS_TOP_BITS | (1 <<bit)).Tip ();
396
413
// After one period of setting the bit on each block, it should have locked in.
397
414
// We keep setting the bit for one more period though, until activation.
398
415
BOOST_CHECK ((versionbitscache.ComputeBlockVersion (lastBlock, params) & (1 << bit)) != 0 );
416
+ BOOST_CHECK (!versionbitscache.IsActiveAfter (lastBlock, params, dep));
399
417
400
418
// Now check that we keep mining the block until the end of this period, and
401
419
// then stop at the beginning of the next period.
402
420
lastBlock = secondChain.Mine ((period * 3 ) - 1 , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
403
421
BOOST_CHECK ((versionbitscache.ComputeBlockVersion (lastBlock, params) & (1 << bit)) != 0 );
422
+ BOOST_CHECK (!versionbitscache.IsActiveAfter (lastBlock, params, dep));
404
423
lastBlock = secondChain.Mine (period * 3 , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
405
424
406
425
if (lastBlock->nHeight + 1 < min_activation_height) {
407
426
// check signalling continues while min_activation_height is not reached
408
427
lastBlock = secondChain.Mine (min_activation_height - 1 , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
409
428
BOOST_CHECK ((versionbitscache.ComputeBlockVersion (lastBlock, params) & (1 << bit)) != 0 );
429
+ BOOST_CHECK (!versionbitscache.IsActiveAfter (lastBlock, params, dep));
410
430
// then reach min_activation_height, which was already REQUIRE'd to start a new period
411
431
lastBlock = secondChain.Mine (min_activation_height, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
412
432
}
413
433
414
434
// Check that we don't signal after activation
415
435
BOOST_CHECK_EQUAL (versionbitscache.ComputeBlockVersion (lastBlock, params) & (1 << bit), 0 );
436
+ BOOST_CHECK (versionbitscache.IsActiveAfter (lastBlock, params, dep));
416
437
}
417
438
}; // struct BlockVersionTest
418
439
0 commit comments