@@ -603,6 +603,61 @@ BOOST_AUTO_TEST_CASE( auto_split_4 )
603603 }
604604}
605605
606+ BOOST_AUTO_TEST_CASE ( incremental_replay_pruned )
607+ {
608+ try {
609+ ilog ( " Testing replay stopped at block with block log set to pruning." );
610+
611+ const uint32_t initial_log_block_count = 5 * BLOCKS_IN_SPLIT_BLOCK_LOG_FILE;
612+
613+ { // Generate split log, full 5 parts.
614+ hived_fixture fixture ( true /* remove blockchain*/ );
615+ INIT_FIXTURE_1 ( " block-log-split" , std::to_string ( MAX_FILES_OF_SPLIT_BLOCK_LOG ) );
616+
617+ for ( uint32_t i = 0 ; i < initial_log_block_count; ++i )
618+ fixture.generate_block ();
619+
620+ // Check that state head block num matches full 5 part block log's.
621+ BOOST_REQUIRE_EQUAL ( fixture.db ->head_block_num (), initial_log_block_count );
622+ }
623+ { // Switch to pruned log, check that block num 3 * BLOCKS_IN_SPLIT_BLOCK_LOG_FILE + 1
624+ // is the tail block - previous one is unavailable.
625+ const uint32_t tail_block_num = 3 * BLOCKS_IN_SPLIT_BLOCK_LOG_FILE + 1 ;
626+ hived_fixture fixture ( false /* remove blockchain*/ );
627+ INIT_FIXTURE_2 ( " block-log-split" , " 1" ,
628+ " stop-at-block" , std::to_string ( initial_log_block_count ) );
629+
630+ const block_read_i& block_reader = fixture.get_chain_plugin ().block_reader ();
631+ auto tail = block_reader.get_block_by_number ( tail_block_num );
632+ BOOST_REQUIRE ( tail );
633+ BOOST_REQUIRE_THROW ( block_reader.get_block_by_number ( tail_block_num -1 ), fc::assert_exception );
634+ }
635+ { // Keep pruned configuration, replay up to block count below pruned tail.
636+ // i.e. block num 3 * BLOCKS_IN_SPLIT_BLOCK_LOG_FILE / 2 is below pruned tail.
637+ const uint32_t middle_of_second_part = 3 * BLOCKS_IN_SPLIT_BLOCK_LOG_FILE / 2 ;
638+ hived_fixture fixture ( false /* remove blockchain*/ );
639+ INIT_FIXTURE_3 ( " block-log-split" , " 1" ,
640+ " force-replay" , " " ,
641+ " stop-at-block" , std::to_string ( middle_of_second_part ) );
642+ // Check that replay was forced and that it ended at desired block, below pruned tail.
643+ BOOST_REQUIRE_EQUAL ( fixture.db ->head_block_num (), middle_of_second_part );
644+ }
645+ { // Make another incremental partial replay, staying below pruned tail.
646+ const uint32_t two_and_a_quarter_part = 9 * BLOCKS_IN_SPLIT_BLOCK_LOG_FILE / 4 ;
647+ hived_fixture fixture ( false /* remove blockchain*/ );
648+ INIT_FIXTURE_3 ( " block-log-split" , " 1" ,
649+ " replay-blockchain" , " " ,
650+ " stop-at-block" , std::to_string ( two_and_a_quarter_part ) );
651+ // Check that replay ended at desired block, below pruned tail.
652+ BOOST_REQUIRE_EQUAL ( fixture.db ->head_block_num (), two_and_a_quarter_part );
653+ }
654+
655+ } catch (fc::exception& e) {
656+ edump ((e.to_detail_string ()));
657+ throw ;
658+ }
659+ }
660+
606661void post_snapshot_block_storage_switch ( int initial_block_storage, int target_block_storage,
607662 bool force_no_tail )
608663{
0 commit comments