diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index f9c59f26b6..2070329114 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -37,6 +37,7 @@ #include #include +#include namespace eosio { namespace chain { @@ -605,7 +606,9 @@ struct controller_impl { } ilog( "Snapshot loaded, lib: ${lib}", ("lib", head->block_num) ); - init(check_shutdown); + init(std::move(check_shutdown)); + if (conf.revert_to_mapped_mode) + db.revert_to_mapped_mode(); ilog( "Finished initialization from snapshot" ); } catch (boost::interprocess::bad_alloc& e) { elog( "Failed initialization from snapshot - db storage not configured to have enough storage for the provided snapshot, please increase and retry snapshot" ); @@ -621,7 +624,7 @@ struct controller_impl { ("genesis_chain_id", genesis_chain_id)("controller_chain_id", chain_id) ); - this->shutdown = shutdown; + this->shutdown = std::move(shutdown); if( fork_db.head() ) { if( read_mode == db_read_mode::IRREVERSIBLE && fork_db.head()->id != fork_db.root()->id ) { fork_db.rollback_head_to_root(); @@ -643,14 +646,14 @@ struct controller_impl { } else { blog.reset( genesis, head->block ); } - init(check_shutdown); + init(std::move(check_shutdown)); } void startup(std::function shutdown, std::function check_shutdown) { EOS_ASSERT( db.revision() >= 1, database_exception, "This version of controller::startup does not work with a fresh state database." ); EOS_ASSERT( fork_db.head(), fork_database_exception, "No existing fork database despite existing chain state. Replay required." ); - this->shutdown = shutdown; + this->shutdown = std::move(shutdown); uint32_t lib_num = fork_db.root()->block_num; auto first_block_num = blog.first_block_num(); if( auto blog_head = blog.head() ) { @@ -673,7 +676,7 @@ struct controller_impl { } head = fork_db.head(); - init(check_shutdown); + init(std::move(check_shutdown)); } diff --git a/libraries/chain/include/eosio/chain/controller.hpp b/libraries/chain/include/eosio/chain/controller.hpp index 21c1bc9620..945bad7ce8 100644 --- a/libraries/chain/include/eosio/chain/controller.hpp +++ b/libraries/chain/include/eosio/chain/controller.hpp @@ -79,6 +79,7 @@ namespace eosio { namespace chain { bool disable_replay_opts = false; bool contracts_console = false; bool allow_ram_billing_in_notify = false; + bool revert_to_mapped_mode = false; 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; diff --git a/libraries/chainbase b/libraries/chainbase index e7a9b5a2d8..6cce710669 160000 --- a/libraries/chainbase +++ b/libraries/chainbase @@ -1 +1 @@ -Subproject commit e7a9b5a2d829127d0acb37c8d850bd645bbaa600 +Subproject commit 6cce7106694a815f8a6045eaa93cad24583a2105 diff --git a/plugins/chain_plugin/chain_plugin.cpp b/plugins/chain_plugin/chain_plugin.cpp index 6327bc118c..e58985e65f 100644 --- a/plugins/chain_plugin/chain_plugin.cpp +++ b/plugins/chain_plugin/chain_plugin.cpp @@ -936,8 +936,10 @@ void chain_plugin_impl::plugin_initialize(const variables_map& options) { // when loading a snapshot, all the state will be modified, so use the `shared` mode instead // of `copy_on_write` to lower memory requirements - if (snapshot_path && chain_config->db_map_mode == pinnable_mapped_file::mapped) + if (snapshot_path && chain_config->db_map_mode == pinnable_mapped_file::mapped) { chain_config->db_map_mode = pinnable_mapped_file::mapped_shared; + chain_config->revert_to_mapped_mode = true; // revert to `mapped` mode after loading snapshot. + } #ifdef EOSIO_EOS_VM_OC_RUNTIME_ENABLED if( options.count("eos-vm-oc-cache-size-mb") )