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

Commit

Permalink
Merge pull request #10061 from EOSIO/huangminghuang/fix-empty-blocklo…
Browse files Browse the repository at this point in the history
…g-restart

fix restart without blocks.log but with retained blocks files
  • Loading branch information
brianjohnson5972 authored Feb 18, 2021
2 parents 3220a11 + f7d170c commit 6312010
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
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()

0 comments on commit 6312010

Please sign in to comment.