From 2c91f7f5f420018be6e1828060af299eda7f9a09 Mon Sep 17 00:00:00 2001 From: Matt Witherspoon <32485495+spoonincode@users.noreply.github.com> Date: Tue, 18 Feb 2025 22:21:10 -0500 Subject: [PATCH 1/3] spelling fix --- libraries/chain/block_log.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/chain/block_log.cpp b/libraries/chain/block_log.cpp index 724f3c85a3..f6a08f1f31 100644 --- a/libraries/chain/block_log.cpp +++ b/libraries/chain/block_log.cpp @@ -597,7 +597,7 @@ namespace eosio { namespace chain { uint64_t pos = block_file.tellp(); EOS_ASSERT(index_file.tellp() == sizeof(uint64_t) * (b->block_num() - preamble.first_block_num), - block_log_append_fail, "Append to index file occuring at wrong position.", + block_log_append_fail, "Append to index file occurring at wrong position.", ("position", (uint64_t)index_file.tellp())( "expected", (b->block_num() - preamble.first_block_num) * sizeof(uint64_t))); block_file.write(packed_block.data(), packed_block.size()); From 88294f4b451500bab75c9545a8b95c057f4c3486 Mon Sep 17 00:00:00 2001 From: Matt Witherspoon <32485495+spoonincode@users.noreply.github.com> Date: Tue, 18 Feb 2025 22:21:42 -0500 Subject: [PATCH 2/3] add a flat->pruned blog test with more blocks --- tests/block_log.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/block_log.cpp b/tests/block_log.cpp index dd0e975d5a..bb06b79fa4 100644 --- a/tests/block_log.cpp +++ b/tests/block_log.cpp @@ -643,4 +643,26 @@ BOOST_DATA_TEST_CASE(empty_prune_to_partitioned_transitions, bdata::xrange(1, 11 } FC_LOG_AND_RETHROW() } +//This test adds "a lot" more blocks to the log before transitioning from flat to pruned. +BOOST_DATA_TEST_CASE(nonprune_to_prune_on_start, bdata::make({1, 1500}) * bdata::make({10, 50}), starting_block, prune_blocks) { try { + //start non pruned + block_log_fixture t(true, true, false, std::optional()); + t.startup(starting_block); + + const unsigned num_blocks_to_add = prune_blocks*3; + unsigned next_block = starting_block == 1 ? 2 : starting_block; + for(unsigned i = 0; i < prune_blocks*3; ++i) + t.add(next_block++, payload_size(), 'z'); + t.check_n_bounce([&]() {}); + + //now switch over to pruned mode + t.prune_blocks = prune_blocks; + t.check_n_bounce([&]() {}); + + if(starting_block == 1) + t.check_range_present(num_blocks_to_add-prune_blocks+2, next_block-1); + else + t.check_range_present(starting_block+num_blocks_to_add-prune_blocks, next_block-1); +} FC_LOG_AND_RETHROW() } + BOOST_AUTO_TEST_SUITE_END() From c5e45ed59951edd91ce5caf68e95cb079e9a1b6d Mon Sep 17 00:00:00 2001 From: Matt Witherspoon <32485495+spoonincode@users.noreply.github.com> Date: Tue, 18 Feb 2025 22:22:17 -0500 Subject: [PATCH 3/3] blog index needs to be open during flat->pruned conversion --- libraries/chain/block_log.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/chain/block_log.cpp b/libraries/chain/block_log.cpp index f6a08f1f31..8f14e89969 100644 --- a/libraries/chain/block_log.cpp +++ b/libraries/chain/block_log.cpp @@ -1160,6 +1160,7 @@ namespace eosio { namespace chain { // convert from non-pruned block log to pruned if necessary if (!preamble.is_currently_pruned()) { block_file.open(fc::cfile::update_rw_mode); + index_file.open(fc::cfile::update_rw_mode); update_head(read_head()); first_block_number = preamble.first_block_num; // need to convert non-pruned log to pruned log. prune any blocks to start with