From a70d6d527ba5a662eb8ae071389890c73f15eaa8 Mon Sep 17 00:00:00 2001 From: Matt Witherspoon <32485495+spoonincode@users.noreply.github.com> Date: Wed, 15 Jun 2022 15:59:20 -0400 Subject: [PATCH 1/4] log db hash on start/stop with integrity-hash-on-start & integrity-hash-on-stop --- libraries/chain/controller.cpp | 8 ++++++-- libraries/chain/include/eosio/chain/controller.hpp | 2 ++ plugins/chain_plugin/chain_plugin.cpp | 5 +++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index e517e4544b..fce5fe9af7 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -569,8 +569,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" ); @@ -696,6 +694,9 @@ 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()) ); + replay( check_shutdown ); // replay any irreversible and reversible blocks ahead of current head if( check_shutdown() ) return; @@ -723,6 +724,9 @@ struct controller_impl { ~controller_impl() { thread_pool.stop(); pending.reset(); + //using the presence of a row in datebase_header index to indicate controller had a successful startup() + if(db.get_index().indices().get().size() && conf.integrity_hash_on_stop) + ilog( "chain database stopped with hash: ${hash}", ("hash", calculate_integrity_hash()) ); } void add_indices() { diff --git a/libraries/chain/include/eosio/chain/controller.hpp b/libraries/chain/include/eosio/chain/controller.hpp index 142f09c5a1..b95b9e33ea 100644 --- a/libraries/chain/include/eosio/chain/controller.hpp +++ b/libraries/chain/include/eosio/chain/controller.hpp @@ -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; diff --git a/plugins/chain_plugin/chain_plugin.cpp b/plugins/chain_plugin/chain_plugin.cpp index bf3cba9dd3..1708edb68e 100644 --- a/plugins/chain_plugin/chain_plugin.cpp +++ b/plugins/chain_plugin/chain_plugin.cpp @@ -373,6 +373,8 @@ void chain_plugin::set_program_options(options_description& cli, options_descrip ("terminate-at-block", bpo::value()->default_value(0), "terminate after reaching this block number (if set to a non-zero number)") ("snapshot", bpo::value(), "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") ; } @@ -1079,6 +1081,9 @@ void chain_plugin::plugin_initialize(const variables_map& options) { my->account_queries_enabled = options.at("enable-account-queries").as(); + my->chain_config->integrity_hash_on_start = options.at("integrity-hash-on-start").as(); + my->chain_config->integrity_hash_on_stop = options.at("integrity-hash-on-stop").as(); + my->chain.emplace( *my->chain_config, std::move(pfs), *chain_id ); if( options.count( "transaction-retry-max-storage-size-gb" )) { From 3019dcdc766636cbb5135774f8af90b9f932c2c8 Mon Sep 17 00:00:00 2001 From: Matt Witherspoon <32485495+spoonincode@users.noreply.github.com> Date: Fri, 17 Jun 2022 15:27:05 -0400 Subject: [PATCH 2/4] just use a bool to track when it's acceptable to log exit hash --- libraries/chain/controller.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index fce5fe9af7..6d455fb959 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -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_exit = false; #if defined(EOSIO_EOS_VM_RUNTIME_ENABLED) || defined(EOSIO_EOS_VM_JIT_RUNTIME_ENABLED) vm::wasm_allocator wasm_alloc; #endif @@ -696,6 +697,7 @@ struct controller_impl { 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 @@ -724,8 +726,8 @@ struct controller_impl { ~controller_impl() { thread_pool.stop(); pending.reset(); - //using the presence of a row in datebase_header index to indicate controller had a successful startup() - if(db.get_index().indices().get().size() && conf.integrity_hash_on_stop) + //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()) ); } From 0f9ac1b210a51fda3ed8945a33a17b02851594ab Mon Sep 17 00:00:00 2001 From: Matt Witherspoon <32485495+spoonincode@users.noreply.github.com> Date: Fri, 17 Jun 2022 15:31:14 -0400 Subject: [PATCH 3/4] missed staging a rename in last commit --- libraries/chain/controller.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index 6d455fb959..384247db91 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -247,7 +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_exit = false; + 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 From 2d0162969fbed55bdd55cc5d756830b622c31da3 Mon Sep 17 00:00:00 2001 From: Matt Witherspoon <32485495+spoonincode@users.noreply.github.com> Date: Tue, 21 Jun 2022 10:55:21 -0400 Subject: [PATCH 4/4] move integrity-hash-on options from CLI to Cfg --- plugins/chain_plugin/chain_plugin.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/chain_plugin/chain_plugin.cpp b/plugins/chain_plugin/chain_plugin.cpp index 1708edb68e..d37bb4af55 100644 --- a/plugins/chain_plugin/chain_plugin.cpp +++ b/plugins/chain_plugin/chain_plugin.cpp @@ -331,7 +331,9 @@ void chain_plugin::set_program_options(options_description& cli, options_descrip ("transaction-finality-status-success-duration-sec", bpo::value()->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()->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(), "if set, periodically prune the block log to store only configured number of most recent blocks"); @@ -373,8 +375,6 @@ void chain_plugin::set_program_options(options_description& cli, options_descrip ("terminate-at-block", bpo::value()->default_value(0), "terminate after reaching this block number (if set to a non-zero number)") ("snapshot", bpo::value(), "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") ; }