Skip to content

Commit

Permalink
Merge pull request #1181 from AntelopeIO/flat2prunedfix_11x
Browse files Browse the repository at this point in the history
[1.1.1] fix flat to pruned block log conversion
  • Loading branch information
spoonincode authored Feb 19, 2025
2 parents 2be4f8a + c5e45ed commit fdd0c71
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion libraries/chain/block_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions tests/block_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t>());
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()

0 comments on commit fdd0c71

Please sign in to comment.