diff --git a/libraries/chain/block_log.cpp b/libraries/chain/block_log.cpp index 61f436a1a5..617fa74171 100644 --- a/libraries/chain/block_log.cpp +++ b/libraries/chain/block_log.cpp @@ -403,6 +403,20 @@ namespace hive { namespace chain { return std::make_tuple(std::move(serialized_data), serialized_data_size, std::move(this_block_artifacts)); } + std::tuple, size_t, block_log_artifacts::block_attributes_t> block_log::read_common_raw_block_data_by_num(uint32_t block_num) const + { + if( block_num == my->_artifacts->read_head_block_num() ) + { + return read_raw_head_block(); + } + else + { + std::tuple, size_t, hive::chain::block_log_artifacts::artifacts_t> data_with_artifacts = + read_raw_block_data_by_num(block_num); + return std::make_tuple(std::get<0>(std::move(data_with_artifacts)), std::get<1>(data_with_artifacts), std::get<2>(data_with_artifacts).attributes); + } + } + // threading guarantees: // - this function may only be called by one thread at a time // - It is safe to call `append` while any number of other threads diff --git a/libraries/chain/block_log_wrapper.cpp b/libraries/chain/block_log_wrapper.cpp index f157472ec4..9400f4e324 100644 --- a/libraries/chain/block_log_wrapper.cpp +++ b/libraries/chain/block_log_wrapper.cpp @@ -153,12 +153,12 @@ std::tuple, size_t, block_attributes_t> block_log_wrappe return get_head_log()->read_raw_head_block(); } -std::tuple, size_t, block_log_artifacts::artifacts_t> block_log_wrapper::read_raw_block_data_by_num(uint32_t block_num) const +std::tuple, size_t, block_log_artifacts::block_attributes_t> block_log_wrapper::read_common_raw_block_data_by_num(uint32_t block_num) const { const block_log_ptr_t log = get_block_log_corresponding_to( block_num ); FC_ASSERT( log, "Unable to find block log corresponding to block number ${block_num}", (block_num)); - return log->read_raw_block_data_by_num( block_num ); + return log->read_common_raw_block_data_by_num( block_num ); } void block_log_wrapper::append( const std::shared_ptr& full_block, const bool is_at_live_sync ) diff --git a/libraries/chain/include/hive/chain/block_log.hpp b/libraries/chain/include/hive/chain/block_log.hpp index 80dea06dbc..9f83c7674b 100644 --- a/libraries/chain/include/hive/chain/block_log.hpp +++ b/libraries/chain/include/hive/chain/block_log.hpp @@ -126,6 +126,7 @@ namespace hive { namespace chain { block_log_artifacts::artifact_container_t& plural_of_artifacts); void flush(); + std::tuple, size_t, block_log_artifacts::block_attributes_t> read_common_raw_block_data_by_num(uint32_t block_num) const; std::tuple, size_t, block_log_artifacts::artifacts_t> read_raw_block_data_by_num(uint32_t block_num) const; void multi_read_raw_block_data(uint32_t first_block_num, uint32_t last_block_num_from_disk, block_log_artifacts::artifact_container_t& plural_of_block_artifacts, diff --git a/libraries/chain/include/hive/chain/block_log_wrapper.hpp b/libraries/chain/include/hive/chain/block_log_wrapper.hpp index 48634a6c54..65afa83bba 100644 --- a/libraries/chain/include/hive/chain/block_log_wrapper.hpp +++ b/libraries/chain/include/hive/chain/block_log_wrapper.hpp @@ -45,8 +45,8 @@ namespace hive { namespace chain { // Methods wrapping safely block_log ones. std::tuple, size_t, block_attributes_t> read_raw_head_block() const; - std::tuple, size_t, block_log_artifacts::artifacts_t> - read_raw_block_data_by_num(uint32_t block_num) const; + std::tuple, size_t, block_attributes_t> + read_common_raw_block_data_by_num(uint32_t block_num) const; void multi_read_raw_block_data(uint32_t first_block_num, uint32_t last_block_num_from_disk, block_log_artifacts::artifact_container_t& plural_of_block_artifacts, std::unique_ptr& block_data_buffer, size_t& block_data_buffer_size ) const; diff --git a/programs/util/compress_block_log.cpp b/programs/util/compress_block_log.cpp index b9294f0c70..55ac5553b4 100644 --- a/programs/util/compress_block_log.cpp +++ b/programs/util/compress_block_log.cpp @@ -315,15 +315,8 @@ void fill_pending_queue(const fc::path &input_path, const bool read_only, uint32 block_to_compress *uncompressed_block = new block_to_compress; uncompressed_block->block_number = current_block_number; - std::tuple, size_t, hive::chain::block_log::block_attributes_t> raw_compressed_block_data; - if (current_block_number == head_block_num) - raw_compressed_block_data = log_reader->read_raw_head_block(); - else - { - std::tuple, size_t, hive::chain::block_log_artifacts::artifacts_t> data_with_artifacts = - log_reader->read_raw_block_data_by_num(current_block_number); - raw_compressed_block_data = std::make_tuple(std::get<0>(std::move(data_with_artifacts)), std::get<1>(data_with_artifacts), std::get<2>(data_with_artifacts).attributes); - } + std::tuple, size_t, hive::chain::block_log::block_attributes_t> raw_compressed_block_data = + log_reader->read_common_raw_block_data_by_num(current_block_number); std::tuple, size_t> raw_block_data = hive::chain::block_log_compression::decompress_raw_block(std::move(raw_compressed_block_data));