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

move --plugins from application to binary #1427 #1437

Merged
merged 16 commits into from
Jan 20, 2019
Merged
Changes from 1 commit
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
33 changes: 19 additions & 14 deletions programs/delayed_node/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fc::optional<fc::logging_config> load_logging_config_from_ini_file(const fc::pat

int main(int argc, char** argv) {
try {
app::application node;
app::application* node = new app::application();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? Now you have to delete it when you're done.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i actually changed that because of this:

(gdb) r
Starting program: /home/alfredo/CLionProjects/pull1427_2/programs/delayed_node/delayed_node 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
2133844ms th_a       main.cpp:109                  main                 ] Writing new config file at /home/alfredo/CLionProjects/pull1427_2/delayed_node_data_dir/config.ini

Program received signal SIGSEGV, Segmentation fault.
0x0000555557889fdd in graphene::chain::database::close (this=0x55555b83ab70, rewind=true) at /home/alfredo/CLionProjects/pull1427_2/libraries/chain/db_management.cpp:222
222	         uint32_t cutoff = get_dynamic_global_properties().last_irreversible_block_num;
(gdb) bt
#0  0x0000555557889fdd in graphene::chain::database::close (this=0x55555b83ab70, rewind=true) at /home/alfredo/CLionProjects/pull1427_2/libraries/chain/db_management.cpp:222
#1  0x0000555557240b11 in graphene::app::application::~application (this=0x7fffffffda00, __in_chrg=<optimized out>) at /home/alfredo/CLionProjects/pull1427_2/libraries/app/application.cpp:926
#2  0x0000555557003387 in main (argc=1, argv=0x7fffffffde48) at /home/alfredo/CLionProjects/pull1427_2/programs/delayed_node/main.cpp:63
(gdb) 

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, the destructor generates a SIGSEGV and the solution is to avoid calling the destructor? That's evil.
Does the crash also happen without your other changes? If so, this should be kept as-is and fixed properly in another issue. If not you should find the root cause and fix it properly now.

bpo::options_description app_options("Graphene Delayed Node");
bpo::options_description cfg_options("Graphene Delayed Node");
app_options.add_options()
Expand All @@ -70,14 +70,14 @@ int main(int argc, char** argv) {

bpo::variables_map options;

auto delayed_plug = node.register_plugin<delayed_node::delayed_node_plugin>();
auto history_plug = node.register_plugin<account_history::account_history_plugin>();
auto market_history_plug = node.register_plugin<market_history::market_history_plugin>();
auto delayed_plug = node->register_plugin<delayed_node::delayed_node_plugin>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps auto delayed_plug = node->register_plugin<delayed_node::delayed_node_plugin>(true);?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sense in this context, added. thanks.

auto history_plug = node->register_plugin<account_history::account_history_plugin>();
auto market_history_plug = node->register_plugin<market_history::market_history_plugin>();

try
{
bpo::options_description cli, cfg;
node.set_program_options(cli, cfg);
node->set_program_options(cli, cfg);
app_options.add(cli);
cfg_options.add(cfg);
bpo::store(bpo::parse_command_line(argc, argv, app_options), options);
Expand All @@ -88,6 +88,13 @@ int main(int argc, char** argv) {
return 1;
}

std::set<std::string> plugins = {"delayed_node", "account_history", "market_history"};
std::for_each(plugins.begin(), plugins.end(), [node](const std::string& plug) mutable {
if (!plug.empty()) {
node->enable_plugin(plug);
}
});

if( options.count("help") )
{
std::cout << app_options << "\n";
Expand Down Expand Up @@ -160,26 +167,24 @@ int main(int argc, char** argv) {
elog("Error parsing configuration file: ${e}", ("e", e.what()));
return 1;
}
if( !options.count("plugins") )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should keep the "plugins" option. We don't want to change the behaviour of the executable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is done 1326a5c

options.insert( std::make_pair( "plugins", bpo::variable_value(std::string("delayed_node account_history market_history"), true) ) );

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

node.startup();
node.startup_plugins();
node->startup();
node->startup_plugins();

fc::promise<int>::ptr exit_promise = new fc::promise<int>("UNIX Signal Handler");
fc::set_signal_handler([&exit_promise](int signal) {
exit_promise->set_value(signal);
}, SIGINT);

ilog("Started delayed node on a chain with ${h} blocks.", ("h", node.chain_database()->head_block_num()));
ilog("Chain ID is ${id}", ("id", node.chain_database()->get_chain_id()) );
ilog("Started delayed node on a chain with ${h} blocks.", ("h", node->chain_database()->head_block_num()));
ilog("Chain ID is ${id}", ("id", node->chain_database()->get_chain_id()) );

int signal = exit_promise->wait();
ilog("Exiting from signal ${n}", ("n", signal));
node.shutdown_plugins();
node->shutdown_plugins();
return 0;
} catch( const fc::exception& e ) {
elog("Exiting with error:\n${e}", ("e", e.to_detail_string()));
Expand Down