From 527b39764a3ee9869b37a62f345d3607d2810480 Mon Sep 17 00:00:00 2001 From: allen han Date: Wed, 13 Jan 2021 15:48:40 -0600 Subject: [PATCH 1/3] Add log path for exception --- libraries/chain/block_log.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/libraries/chain/block_log.cpp b/libraries/chain/block_log.cpp index b91a1ee62bf..56c99165522 100644 --- a/libraries/chain/block_log.cpp +++ b/libraries/chain/block_log.cpp @@ -37,6 +37,8 @@ namespace eosio { namespace chain { uint32_t version = 0; uint32_t first_block_num = 0; std::variant chain_context; + fc::path log_path; + chain_id_type chain_id() const { return std::visit(overloaded{[](const chain_id_type& id) { return id; }, @@ -53,8 +55,8 @@ namespace eosio { namespace chain { EOS_ASSERT( block_log::is_supported_version(version), block_log_unsupported_version, "Unsupported version of block log. Block log version is ${version} while code supports version(s) " - "[${min},${max}]", - ("version", version)("min", block_log::min_supported_version)("max", block_log::max_supported_version)); + "[${min},${max}], log file: ${log}", + ("version", version)("min", block_log::min_supported_version)("max", block_log::max_supported_version)("log", log_path)); first_block_num = 1; if (version != initial_version) { @@ -279,7 +281,10 @@ namespace eosio { namespace chain { public: block_log_data() = default; - block_log_data(const fc::path& path, mapmode mode = mapmode::readonly) { open(path, mode); } + block_log_data(const fc::path& path, mapmode mode = mapmode::readonly) { + preamble.log_path = path; + open(path, mode); + } const block_log_preamble& get_preamble() const { return preamble; } @@ -297,6 +302,7 @@ namespace eosio { namespace chain { uint32_t first_block_num() const { return preamble.first_block_num; } uint64_t first_block_position() const { return first_block_pos; } chain_id_type chain_id() const { return preamble.chain_id(); } + fc::path log_path() const { return preamble.log_path; } std::optional get_genesis_state() const { return std::visit(overloaded{[](const chain_id_type&) { return std::optional{}; }, @@ -398,11 +404,11 @@ namespace eosio { namespace chain { block_log_data log_data; block_log_index log_index; - block_log_bundle(fc::path block_dir) { - block_file_name = block_dir / "blocks.log"; + block_log_bundle(fc::path block_dir) + : block_file_name (block_dir / "blocks.log") + , log_data(block_file_name) + { index_file_name = block_dir / "blocks.index"; - - log_data.open(block_file_name); log_index.open(index_file_name); uint32_t log_num_blocks = log_data.num_blocks(); From 37da4b21bf74413c2f0e5287d259f30b35cb97d1 Mon Sep 17 00:00:00 2001 From: allen han Date: Tue, 19 Jan 2021 10:49:54 -0600 Subject: [PATCH 2/3] set log path in open --- libraries/chain/block_log.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libraries/chain/block_log.cpp b/libraries/chain/block_log.cpp index 56c99165522..23d1e00649f 100644 --- a/libraries/chain/block_log.cpp +++ b/libraries/chain/block_log.cpp @@ -282,7 +282,6 @@ namespace eosio { namespace chain { block_log_data() = default; block_log_data(const fc::path& path, mapmode mode = mapmode::readonly) { - preamble.log_path = path; open(path, mode); } @@ -293,6 +292,7 @@ namespace eosio { namespace chain { file.close(); file.open(path.string(), mode); fc::datastream ds(this->data(), this->size()); + preamble.log_path = path; preamble.read_from(ds); first_block_pos = ds.tellp(); return ds; @@ -302,7 +302,6 @@ namespace eosio { namespace chain { uint32_t first_block_num() const { return preamble.first_block_num; } uint64_t first_block_position() const { return first_block_pos; } chain_id_type chain_id() const { return preamble.chain_id(); } - fc::path log_path() const { return preamble.log_path; } std::optional get_genesis_state() const { return std::visit(overloaded{[](const chain_id_type&) { return std::optional{}; }, From 2713591bf3379317f0b2b1350a7ac73c4566490a Mon Sep 17 00:00:00 2001 From: allen han Date: Tue, 19 Jan 2021 11:15:20 -0600 Subject: [PATCH 3/3] Add log_path as parameter --- libraries/chain/block_log.cpp | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/libraries/chain/block_log.cpp b/libraries/chain/block_log.cpp index 23d1e00649f..125dd6752c0 100644 --- a/libraries/chain/block_log.cpp +++ b/libraries/chain/block_log.cpp @@ -37,8 +37,6 @@ namespace eosio { namespace chain { uint32_t version = 0; uint32_t first_block_num = 0; std::variant chain_context; - fc::path log_path; - chain_id_type chain_id() const { return std::visit(overloaded{[](const chain_id_type& id) { return id; }, @@ -49,14 +47,14 @@ namespace eosio { namespace chain { constexpr static int nbytes_with_chain_id = // the bytes count when the preamble contains chain_id sizeof(version) + sizeof(first_block_num) + sizeof(chain_id_type) + sizeof(block_log::npos); - void read_from(fc::datastream& ds) { + void read_from(fc::datastream& ds, const fc::path& log_path) { ds.read((char*)&version, sizeof(version)); EOS_ASSERT(version > 0, block_log_exception, "Block log was not setup properly"); EOS_ASSERT( block_log::is_supported_version(version), block_log_unsupported_version, "Unsupported version of block log. Block log version is ${version} while code supports version(s) " "[${min},${max}], log file: ${log}", - ("version", version)("min", block_log::min_supported_version)("max", block_log::max_supported_version)("log", log_path)); + ("version", version)("min", block_log::min_supported_version)("max", block_log::max_supported_version)("log", log_path.generic_string())); first_block_num = 1; if (version != initial_version) { @@ -281,9 +279,7 @@ namespace eosio { namespace chain { public: block_log_data() = default; - block_log_data(const fc::path& path, mapmode mode = mapmode::readonly) { - open(path, mode); - } + block_log_data(const fc::path& path, mapmode mode = mapmode::readonly) { open(path, mode); } const block_log_preamble& get_preamble() const { return preamble; } @@ -292,8 +288,7 @@ namespace eosio { namespace chain { file.close(); file.open(path.string(), mode); fc::datastream ds(this->data(), this->size()); - preamble.log_path = path; - preamble.read_from(ds); + preamble.read_from(ds, path); first_block_pos = ds.tellp(); return ds; } @@ -403,11 +398,11 @@ namespace eosio { namespace chain { block_log_data log_data; block_log_index log_index; - block_log_bundle(fc::path block_dir) - : block_file_name (block_dir / "blocks.log") - , log_data(block_file_name) - { + block_log_bundle(fc::path block_dir) { + block_file_name = block_dir / "blocks.log"; index_file_name = block_dir / "blocks.index"; + + log_data.open(block_file_name); log_index.open(index_file_name); uint32_t log_num_blocks = log_data.num_blocks();