@@ -271,35 +271,35 @@ BOOST_AUTO_TEST_CASE(versionbits_computeblockversion)
271
271
// Before MedianTimePast of the chain has crossed nStartTime, the bit
272
272
// should not be set.
273
273
CBlockIndex *lastBlock = nullptr ;
274
- lastBlock = firstChain.Mine (2016 , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
274
+ lastBlock = firstChain.Mine (mainnetParams. nMinerConfirmationWindow , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
275
275
BOOST_CHECK_EQUAL (ComputeBlockVersion (lastBlock, mainnetParams) & (1 <<bit), 0 );
276
276
277
- // Mine 2011 more blocks at the old time, and check that CBV isn't setting the bit yet.
278
- for (int i= 1 ; i< 2012 ; i++) {
279
- lastBlock = firstChain.Mine (2016 + i, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
277
+ // Mine more blocks (4 less than the adjustment period) at the old time, and check that CBV isn't setting the bit yet.
278
+ for (uint32_t i = 1 ; i < mainnetParams. nMinerConfirmationWindow - 4 ; i++) {
279
+ lastBlock = firstChain.Mine (mainnetParams. nMinerConfirmationWindow + i, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
280
280
// This works because VERSIONBITS_LAST_OLD_BLOCK_VERSION happens
281
281
// to be 4, and the bit we're testing happens to be bit 28.
282
282
BOOST_CHECK_EQUAL (ComputeBlockVersion (lastBlock, mainnetParams) & (1 <<bit), 0 );
283
283
}
284
284
// Now mine 5 more blocks at the start time -- MTP should not have passed yet, so
285
285
// CBV should still not yet set the bit.
286
286
nTime = nStartTime;
287
- for (int i= 2012 ; i<= 2016 ; i++) {
288
- lastBlock = firstChain.Mine (2016 + i, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
287
+ for (uint32_t i = mainnetParams. nMinerConfirmationWindow - 4 ; i <= mainnetParams. nMinerConfirmationWindow ; i++) {
288
+ lastBlock = firstChain.Mine (mainnetParams. nMinerConfirmationWindow + i, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
289
289
BOOST_CHECK_EQUAL (ComputeBlockVersion (lastBlock, mainnetParams) & (1 <<bit), 0 );
290
290
}
291
291
292
292
// Advance to the next period and transition to STARTED,
293
- lastBlock = firstChain.Mine (6048 , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
293
+ lastBlock = firstChain.Mine (mainnetParams. nMinerConfirmationWindow * 3 , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
294
294
// so ComputeBlockVersion should now set the bit,
295
295
BOOST_CHECK ((ComputeBlockVersion (lastBlock, mainnetParams) & (1 <<bit)) != 0 );
296
296
// and should also be using the VERSIONBITS_TOP_BITS.
297
297
BOOST_CHECK_EQUAL (ComputeBlockVersion (lastBlock, mainnetParams) & VERSIONBITS_TOP_MASK, VERSIONBITS_TOP_BITS);
298
298
299
299
// Check that ComputeBlockVersion will set the bit until nTimeout
300
300
nTime += 600 ;
301
- int blocksToMine = 4032 ; // test blocks for up to 2 time periods
302
- int nHeight = 6048 ;
301
+ uint32_t blocksToMine = mainnetParams. nMinerConfirmationWindow * 2 ; // test blocks for up to 2 time periods
302
+ uint32_t nHeight = mainnetParams. nMinerConfirmationWindow * 3 ;
303
303
// These blocks are all before nTimeout is reached.
304
304
while (nTime < nTimeout && blocksToMine > 0 ) {
305
305
lastBlock = firstChain.Mine (nHeight+1 , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
@@ -313,7 +313,7 @@ BOOST_AUTO_TEST_CASE(versionbits_computeblockversion)
313
313
nTime = nTimeout;
314
314
// FAILED is only triggered at the end of a period, so CBV should be setting
315
315
// the bit until the period transition.
316
- for (int i= 0 ; i< 2015 ; i++) {
316
+ for (uint32_t i = 0 ; i < mainnetParams. nMinerConfirmationWindow - 1 ; i++) {
317
317
lastBlock = firstChain.Mine (nHeight+1 , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
318
318
BOOST_CHECK ((ComputeBlockVersion (lastBlock, mainnetParams) & (1 <<bit)) != 0 );
319
319
nHeight += 1 ;
@@ -329,20 +329,20 @@ BOOST_AUTO_TEST_CASE(versionbits_computeblockversion)
329
329
330
330
// Mine one period worth of blocks, and check that the bit will be on for the
331
331
// next period.
332
- lastBlock = secondChain.Mine (2016 , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
332
+ lastBlock = secondChain.Mine (mainnetParams. nMinerConfirmationWindow , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
333
333
BOOST_CHECK ((ComputeBlockVersion (lastBlock, mainnetParams) & (1 <<bit)) != 0 );
334
334
335
335
// Mine another period worth of blocks, signaling the new bit.
336
- lastBlock = secondChain.Mine (4032 , nTime, VERSIONBITS_TOP_BITS | (1 <<bit)).Tip ();
336
+ lastBlock = secondChain.Mine (mainnetParams. nMinerConfirmationWindow * 2 , nTime, VERSIONBITS_TOP_BITS | (1 <<bit)).Tip ();
337
337
// After one period of setting the bit on each block, it should have locked in.
338
338
// We keep setting the bit for one more period though, until activation.
339
339
BOOST_CHECK ((ComputeBlockVersion (lastBlock, mainnetParams) & (1 <<bit)) != 0 );
340
340
341
341
// Now check that we keep mining the block until the end of this period, and
342
342
// then stop at the beginning of the next period.
343
- lastBlock = secondChain.Mine (6047 , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
344
- BOOST_CHECK ((ComputeBlockVersion (lastBlock, mainnetParams) & (1 << bit)) != 0 );
345
- lastBlock = secondChain.Mine (6048 , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
343
+ lastBlock = secondChain.Mine ((mainnetParams. nMinerConfirmationWindow * 3 ) - 1 , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
344
+ BOOST_CHECK ((ComputeBlockVersion (lastBlock, mainnetParams) & (1 << bit)) != 0 );
345
+ lastBlock = secondChain.Mine (mainnetParams. nMinerConfirmationWindow * 3 , nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip ();
346
346
BOOST_CHECK_EQUAL (ComputeBlockVersion (lastBlock, mainnetParams) & (1 <<bit), 0 );
347
347
348
348
// Finally, verify that after a soft fork has activated, CBV no longer uses
0 commit comments