Skip to content

Commit

Permalink
Merge pull request AntelopeIO#395 from eosnetworkfoundation/log_integ…
Browse files Browse the repository at this point in the history
…rity_hash_startstop

log integrity hash on start/stop with integrity-hash-on-start & integrity-hash-on-stop options
  • Loading branch information
spoonincode authored Jun 21, 2022
2 parents 5bcc66d + 2d01629 commit 91bf1f1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
10 changes: 8 additions & 2 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ struct controller_impl {
named_thread_pool thread_pool;
platform_timer timer;
deep_mind_handler* deep_mind_logger = nullptr;
bool okay_to_print_integrity_hash_on_stop = false;
#if defined(EOSIO_EOS_VM_RUNTIME_ENABLED) || defined(EOSIO_EOS_VM_JIT_RUNTIME_ENABLED)
vm::wasm_allocator wasm_alloc;
#endif
Expand Down Expand Up @@ -569,8 +570,6 @@ struct controller_impl {
"Snapshot is invalid." );
blog.reset( chain_id, lib_num + 1 );
}
const auto hash = calculate_integrity_hash();
ilog( "database initialized with hash: ${hash}", ("hash", hash) );

init(check_shutdown);
ilog( "Finished initialization from snapshot" );
Expand Down Expand Up @@ -696,6 +695,10 @@ struct controller_impl {
dm_logger->on_startup(db, head->block_num);
}

if( conf.integrity_hash_on_start )
ilog( "chain database started with hash: ${hash}", ("hash", calculate_integrity_hash()) );
okay_to_print_integrity_hash_on_stop = true;

replay( check_shutdown ); // replay any irreversible and reversible blocks ahead of current head

if( check_shutdown() ) return;
Expand Down Expand Up @@ -723,6 +726,9 @@ struct controller_impl {
~controller_impl() {
thread_pool.stop();
pending.reset();
//only log this not just if configured to, but also if initialization made it to the point we'd log the startup too
if(okay_to_print_integrity_hash_on_stop && conf.integrity_hash_on_stop)
ilog( "chain database stopped with hash: ${hash}", ("hash", calculate_integrity_hash()) );
}

void add_indices() {
Expand Down
2 changes: 2 additions & 0 deletions libraries/chain/include/eosio/chain/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ namespace eosio { namespace chain {
uint32_t maximum_variable_signature_length = chain::config::default_max_variable_signature_length;
bool disable_all_subjective_mitigations = false; //< for developer & testing purposes, can be configured using `disable-all-subjective-mitigations` when `EOSIO_DEVELOPER` build option is provided
uint32_t terminate_at_block = 0; //< primarily for testing purposes
bool integrity_hash_on_start= false;
bool integrity_hash_on_stop = false;

wasm_interface::vm_type wasm_runtime = chain::config::default_wasm_runtime;
eosvmoc::config eosvmoc_config;
Expand Down
7 changes: 6 additions & 1 deletion plugins/chain_plugin/chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,9 @@ void chain_plugin::set_program_options(options_description& cli, options_descrip
("transaction-finality-status-success-duration-sec", bpo::value<uint64_t>()->default_value(config::default_max_transaction_finality_status_success_duration_sec),
"Duration (in seconds) a successful transaction's Finality Status will remain available from being first identified.")
("transaction-finality-status-failure-duration-sec", bpo::value<uint64_t>()->default_value(config::default_max_transaction_finality_status_failure_duration_sec),
"Duration (in seconds) a failed transaction's Finality Status will remain available from being first identified.");
"Duration (in seconds) a failed transaction's Finality Status will remain available from being first identified.")
("integrity-hash-on-start", bpo::bool_switch(), "Log the state integrity hash on startup")
("integrity-hash-on-stop", bpo::bool_switch(), "Log the state integrity hash on shutdown");

if(cfile::supports_hole_punching())
cfg.add_options()("block-log-retain-blocks", bpo::value<uint32_t>(), "if set, periodically prune the block log to store only configured number of most recent blocks");
Expand Down Expand Up @@ -1079,6 +1081,9 @@ void chain_plugin::plugin_initialize(const variables_map& options) {

my->account_queries_enabled = options.at("enable-account-queries").as<bool>();

my->chain_config->integrity_hash_on_start = options.at("integrity-hash-on-start").as<bool>();
my->chain_config->integrity_hash_on_stop = options.at("integrity-hash-on-stop").as<bool>();

my->chain.emplace( *my->chain_config, std::move(pfs), *chain_id );

if( options.count( "transaction-retry-max-storage-size-gb" )) {
Expand Down

0 comments on commit 91bf1f1

Please sign in to comment.