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

Fix SHIP block delay - 2.0 #8952

Merged
merged 1 commit into from
Apr 18, 2020
Merged
Changes from all 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
37 changes: 27 additions & 10 deletions plugins/state_history_plugin/state_history_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,18 +272,14 @@ struct state_history_plugin_impl : std::enable_shared_from_this<state_history_pl
send_update();
}

void send_update(bool changed = false) {
if (changed)
need_to_send_update = true;
if (!send_queue.empty() || !need_to_send_update || !current_request ||
!current_request->max_messages_in_flight)
void send_update(get_blocks_result_v0 result) {
need_to_send_update = true;
if (!send_queue.empty() || !current_request || !current_request->max_messages_in_flight)
return;
auto& chain = plugin->chain_plug->chain();
get_blocks_result_v0 result;
result.head = {chain.head_block_num(), chain.head_block_id()};
auto& chain = plugin->chain_plug->chain();
result.last_irreversible = {chain.last_irreversible_block_num(), chain.last_irreversible_block_id()};
uint32_t current =
current_request->irreversible_only ? result.last_irreversible.block_num : result.head.block_num;
current_request->irreversible_only ? result.last_irreversible.block_num : result.head.block_num;
if (current_request->start_block_num <= current &&
current_request->start_block_num < current_request->end_block_num) {
auto block_id = plugin->get_block_id(current_request->start_block_num);
Expand All @@ -307,6 +303,27 @@ struct state_history_plugin_impl : std::enable_shared_from_this<state_history_pl
current_request->start_block_num < current_request->end_block_num;
}

void send_update(const block_state_ptr& block_state) {
need_to_send_update = true;
if (!send_queue.empty() || !current_request || !current_request->max_messages_in_flight)
return;
get_blocks_result_v0 result;
result.head = {block_state->block_num, block_state->id};
send_update(std::move(result));
}

void send_update(bool changed = false) {
if (changed)
need_to_send_update = true;
if (!send_queue.empty() || !need_to_send_update || !current_request ||
!current_request->max_messages_in_flight)
return;
auto& chain = plugin->chain_plug->chain();
get_blocks_result_v0 result;
result.head = {chain.head_block_num(), chain.head_block_id()};
send_update(std::move(result));
}

template <typename F>
void catch_and_close(F f) {
try {
Expand Down Expand Up @@ -424,7 +441,7 @@ struct state_history_plugin_impl : std::enable_shared_from_this<state_history_pl
if (p) {
if (p->current_request && block_state->block_num < p->current_request->start_block_num)
p->current_request->start_block_num = block_state->block_num;
p->send_update(true);
p->send_update(block_state);
}
}
}
Expand Down