Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.2] Backport: [statehist] Ship logs reduction / optimization #620

Merged
merged 6 commits into from
Jul 8, 2022
Merged
Changes from 2 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
28 changes: 28 additions & 0 deletions plugins/state_history_plugin/state_history_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ namespace ws = boost::beast::websocket;

extern const char* const state_history_plugin_abi;

// during syncing if block is older than this, reduce logging
const int64_t log_reduction_minutes = 5;
vladtr marked this conversation as resolved.
Show resolved Hide resolved

// during reduced logging, log every log_reduction_one_per block
const uint32_t log_reduction_one_per = 1000;

namespace eosio {
using namespace chain;
using namespace state_history;
Expand Down Expand Up @@ -234,6 +240,28 @@ struct state_history_plugin_impl : std::enable_shared_from_this<state_history_pl
}
++current_request->start_block_num;
}

auto& block_num = current_request->start_block_num;
auto get_blk = [&chain, block_num, block_state]() -> signed_block_ptr {
try {
if (block_state && block_state->block_num == block_num)
return block_state->block;
return chain.fetch_block_by_number(block_num);
} catch (...) {
return {};
}
};
auto block = get_blk();

bool fresh_block = block && fc::time_point::now() - block->timestamp < fc::minutes(log_reduction_minutes);
if( fresh_block || (result.this_block && result.this_block->block_num % log_reduction_one_per == 0) ) {
ilog("pushing result "
vladtr marked this conversation as resolved.
Show resolved Hide resolved
"{\"head\":{\"block_num\":${head}},\"last_irreversible\":{\"block_num\":${last_irr}},\"this_block\":{"
"\"block_num\":${this_block}}} to send queue",
("head", result.head.block_num)("last_irr", result.last_irreversible.block_num)(
"this_block", result.this_block ? result.this_block->block_num : fc::variant()));
}

send(std::move(result));
--current_request->max_messages_in_flight;
need_to_send_update = current_request->start_block_num <= current &&
Expand Down