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
Show file tree
Hide file tree
Changes from 9 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
28 changes: 0 additions & 28 deletions libraries/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,6 @@ void application::set_program_options(boost::program_options::options_descriptio
("genesis-json", bpo::value<boost::filesystem::path>(), "File to read Genesis State from")
("dbg-init-key", bpo::value<string>(), "Block signing key to use for init witnesses, overrides genesis file")
("api-access", bpo::value<boost::filesystem::path>(), "JSON file specifying API permissions")
("plugins", bpo::value<string>(), "Space-separated list of plugins to activate")
("io-threads", bpo::value<uint16_t>()->implicit_value(0), "Number of IO threads, default to 0 for auto-configuration")
("enable-subscribe-to-all", bpo::value<bool>()->implicit_value(true),
"Whether allow API clients to subscribe to universal object creation and removal events")
Expand Down Expand Up @@ -1006,33 +1005,6 @@ void application::initialize(const fc::path& data_dir, const boost::program_opti
const uint16_t num_threads = options["io-threads"].as<uint16_t>();
fc::asio::default_io_service_scope::set_num_threads(num_threads);
}

std::vector<string> wanted;
if( options.count("plugins") )
{
boost::split(wanted, options.at("plugins").as<std::string>(), [](char c){return c == ' ';});
}
else
{
wanted.push_back("witness");
wanted.push_back("account_history");
wanted.push_back("market_history");
wanted.push_back("grouped_orders");
}
int es_ah_conflict_counter = 0;
for (auto& it : wanted)
{
if(it == "account_history")
++es_ah_conflict_counter;
if(it == "elasticsearch")
++es_ah_conflict_counter;

if(es_ah_conflict_counter > 1) {
elog("Can't start program with elasticsearch and account_history plugin at the same time");
std::exit(EXIT_FAILURE);
}
if (!it.empty()) enable_plugin(it);
}
}

void application::startup()
Expand Down
18 changes: 11 additions & 7 deletions libraries/app/include/graphene/app/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,17 @@ namespace graphene { namespace app {
application();
~application();

void set_program_options( boost::program_options::options_description& command_line_options,
boost::program_options::options_description& configuration_file_options )const;
void initialize(const fc::path& data_dir, const boost::program_options::variables_map&options);
void initialize_plugins( const boost::program_options::variables_map& options );
void set_program_options(boost::program_options::options_description& command_line_options,
boost::program_options::options_description& configuration_file_options)const;
void initialize(const fc::path& data_dir, const boost::program_options::variables_map& options);
void initialize_plugins(const boost::program_options::variables_map& options);
void startup();
void shutdown();
void startup_plugins();
void shutdown_plugins();

template<typename PluginType>
std::shared_ptr<PluginType> register_plugin()
{
std::shared_ptr<PluginType> register_plugin(bool auto_load = false) {
auto plug = std::make_shared<PluginType>();
plug->plugin_set_app(this);

Expand All @@ -72,6 +71,10 @@ namespace graphene { namespace app {
_cfg_options.add(plugin_cfg_options);

add_available_plugin( plug );

if (auto_load)
enable_plugin(plug->plugin_name());

return plug;
}
std::shared_ptr<abstract_plugin> get_plugin( const string& name )const;
Expand All @@ -98,8 +101,9 @@ namespace graphene { namespace app {

const application_options& get_options();

private:
void enable_plugin( const string& name );

private:
void add_available_plugin( std::shared_ptr<abstract_plugin> p );
std::shared_ptr<detail::application_impl> my;

Expand Down
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
25 changes: 21 additions & 4 deletions programs/witness_node/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <boost/filesystem.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/container/flat_set.hpp>
#include <boost/algorithm/string.hpp>

#include <graphene/utilities/git_revision.hpp>
#include <boost/algorithm/string/replace.hpp>
Expand All @@ -64,9 +65,11 @@ int main(int argc, char** argv) {
bpo::options_description cfg_options("Graphene Witness Node");
app_options.add_options()
("help,h", "Print this help message and exit.")
("data-dir,d", bpo::value<boost::filesystem::path>()->default_value("witness_node_data_dir"), "Directory containing databases, configuration file, etc.")
("data-dir,d", bpo::value<boost::filesystem::path>()->default_value("witness_node_data_dir"),
"Directory containing databases, configuration file, etc.")
("version,v", "Display version information")
;
("plugins", bpo::value<std::string>()->default_value("witness account_history market_history grouped_orders"),
"Space-separated list of plugins to activate");

bpo::variables_map options;

Expand All @@ -90,10 +93,24 @@ int main(int argc, char** argv) {
}
catch (const boost::program_options::error& e)
{
std::cerr << "Error parsing command line: " << e.what() << "\n";
return 1;
std::cerr << "Error parsing command line: " << e.what() << "\n";
return 1;
}

std::set<std::string> plugins;
boost::split(plugins, options.at("plugins").as<std::string>(), [](char c){return c == ' ';});

if(plugins.count("account_history") && plugins.count("elasticsearch")) {
std::cerr << "Plugin conflict: Cannot load both account_history plugin and elasticsearch plugin\n";
return 1;
}

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
8 changes: 4 additions & 4 deletions tests/cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ int get_available_port()
std::shared_ptr<graphene::app::application> start_application(fc::temp_directory& app_dir, int& server_port_number) {
std::shared_ptr<graphene::app::application> app1(new graphene::app::application{});

app1->register_plugin<graphene::account_history::account_history_plugin>();
app1->register_plugin< graphene::market_history::market_history_plugin >();
app1->register_plugin< graphene::witness_plugin::witness_plugin >();
app1->register_plugin< graphene::grouped_orders::grouped_orders_plugin>();
app1->register_plugin<graphene::account_history::account_history_plugin>(true);
app1->register_plugin< graphene::market_history::market_history_plugin >(true);
app1->register_plugin< graphene::witness_plugin::witness_plugin >(true);
app1->register_plugin< graphene::grouped_orders::grouped_orders_plugin>(true);
app1->startup_plugins();
boost::program_options::variables_map cfg;
#ifdef _WIN32
Expand Down