15
15
/* Define a virtual block time, one block per 10 minutes after Nov 14 2014, 0:55:36am */
16
16
static int32_t TestTime (int nHeight) { return 1415926536 + 600 * nHeight; }
17
17
18
- static int32_t ComputeBlockVersion (const CBlockIndex* pindexPrev, const Consensus::Params& params)
19
- {
20
- return g_versionbitscache.ComputeBlockVersion (pindexPrev, params);
21
- }
22
-
23
18
static const std::string StateName (ThresholdState state)
24
19
{
25
20
switch (state) {
@@ -273,7 +268,7 @@ static void check_computeblockversion(const Consensus::Params& params, Consensus
273
268
int min_activation_height = params.vDeployments [dep].min_activation_height ;
274
269
275
270
// should not be any signalling for first block
276
- BOOST_CHECK_EQUAL (ComputeBlockVersion (nullptr , params), VERSIONBITS_TOP_BITS);
271
+ BOOST_CHECK_EQUAL (g_versionbitscache. ComputeBlockVersion (nullptr , params), VERSIONBITS_TOP_BITS);
277
272
278
273
// always/never active deployments shouldn't need to be tested further
279
274
if (nStartTime == Consensus::BIP9Deployment::ALWAYS_ACTIVE ||
@@ -312,38 +307,38 @@ static void check_computeblockversion(const Consensus::Params& params, Consensus
312
307
// earlier time, so will transition from DEFINED to STARTED at the
313
308
// end of the first period by mining blocks at nTime == 0
314
309
lastBlock = firstChain.Mine (params.nMinerConfirmationWindow - 1 , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
315
- BOOST_CHECK_EQUAL (ComputeBlockVersion (lastBlock, params) & (1 << bit), 0 );
310
+ BOOST_CHECK_EQUAL (g_versionbitscache. ComputeBlockVersion (lastBlock, params) & (1 << bit), 0 );
316
311
lastBlock = firstChain.Mine (params.nMinerConfirmationWindow , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
317
- BOOST_CHECK ((ComputeBlockVersion (lastBlock, params) & (1 << bit)) != 0 );
312
+ BOOST_CHECK ((g_versionbitscache. ComputeBlockVersion (lastBlock, params) & (1 << bit)) != 0 );
318
313
// then we'll keep mining at nStartTime...
319
314
} else {
320
315
// use a time 1s earlier than start time to check we stay DEFINED
321
316
--nTime;
322
317
323
318
// Start generating blocks before nStartTime
324
319
lastBlock = firstChain.Mine (params.nMinerConfirmationWindow , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
325
- BOOST_CHECK_EQUAL (ComputeBlockVersion (lastBlock, params) & (1 << bit), 0 );
320
+ BOOST_CHECK_EQUAL (g_versionbitscache. ComputeBlockVersion (lastBlock, params) & (1 << bit), 0 );
326
321
327
322
// Mine more blocks (4 less than the adjustment period) at the old time, and check that CBV isn't setting the bit yet.
328
323
for (uint32_t i = 1 ; i < params.nMinerConfirmationWindow - 4 ; i++) {
329
324
lastBlock = firstChain.Mine (params.nMinerConfirmationWindow + i, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
330
- BOOST_CHECK_EQUAL (ComputeBlockVersion (lastBlock, params) & (1 << bit), 0 );
325
+ BOOST_CHECK_EQUAL (g_versionbitscache. ComputeBlockVersion (lastBlock, params) & (1 << bit), 0 );
331
326
}
332
327
// Now mine 5 more blocks at the start time -- MTP should not have passed yet, so
333
328
// CBV should still not yet set the bit.
334
329
nTime = nStartTime;
335
330
for (uint32_t i = params.nMinerConfirmationWindow - 4 ; i <= params.nMinerConfirmationWindow ; i++) {
336
331
lastBlock = firstChain.Mine (params.nMinerConfirmationWindow + i, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
337
- BOOST_CHECK_EQUAL (ComputeBlockVersion (lastBlock, params) & (1 << bit), 0 );
332
+ BOOST_CHECK_EQUAL (g_versionbitscache. ComputeBlockVersion (lastBlock, params) & (1 << bit), 0 );
338
333
}
339
334
// Next we will advance to the next period and transition to STARTED,
340
335
}
341
336
342
337
lastBlock = firstChain.Mine (params.nMinerConfirmationWindow * 3 , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
343
338
// so ComputeBlockVersion should now set the bit,
344
- BOOST_CHECK ((ComputeBlockVersion (lastBlock, params) & (1 << bit)) != 0 );
339
+ BOOST_CHECK ((g_versionbitscache. ComputeBlockVersion (lastBlock, params) & (1 << bit)) != 0 );
345
340
// and should also be using the VERSIONBITS_TOP_BITS.
346
- BOOST_CHECK_EQUAL (ComputeBlockVersion (lastBlock, params) & VERSIONBITS_TOP_MASK, VERSIONBITS_TOP_BITS);
341
+ BOOST_CHECK_EQUAL (g_versionbitscache. ComputeBlockVersion (lastBlock, params) & VERSIONBITS_TOP_MASK, VERSIONBITS_TOP_BITS);
347
342
348
343
// Check that ComputeBlockVersion will set the bit until nTimeout
349
344
nTime += 600 ;
@@ -352,8 +347,8 @@ static void check_computeblockversion(const Consensus::Params& params, Consensus
352
347
// These blocks are all before nTimeout is reached.
353
348
while (nTime < nTimeout && blocksToMine > 0 ) {
354
349
lastBlock = firstChain.Mine (nHeight+1 , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
355
- BOOST_CHECK ((ComputeBlockVersion (lastBlock, params) & (1 << bit)) != 0 );
356
- BOOST_CHECK_EQUAL (ComputeBlockVersion (lastBlock, params) & VERSIONBITS_TOP_MASK, VERSIONBITS_TOP_BITS);
350
+ BOOST_CHECK ((g_versionbitscache. ComputeBlockVersion (lastBlock, params) & (1 << bit)) != 0 );
351
+ BOOST_CHECK_EQUAL (g_versionbitscache. ComputeBlockVersion (lastBlock, params) & VERSIONBITS_TOP_MASK, VERSIONBITS_TOP_BITS);
357
352
blocksToMine--;
358
353
nTime += 600 ;
359
354
nHeight += 1 ;
@@ -367,20 +362,20 @@ static void check_computeblockversion(const Consensus::Params& params, Consensus
367
362
// finish the last period before we start timing out
368
363
while (nHeight % params.nMinerConfirmationWindow != 0 ) {
369
364
lastBlock = firstChain.Mine (nHeight+1 , nTime - 1 , VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
370
- BOOST_CHECK ((ComputeBlockVersion (lastBlock, params) & (1 << bit)) != 0 );
365
+ BOOST_CHECK ((g_versionbitscache. ComputeBlockVersion (lastBlock, params) & (1 << bit)) != 0 );
371
366
nHeight += 1 ;
372
367
}
373
368
374
369
// FAILED is only triggered at the end of a period, so CBV should be setting
375
370
// the bit until the period transition.
376
371
for (uint32_t i = 0 ; i < params.nMinerConfirmationWindow - 1 ; i++) {
377
372
lastBlock = firstChain.Mine (nHeight+1 , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
378
- BOOST_CHECK ((ComputeBlockVersion (lastBlock, params) & (1 << bit)) != 0 );
373
+ BOOST_CHECK ((g_versionbitscache. ComputeBlockVersion (lastBlock, params) & (1 << bit)) != 0 );
379
374
nHeight += 1 ;
380
375
}
381
376
// The next block should trigger no longer setting the bit.
382
377
lastBlock = firstChain.Mine (nHeight+1 , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
383
- BOOST_CHECK_EQUAL (ComputeBlockVersion (lastBlock, params) & (1 << bit), 0 );
378
+ BOOST_CHECK_EQUAL (g_versionbitscache. ComputeBlockVersion (lastBlock, params) & (1 << bit), 0 );
384
379
}
385
380
386
381
// On a new chain:
@@ -391,30 +386,30 @@ static void check_computeblockversion(const Consensus::Params& params, Consensus
391
386
// Mine one period worth of blocks, and check that the bit will be on for the
392
387
// next period.
393
388
lastBlock = secondChain.Mine (params.nMinerConfirmationWindow , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
394
- BOOST_CHECK ((ComputeBlockVersion (lastBlock, params) & (1 << bit)) != 0 );
389
+ BOOST_CHECK ((g_versionbitscache. ComputeBlockVersion (lastBlock, params) & (1 << bit)) != 0 );
395
390
396
391
// Mine another period worth of blocks, signaling the new bit.
397
392
lastBlock = secondChain.Mine (params.nMinerConfirmationWindow * 2 , nTime, VERSIONBITS_TOP_BITS | (1 <<bit)).Tip ();
398
393
// After one period of setting the bit on each block, it should have locked in.
399
394
// We keep setting the bit for one more period though, until activation.
400
- BOOST_CHECK ((ComputeBlockVersion (lastBlock, params) & (1 << bit)) != 0 );
395
+ BOOST_CHECK ((g_versionbitscache. ComputeBlockVersion (lastBlock, params) & (1 << bit)) != 0 );
401
396
402
397
// Now check that we keep mining the block until the end of this period, and
403
398
// then stop at the beginning of the next period.
404
399
lastBlock = secondChain.Mine ((params.nMinerConfirmationWindow * 3 ) - 1 , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
405
- BOOST_CHECK ((ComputeBlockVersion (lastBlock, params) & (1 << bit)) != 0 );
400
+ BOOST_CHECK ((g_versionbitscache. ComputeBlockVersion (lastBlock, params) & (1 << bit)) != 0 );
406
401
lastBlock = secondChain.Mine (params.nMinerConfirmationWindow * 3 , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
407
402
408
403
if (lastBlock->nHeight + 1 < min_activation_height) {
409
404
// check signalling continues while min_activation_height is not reached
410
405
lastBlock = secondChain.Mine (min_activation_height - 1 , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
411
- BOOST_CHECK ((ComputeBlockVersion (lastBlock, params) & (1 << bit)) != 0 );
406
+ BOOST_CHECK ((g_versionbitscache. ComputeBlockVersion (lastBlock, params) & (1 << bit)) != 0 );
412
407
// then reach min_activation_height, which was already REQUIRE'd to start a new period
413
408
lastBlock = secondChain.Mine (min_activation_height, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
414
409
}
415
410
416
411
// Check that we don't signal after activation
417
- BOOST_CHECK_EQUAL (ComputeBlockVersion (lastBlock, params) & (1 << bit), 0 );
412
+ BOOST_CHECK_EQUAL (g_versionbitscache. ComputeBlockVersion (lastBlock, params) & (1 << bit), 0 );
418
413
}
419
414
420
415
BOOST_AUTO_TEST_CASE (versionbits_computeblockversion)
0 commit comments