@@ -407,3 +407,38 @@ TEST(long_term_block_weight, long_growth_spike_and_drop)
407
407
ASSERT_GT (long_term_effective_median_block_weight, 300000 * 1.07 );
408
408
ASSERT_LT (long_term_effective_median_block_weight, 300000 * 1.09 );
409
409
}
410
+
411
+ TEST (long_term_block_weight, cache_matches_true_value)
412
+ {
413
+ PREFIX (16 );
414
+
415
+ // Add big blocks to increase the block weight limit
416
+ for (uint64_t h = 0 ; h <= 2000 ; ++h)
417
+ {
418
+ size_t w = bc->get_current_cumulative_block_weight_limit ();
419
+ uint64_t ltw = bc->get_next_long_term_block_weight (w);
420
+ bc->get_db ().add_block (std::make_pair (cryptonote::block (), " " ), w, ltw, h, h, {});
421
+ bc->update_next_cumulative_weight_limit ();
422
+ }
423
+
424
+ ASSERT_GT (bc->get_current_cumulative_block_weight_limit () * 10 /17 , 300000 );
425
+
426
+ // Add small blocks to the top of the chain
427
+ for (uint64_t h = 2000 ; h <= 5001 ; ++h)
428
+ {
429
+ size_t w = (bc->get_current_cumulative_block_weight_median () * 10 /17 ) - 1000 ;
430
+ uint64_t ltw = bc->get_next_long_term_block_weight (w);
431
+ bc->get_db ().add_block (std::make_pair (cryptonote::block (), " " ), w, ltw, h, h, {});
432
+ bc->update_next_cumulative_weight_limit ();
433
+ }
434
+
435
+ // get the weight limit
436
+ uint64_t weight_limit = bc->get_current_cumulative_block_weight_limit ();
437
+ // refresh the cache
438
+ bc->m_long_term_block_weights_cache_rolling_median .clear ();
439
+ bc->get_long_term_block_weight_median (bc->get_db ().height () - TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW, TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW);
440
+ bc->update_next_cumulative_weight_limit ();
441
+
442
+ // make sure the weight limit is the same
443
+ ASSERT_EQ (weight_limit, bc->get_current_cumulative_block_weight_limit ());
444
+ }
0 commit comments