Skip to content

Commit

Permalink
GH-1941 Fix ship startup
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Dec 21, 2023
1 parent bc2ff35 commit 1258af4
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions plugins/state_history_plugin/state_history_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ struct state_history_plugin_impl : std::enable_shared_from_this<state_history_pl

try {
store_traces(block, id);
store_chain_state(id, static_cast<signed_block_header>(*block), block->block_num());
store_chain_state(id, block->previous, block->block_num());
} catch (const fc::exception& e) {
fc_elog(_log, "fc::exception: ${details}", ("details", e.to_detail_string()));
// Both app().quit() and exception throwing are required. Without app().quit(),
Expand Down Expand Up @@ -256,7 +256,7 @@ struct state_history_plugin_impl : std::enable_shared_from_this<state_history_pl
}

// called from main thread
void store_chain_state(const block_id_type& id, const signed_block_header& block_header, uint32_t block_num) {
void store_chain_state(const block_id_type& id, const block_id_type& previous_id, uint32_t block_num) {
if (!chain_state_log)
return;
bool fresh = chain_state_log->empty();
Expand All @@ -265,7 +265,7 @@ struct state_history_plugin_impl : std::enable_shared_from_this<state_history_pl

state_history_log_header header{
.magic = ship_magic(ship_current_version, 0), .block_id = id, .payload_size = 0};
chain_state_log->pack_and_write_entry(header, block_header.previous, [this, fresh](auto&& buf) {
chain_state_log->pack_and_write_entry(header, previous_id, [this, fresh](auto&& buf) {
pack_deltas(buf, chain_plug->chain().db(), fresh);
});
} // store_chain_state
Expand Down Expand Up @@ -406,11 +406,10 @@ void state_history_plugin_impl::plugin_startup() {
try {
const auto& chain = chain_plug->chain();
update_current();
const auto& b = chain.head_block();
const auto& id = chain.head_block_id();
if( b && chain_state_log && chain_state_log->empty() ) {
uint32_t block_num = chain.head_block_num();
if( block_num > 0 && chain_state_log && chain_state_log->empty() ) {
fc_ilog( _log, "Storing initial state on startup, this can take a considerable amount of time" );
store_chain_state( id, *b, b->block_num() );
store_chain_state( chain.head_block_id(), chain.head_block_header().previous, block_num );
fc_ilog( _log, "Done storing initial state on startup" );
}
first_available_block = chain.earliest_available_block_num();
Expand Down

0 comments on commit 1258af4

Please sign in to comment.