witness_node: Implement --genesis-timestamp command line parameter

This commit is contained in:
theoreticalbts 2015-08-28 14:12:54 -04:00
parent f63cbe4868
commit 9b4e270bc4
2 changed files with 12 additions and 3 deletions

View file

@ -227,8 +227,16 @@ namespace detail {
auto initial_state = [&] { auto initial_state = [&] {
ilog("Initializing database..."); ilog("Initializing database...");
if( _options->count("genesis-json") ) if( _options->count("genesis-json") )
return fc::json::from_file(_options->at("genesis-json").as<boost::filesystem::path>()) {
.as<genesis_state_type>(); genesis_state_type genesis = fc::json::from_file(_options->at("genesis-json").as<boost::filesystem::path>()).as<genesis_state_type>();
if( _options->count("genesis-timestamp") )
{
genesis.initial_timestamp = graphene::time::now() + genesis.initial_parameters.block_interval + _options->at("genesis-timestamp").as<uint32_t>();
genesis.initial_timestamp -= genesis.initial_timestamp.sec_since_epoch() % genesis.initial_parameters.block_interval;
std::cerr << "Used genesis timestamp: " << genesis.initial_timestamp.to_iso_string() << " (PLEASE RECORD THIS)\n";
}
return genesis;
}
else else
{ {
std::string egenesis_json; std::string egenesis_json;
@ -612,6 +620,7 @@ void application::set_program_options(boost::program_options::options_descriptio
"invalid file is found, it will be replaced with an example Genesis State.") "invalid file is found, it will be replaced with an example Genesis State.")
("replay-blockchain", "Rebuild object graph by replaying all blocks") ("replay-blockchain", "Rebuild object graph by replaying all blocks")
("resync-blockchain", "Delete all blocks and re-sync with network from scratch") ("resync-blockchain", "Delete all blocks and re-sync with network from scratch")
("genesis-timestamp", bpo::value<uint32_t>(), "Replace timestamp from genesis.json with current time plus this many seconds (experts only!)")
; ;
command_line_options.add(_cli_options); command_line_options.add(_cli_options);
configuration_file_options.add(_cfg_options); configuration_file_options.add(_cfg_options);

View file

@ -48,7 +48,7 @@ void new_chain_banner( const graphene::chain::database& db )
if( db.get_slot_at_time( graphene::time::now() ) > 200 ) if( db.get_slot_at_time( graphene::time::now() ) > 200 )
{ {
std::cerr << "Your genesis seems to have an old timestamp\n" std::cerr << "Your genesis seems to have an old timestamp\n"
"Please consider using a script to produce a genesis file with a recent timestamp\n" "Please consider using the --genesis-timestamp option to give your genesis a recent timestamp\n"
"\n" "\n"
; ;
} }