Skip to content
This repository was archived by the owner on Aug 2, 2022. It is now read-only.

fix restart without blocks.log but with retained blocks files #10061

Merged
merged 1 commit into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions libraries/chain/block_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,12 @@ namespace eosio { namespace chain {
const auto log_size = fc::file_size(block_file.get_file_path());
const auto index_size = fc::file_size(index_file.get_file_path());

if (log_size == 0 && !catalog.empty()) {
this->reset(catalog.last_block_num() + 1, catalog.verifier.chain_id);
this->head = read_block_by_num(catalog.last_block_num());
return;
}

if (log_size) {
ilog("Log is nonempty");
block_log_data log_data(block_file.get_file_path());
Expand Down
6 changes: 6 additions & 0 deletions libraries/chain/include/eosio/chain/log_catalog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ struct log_catalog {
return collection.begin()->first;
}

uint32_t last_block_num() const {
if (empty())
return 0;
return collection.rbegin()->second.last_block_num;
}

static bfs::path make_abosolute_dir(const bfs::path& base_dir, bfs::path new_dir) {
if (new_dir.is_relative())
new_dir = base_dir / new_dir;
Expand Down
8 changes: 8 additions & 0 deletions unittests/restart_chain_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,14 @@ BOOST_AUTO_TEST_CASE(test_split_log_util2) {
BOOST_CHECK(bfs::exists( retained_dir / "blocks-51-100.index" ));
BOOST_CHECK(bfs::exists( retained_dir / "blocks-101-150.log" ));
BOOST_CHECK(bfs::exists( retained_dir / "blocks-101-150.index" ));

bfs::remove(blocks_dir/"blocks.log");
bfs::remove(blocks_dir/"blocks.index");

block_log blog({.log_dir = blocks_dir, .retained_dir = retained_dir });

BOOST_CHECK(blog.version() != 0);
BOOST_CHECK(blog.head().get());
}

BOOST_AUTO_TEST_SUITE_END()