Skip to content

Commit

Permalink
Merge pull request #73 from DaoCasino/state-history-logs
Browse files Browse the repository at this point in the history
fix state history realtime blocks streaming lag
  • Loading branch information
algys authored Jul 19, 2020
2 parents 20f2b21 + e8fca7b commit fb08e9f
Showing 1 changed file with 29 additions and 16 deletions.
45 changes: 29 additions & 16 deletions plugins/state_history_plugin/state_history_plugin.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* @file
* @copyright defined in eos/LICENSE
*/

#include <eosio/chain/config.hpp>
#include <eosio/state_history_plugin/state_history_log.hpp>
#include <eosio/state_history_plugin/state_history_serialization.hpp>
Expand Down Expand Up @@ -99,7 +94,7 @@ bool include_delta(const eosio::chain::resource_limits::resource_limits_state_ob
bool include_delta(const eosio::chain::account_metadata_object& old,
const eosio::chain::account_metadata_object& curr) {
return //
old.name.value != curr.name.value || //
old.name != curr.name || //
old.is_privileged() != curr.is_privileged() || //
old.last_code_update != curr.last_code_update || //
old.vm_type != curr.vm_type || //
Expand Down Expand Up @@ -277,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 @@ -312,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 @@ -429,11 +441,12 @@ 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);
}
}
}


void store_traces(const block_state_ptr& block_state) {
if (!trace_log)
return;
Expand Down

0 comments on commit fb08e9f

Please sign in to comment.