Skip to content

Commit

Permalink
feature: indicate average speed of appending while fast syncing
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com>
  • Loading branch information
xDimon committed Aug 10, 2022
1 parent bd15e37 commit 8f2c6d7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
27 changes: 18 additions & 9 deletions core/consensus/babe/impl/block_appender_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,17 +246,26 @@ namespace kagome::consensus {
}
}

SL_DEBUG(logger_,
"Imported header of block {} within {} us",
block_info,
std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::high_resolution_clock::now() - t_start)
.count());
auto now = std::chrono::high_resolution_clock::now();

SL_DEBUG(
logger_,
"Imported header of block {} within {} us",
block_info,
std::chrono::duration_cast<std::chrono::microseconds>(now - t_start)
.count());

if (block_info.number % 512 == 0) {
auto block_delta = block_info.number - speed_data_.block_number;
auto time_delta = now - speed_data_.time;
if (block_delta >= 25000 or time_delta >= std::chrono::minutes(1)) {
SL_INFO(logger_,
"Imported another 512 headers of blocks. Last one imported is {}",
block_info);
"Imported {} more headers of blocks. Average speed is {} bps",
block_delta,
block_delta
/ std::chrono::duration_cast<std::chrono::seconds>(time_delta)
.count());
speed_data_.block_number = block_info.number;
speed_data_.time = now;
}

consistency_guard.commit();
Expand Down
5 changes: 5 additions & 0 deletions core/consensus/babe/impl/block_appender_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ namespace kagome::consensus {
// Justification Store for Future Applying
std::map<primitives::BlockInfo, primitives::Justification> justifications_;

struct {
std::chrono::high_resolution_clock::time_point time;
primitives::BlockNumber block_number;
} speed_data_;

log::Logger logger_;
};

Expand Down

0 comments on commit 8f2c6d7

Please sign in to comment.