Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.2] log integrity hash on start/stop with integrity-hash-on-start & integrity-hash-on-stop options #395

Merged
merged 4 commits into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
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
5 changes: 5 additions & 0 deletions plugins/chain_plugin/chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,8 @@ void chain_plugin::set_program_options(options_description& cli, options_descrip
("terminate-at-block", bpo::value<uint32_t>()->default_value(0),
"terminate after reaching this block number (if set to a non-zero number)")
("snapshot", bpo::value<bfs::path>(), "File to read Snapshot State from")
("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")
heifner marked this conversation as resolved.
Show resolved Hide resolved
;

}
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