提交 4012876d 编写于 作者: A arhag

nodeos can now extract the genesis state from blocks.log

Also return correct error code when database is dirty.
上级 1fbc65b8
......@@ -246,6 +246,8 @@ namespace eosio { namespace chain {
3100003, "unknown transaction" )
FC_DECLARE_DERIVED_EXCEPTION( fixed_reversible_db_exception, misc_exception,
3100004, "corrupted reversible block database was fixed" )
FC_DECLARE_DERIVED_EXCEPTION( extract_genesis_state_exception, misc_exception,
3100005, "extracted genesis state from blocks.log" )
FC_DECLARE_DERIVED_EXCEPTION( missing_plugin_exception, chain_exception,
3110000, "missing plugin exception" )
......
......@@ -117,7 +117,9 @@ void chain_plugin::set_program_options(options_description& cli, options_descrip
("wasm-runtime", bpo::value<eosio::chain::wasm_interface::vm_type>()->value_name("wavm/binaryen"), "Override default WASM runtime")
("chain-state-db-size-mb", bpo::value<uint64_t>()->default_value(config::default_state_size / (1024 * 1024)), "Maximum size (in MB) of the chain state database")
("reversible-blocks-db-size-mb", bpo::value<uint64_t>()->default_value(config::default_reversible_cache_size / (1024 * 1024)), "Maximum size (in MB) of the reversible blocks database")
("contracts-console", bpo::bool_switch()->default_value(false),
"print contract's output to console")
;
#warning TODO: rate limiting
/*("per-authorized-account-transaction-msg-rate-limit-time-frame-sec", bpo::value<uint32_t>()->default_value(default_per_auth_account_time_frame_seconds),
......@@ -128,8 +130,12 @@ void chain_plugin::set_program_options(options_description& cli, options_descrip
"The time frame, in seconds, that the per-code-account-transaction-msg-rate-limit is imposed over.")
("per-code-account-transaction-msg-rate-limit", bpo::value<uint32_t>()->default_value(default_per_code_account),
"Limits the maximum rate of transaction messages that an account's code is allowed each per-code-account-transaction-msg-rate-limit-time-frame-sec.")*/
;
cli.add_options()
("print-genesis-json", bpo::bool_switch()->default_value(false),
"extract genesis_state from blocks.log as JSON, print to console, and exit")
("extract-genesis-json", bpo::value<bfs::path>(),
"extract genesis_state from blocks.log as JSON, write into specified file, and exit")
("fix-reversible-blocks", bpo::bool_switch()->default_value(false),
"recovers reversible block database if that database is in a bad state")
("force-all-checks", bpo::bool_switch()->default_value(false),
......@@ -140,8 +146,6 @@ void chain_plugin::set_program_options(options_description& cli, options_descrip
"clear chain state database, recover as many blocks as possible from the block log, and then replay those blocks")
("delete-all-blocks", bpo::bool_switch()->default_value(false),
"clear chain state database and block log")
("contracts-console", bpo::bool_switch()->default_value(false),
"print contract's output to console")
;
}
......@@ -209,6 +213,27 @@ void chain_plugin::plugin_initialize(const variables_map& options) {
my->chain_config->force_all_checks = options.at("force-all-checks").as<bool>();
my->chain_config->contracts_console = options.at("contracts-console").as<bool>();
if( options.count("extract-genesis-json") || options.at("print-genesis-json").as<bool>() ) {
auto gs = block_log::extract_genesis_state( my->blocks_dir );
if( options.at("print-genesis-json").as<bool>() ) {
ilog( "Genesis JSON:\n${genesis}", ("genesis", json::to_pretty_string(gs)) );
}
if( options.count("extract-genesis-json") ) {
auto p = options.at("extract-genesis-json").as<bfs::path>();
if( p.is_relative() ) {
p = bfs::current_path() / p;
}
fc::json::save_to_file( gs, p, true );
ilog( "Saved genesis JSON to '${path}'", ("path", p.generic_string()) );
}
EOS_THROW( extract_genesis_state_exception, "extracted genesis state from blocks.log" );
}
if( options.at("delete-all-blocks").as<bool>() ) {
ilog("Deleting state database and blocks");
fc::remove_all( my->chain_config->state_dir );
......
......@@ -80,11 +80,13 @@ void initialize_logging()
}
enum return_codes {
OTHER_FAIL = -2,
INITIALIZE_FAIL = -1,
SUCCESS = 0,
BAD_ALLOC = 1,
FIXED_REVERSIBLE = 2
OTHER_FAIL = -2,
INITIALIZE_FAIL = -1,
SUCCESS = 0,
BAD_ALLOC = 1,
DATABASE_DIRTY = 2,
FIXED_REVERSIBLE = 3,
EXTRACTED_GENESIS = 4
};
int main(int argc, char** argv)
......@@ -103,6 +105,8 @@ int main(int argc, char** argv)
ilog("eosio root is ${root}", ("root", root.string()));
app().startup();
app().exec();
} catch( const extract_genesis_state_exception& e ) {
return EXTRACTED_GENESIS;
} catch( const fixed_reversible_db_exception& e ) {
return FIXED_REVERSIBLE;
} catch( const fc::exception& e ) {
......@@ -117,11 +121,14 @@ int main(int argc, char** argv)
} catch( const std::runtime_error& e ) {
if( std::string(e.what()) == "database dirty flag set" ) {
elog( "database dirty flag set (likely due to unclean shutdown): replay required" );
return DATABASE_DIRTY;
} else if( std::string(e.what()) == "database metadata dirty flag set" ) {
elog( "database metadata dirty flag set (likely due to unclean shutdown): replay required" );
return DATABASE_DIRTY;
} else {
elog( "${e}", ("e",e.what()));
}
return OTHER_FAIL;
} catch( const std::exception& e ) {
elog("${e}", ("e",e.what()));
return OTHER_FAIL;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册