Skip to content

Commit e835967

Browse files
authored
Merge pull request #1184 from AntelopeIO/flat2prunedfix
[1.1.1 -> main] fix flat to pruned block log conversion
2 parents 26ce2c7 + 62ab773 commit e835967

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

libraries/chain/block_log.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ namespace eosio { namespace chain {
597597
uint64_t pos = block_file.tellp();
598598

599599
EOS_ASSERT(index_file.tellp() == sizeof(uint64_t) * (b->block_num() - preamble.first_block_num),
600-
block_log_append_fail, "Append to index file occuring at wrong position.",
600+
block_log_append_fail, "Append to index file occurring at wrong position.",
601601
("position", (uint64_t)index_file.tellp())(
602602
"expected", (b->block_num() - preamble.first_block_num) * sizeof(uint64_t)));
603603
block_file.write(packed_block.data(), packed_block.size());
@@ -1165,6 +1165,7 @@ namespace eosio { namespace chain {
11651165
// convert from non-pruned block log to pruned if necessary
11661166
if (!preamble.is_currently_pruned()) {
11671167
block_file.open(fc::cfile::update_rw_mode);
1168+
index_file.open(fc::cfile::update_rw_mode);
11681169
update_head(read_head());
11691170
first_block_number = preamble.first_block_num;
11701171
// need to convert non-pruned log to pruned log. prune any blocks to start with

tests/block_log.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -644,4 +644,26 @@ BOOST_DATA_TEST_CASE(empty_prune_to_partitioned_transitions, bdata::xrange(1, 11
644644

645645
} FC_LOG_AND_RETHROW() }
646646

647+
//This test adds "a lot" more blocks to the log before transitioning from flat to pruned.
648+
BOOST_DATA_TEST_CASE(nonprune_to_prune_on_start, bdata::make({1, 1500}) * bdata::make({10, 50}), starting_block, prune_blocks) { try {
649+
//start non pruned
650+
block_log_fixture t(true, true, false, std::optional<uint32_t>());
651+
t.startup(starting_block);
652+
653+
const unsigned num_blocks_to_add = prune_blocks*3;
654+
unsigned next_block = starting_block == 1 ? 2 : starting_block;
655+
for(unsigned i = 0; i < prune_blocks*3; ++i)
656+
t.add(next_block++, payload_size(), 'z');
657+
t.check_n_bounce([&]() {});
658+
659+
//now switch over to pruned mode
660+
t.prune_blocks = prune_blocks;
661+
t.check_n_bounce([&]() {});
662+
663+
if(starting_block == 1)
664+
t.check_range_present(num_blocks_to_add-prune_blocks+2, next_block-1);
665+
else
666+
t.check_range_present(starting_block+num_blocks_to_add-prune_blocks, next_block-1);
667+
} FC_LOG_AND_RETHROW() }
668+
647669
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)