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

Commit

Permalink
Merge pull request #10340 from EOSIO/huangminghuang/state-history-exi…
Browse files Browse the repository at this point in the history
…t-on-failure-2.1

state-history-exit-on-failure-2.1
  • Loading branch information
huangminghuang authored May 6, 2021
2 parents e9fa299 + 3cfd926 commit 3344ff9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
3 changes: 2 additions & 1 deletion libraries/chain/include/eosio/chain/exceptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,8 @@ namespace eosio { namespace chain {
3140000, "Exceptions that are allowed to bubble out of emit calls in controller" )
FC_DECLARE_DERIVED_EXCEPTION( checkpoint_exception, controller_emit_signal_exception,
3140001, "Block does not match checkpoint" )

FC_DECLARE_DERIVED_EXCEPTION( state_history_write_exception, controller_emit_signal_exception,
3140002, "State history write error" )

FC_DECLARE_DERIVED_EXCEPTION( abi_exception, chain_exception,
3015000, "ABI exception" )
Expand Down
25 changes: 21 additions & 4 deletions plugins/state_history_plugin/state_history_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,16 +415,33 @@ struct state_history_plugin_impl : std::enable_shared_from_this<state_history_pl
trace_log->add_transaction(p, t);
}

void store(const block_state_ptr& block_state) {
try {
if (trace_log)
trace_log->store(chain_plug->chain().db(), block_state);
if (chain_state_log)
chain_state_log->store(chain_plug->chain().kv_db(), block_state);
return;
}
FC_LOG_AND_DROP()

// Both app().quit() and exception throwing are required. Without app().quit(),
// the exception would be caught and drop before reaching main(). The exception is
// to ensure the block won't be committed.
appbase::app().quit();
EOS_THROW(
chain::state_history_write_exception,
"State history encountered an Error which it cannot recover from. Please resolve the error and relaunch "
"the process");
}

void on_accepted_block(const block_state_ptr& block_state) {
auto blk_trace = fc_create_trace_with_id("Block", block_state->id);
auto blk_span = fc_create_span(blk_trace, "SHiP-Accepted");
fc_add_tag(blk_span, "block_id", block_state->id);
fc_add_tag(blk_span, "block_num", block_state->block_num);
fc_add_tag(blk_span, "block_time", block_state->block->timestamp.to_time_point());
if (trace_log)
trace_log->store(chain_plug->chain().db(), block_state);
if (chain_state_log)
chain_state_log->store(chain_plug->chain().kv_db(), block_state);
this->store(block_state);
for (auto& s : sessions) {
auto& p = s.second;
if (p) {
Expand Down

0 comments on commit 3344ff9

Please sign in to comment.