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

Avoid calling exit from inside library, and removed "create-genesis-json" startup option #1529

Merged
merged 5 commits into from
Jan 22, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
51 changes: 9 additions & 42 deletions libraries/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,18 +444,14 @@ void application_impl::startup()

if( _options->count("api-access") ) {

if(fc::exists(_options->at("api-access").as<boost::filesystem::path>()))
{
_apiaccess = fc::json::from_file( _options->at("api-access").as<boost::filesystem::path>() ).as<api_access>( 20 );
ilog( "Using api access file from ${path}",
("path", _options->at("api-access").as<boost::filesystem::path>().string()) );
}
else
{
elog("Failed to load file from ${path}",
("path", _options->at("api-access").as<boost::filesystem::path>().string()));
std::exit(EXIT_FAILURE);
}
fc::path api_access_file = _options->at("api-access").as<boost::filesystem::path>();

FC_ASSERT( fc::exists(api_access_file),
"Failed to load file from ${path}", ("path", api_access_file) );

_apiaccess = fc::json::from_file( api_access_file ).as<api_access>( 20 );
ilog( "Using api access file from ${path}",
("path", api_access_file) );
}
else
{
Expand Down Expand Up @@ -984,10 +980,6 @@ void application::set_program_options(boost::program_options::options_descriptio
;
command_line_options.add(configuration_file_options);
command_line_options.add_options()
("create-genesis-json", bpo::value<boost::filesystem::path>(),
"Path to create a Genesis State at. If a well-formed JSON file exists at the path, it will be parsed and any "
"missing fields in a Genesis State will be added, and any unknown fields will be removed. If no file or an "
"invalid file is found, it will be replaced with an example Genesis State.")
("replay-blockchain", "Rebuild object graph by replaying all blocks without validation")
("revalidate-blockchain", "Rebuild object graph by replaying all blocks with full validation")
("resync-blockchain", "Delete all blocks and re-sync with network from scratch")
Expand All @@ -1004,31 +996,6 @@ void application::initialize(const fc::path& data_dir, const boost::program_opti
my->_data_dir = data_dir;
my->_options = &options;

if( options.count("create-genesis-json") )
{
fc::path genesis_out = options.at("create-genesis-json").as<boost::filesystem::path>();
genesis_state_type genesis_state = detail::create_example_genesis();
if( fc::exists(genesis_out) )
{
try {
genesis_state = fc::json::from_file(genesis_out).as<genesis_state_type>( 20 );
} catch(const fc::exception& e) {
std::cerr << "Unable to parse existing genesis file:\n" << e.to_string()
<< "\nWould you like to replace it? [y/N] ";
char response = std::cin.get();
if( toupper(response) != 'Y' )
return;
}

std::cerr << "Updating genesis state in file " << genesis_out.generic_string() << "\n";
} else {
std::cerr << "Creating example genesis state in file " << genesis_out.generic_string() << "\n";
}
fc::json::save_to_file(genesis_state, genesis_out);

std::exit(EXIT_SUCCESS);
}

if ( options.count("io-threads") )
{
const uint16_t num_threads = options["io-threads"].as<uint16_t>();
Expand All @@ -1039,7 +1006,7 @@ void application::initialize(const fc::path& data_dir, const boost::program_opti
void application::startup()
{
try {
my->startup();
my->startup();
} catch ( const fc::exception& e ) {
elog( "${e}", ("e",e.to_detail_string()) );
throw;
Expand Down
2 changes: 1 addition & 1 deletion libraries/app/application_impl.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class application_impl : public net::node_delegate
{
}

~application_impl()
virtual ~application_impl()
{
}

Expand Down
3 changes: 3 additions & 0 deletions libraries/chain/db_management.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ void database::open(

void database::close(bool rewind)
{
if (!_opened)
return;

// TODO: Save pending tx's on close()
clear_pending();

Expand Down
6 changes: 4 additions & 2 deletions programs/delayed_node/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ int main(int argc, char** argv) {
node.initialize_plugins( options );

node.startup();

node.startup_plugins();

fc::promise<int>::ptr exit_promise = new fc::promise<int>("UNIX Signal Handler");
Expand All @@ -188,10 +189,11 @@ int main(int argc, char** argv) {
int signal = exit_promise->wait();
ilog("Exiting from signal ${n}", ("n", signal));
node.shutdown_plugins();
return 0;
node.shutdown();
return EXIT_SUCCESS;
} catch( const fc::exception& e ) {
elog("Exiting with error:\n${e}", ("e", e.to_detail_string()));
return 1;
return EXIT_FAILURE;
}
}

Expand Down
5 changes: 3 additions & 2 deletions programs/witness_node/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ int main(int argc, char** argv) {
app::load_configuration_options(data_dir, cfg_options, options);

bpo::notify(options);

node->initialize(data_dir, options);
node->initialize_plugins( options );

Expand All @@ -163,7 +164,7 @@ int main(int argc, char** argv) {
node->shutdown_plugins();
node->shutdown();
delete node;
return 0;
return EXIT_SUCCESS;
} catch( const fc::exception& e ) {
// deleting the node can yield, so do this outside the exception handler
unhandled_exception = e;
Expand All @@ -174,7 +175,7 @@ int main(int argc, char** argv) {
elog("Exiting with error:\n${e}", ("e", unhandled_exception->to_detail_string()));
node->shutdown();
delete node;
return 1;
return EXIT_FAILURE;
}
}