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

Add ability to start pow server as child process #2331

Merged
merged 1 commit into from
Oct 15, 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
19 changes: 19 additions & 0 deletions nano/nano_node/daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,26 @@ void nano_daemon::daemon::run (boost::filesystem::path const & data_path, nano::
nano::ipc::ipc_server ipc_server (*node, config.rpc);
#if BOOST_PROCESS_SUPPORTED
std::unique_ptr<boost::process::child> rpc_process;
std::unique_ptr<boost::process::child> nano_pow_server_process;
#endif

if (config.pow_server.enable)
{
if (!boost::filesystem::exists (config.pow_server.pow_server_path))
{
std::cerr << std::string ("nano_pow_server is configured to start as a child process, however the file cannot be found at: ") + config.pow_server.pow_server_path << std::endl;
std::exit (1);
}

#if BOOST_PROCESS_SUPPORTED
auto network = node->network_params.network.get_current_network_as_string ();
nano_pow_server_process = std::make_unique<boost::process::child> (config.pow_server.pow_server_path, "--config_path", data_path / "config-nano-pow-server.toml");
#else
std::cerr << "nano_pow_server is configured to start as a child process, but this is not supported on this system. Disable startup and start the server manually." << std::endl;
std::exit (1);
#endif
}

std::unique_ptr<std::thread> rpc_process_thread;
std::unique_ptr<nano::rpc> rpc;
std::unique_ptr<nano::rpc_handler_interface> rpc_handler;
Expand Down
26 changes: 26 additions & 0 deletions nano/nano_wallet/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,28 @@ int run_wallet (QApplication & application, int argc, char * const * argv, boost

#if BOOST_PROCESS_SUPPORTED
std::unique_ptr<boost::process::child> rpc_process;
std::unique_ptr<boost::process::child> nano_pow_server_process;
#endif

if (config.pow_server.enable)
{
if (!boost::filesystem::exists (config.pow_server.pow_server_path))
{
splash->hide ();
show_error (std::string ("nano_pow_server is configured to start as a child process, however the file cannot be found at: ") + config.pow_server.pow_server_path);
std::exit (1);
}

#if BOOST_PROCESS_SUPPORTED
auto network = node->network_params.network.get_current_network_as_string ();
nano_pow_server_process = std::make_unique<boost::process::child> (config.pow_server.pow_server_path, "--config_path", data_path / "config-nano-pow-server.toml");
#else
splash->hide ();
show_error ("nano_pow_server is configured to start as a child process, but this is not supported on this system. Disable startup and start the server manually.");
std::exit (1);
#endif
}

std::unique_ptr<nano::rpc> rpc;
std::unique_ptr<nano::rpc_handler_interface> rpc_handler;
if (config.rpc_enable)
Expand Down Expand Up @@ -171,6 +192,11 @@ int run_wallet (QApplication & application, int argc, char * const * argv, boost
{
rpc_process->terminate ();
}

if (nano_pow_server_process)
{
nano_pow_server_process->terminate ();
}
#endif
runner.stop_event_processing ();
});
Expand Down
2 changes: 2 additions & 0 deletions nano/node/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ add_library (node
payment_observer_processor.cpp
portmapping.hpp
portmapping.cpp
node_pow_server_config.hpp
node_pow_server_config.cpp
repcrawler.hpp
repcrawler.cpp
testing.hpp
Expand Down
23 changes: 15 additions & 8 deletions nano/node/daemonconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@ nano::error nano::daemon_config::serialize_toml (nano::tomlconfig & toml)
opencl_l.put ("enable", opencl_enable);
toml.put_child ("opencl", opencl_l);

nano::tomlconfig pow_server_l;
pow_server.serialize_toml (pow_server_l);
nano::tomlconfig pow_server (pow_server_l);
toml.put_child ("nano_pow_server", pow_server);

return toml.get_error ();
}

nano::error nano::daemon_config::deserialize_toml (nano::tomlconfig & toml)
{
auto rpc_l (toml.get_optional_child ("rpc"));

if (!toml.get_error () && rpc_l)
{
rpc_l->get_optional<bool> ("enable", rpc_enable);
Expand All @@ -50,14 +54,17 @@ nano::error nano::daemon_config::deserialize_toml (nano::tomlconfig & toml)
node.deserialize_toml (*node_l);
}

if (!toml.get_error ())
auto opencl_l (toml.get_optional_child ("opencl"));
if (!toml.get_error () && opencl_l)
{
auto opencl_l (toml.get_optional_child ("opencl"));
if (!toml.get_error () && opencl_l)
{
opencl_l->get_optional<bool> ("enable", opencl_enable);
opencl.deserialize_toml (*opencl_l);
}
opencl_l->get_optional<bool> ("enable", opencl_enable);
opencl.deserialize_toml (*opencl_l);
}

auto pow_l (toml.get_optional_child ("nano_pow_server"));
if (!toml.get_error () && pow_l)
{
pow_server.deserialize_toml (*pow_l);
}

return toml.get_error ();
Expand Down
2 changes: 2 additions & 0 deletions nano/node/daemonconfig.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <nano/lib/errors.hpp>
#include <nano/node/node_pow_server_config.hpp>
#include <nano/node/node_rpc_config.hpp>
#include <nano/node/nodeconfig.hpp>
#include <nano/node/openclconfig.hpp>
Expand All @@ -25,6 +26,7 @@ class daemon_config
nano::node_config node;
bool opencl_enable{ false };
nano::opencl_config opencl;
nano::node_pow_server_config pow_server;
boost::filesystem::path data_path;
unsigned json_version () const
{
Expand Down
19 changes: 19 additions & 0 deletions nano/node/node_pow_server_config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <nano/lib/config.hpp>
#include <nano/lib/rpcconfig.hpp>
#include <nano/lib/tomlconfig.hpp>
#include <nano/node/node_pow_server_config.hpp>

nano::error nano::node_pow_server_config::serialize_toml (nano::tomlconfig & toml) const
{
toml.put ("enable", enable, "Enable or disable starting Nano PoW Server as a child process.\ntype:bool");
toml.put ("nano_pow_server_path", pow_server_path, "Path to the nano_pow_server executable.\ntype:string,path");
return toml.get_error ();
}

nano::error nano::node_pow_server_config::deserialize_toml (nano::tomlconfig & toml)
{
toml.get_optional<bool> ("enable", enable);
toml.get_optional<std::string> ("nano_pow_server_path", pow_server_path);

return toml.get_error ();
}
38 changes: 38 additions & 0 deletions nano/node/node_pow_server_config.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#pragma once

#include <nano/lib/rpcconfig.hpp>

#include <boost/dll/runtime_symbol_info.hpp>
#include <boost/filesystem.hpp>

#include <string>

namespace nano
{
class tomlconfig;

inline std::string get_default_pow_server_filepath ()
{
boost::system::error_code err;
auto running_executable_filepath = boost::dll::program_location (err);

// Construct the nano_pow_server executable file path based on where the currently running executable is found.
auto pow_server_filepath = running_executable_filepath.parent_path () / "nano_pow_server";
if (running_executable_filepath.has_extension ())
{
pow_server_filepath.replace_extension (running_executable_filepath.extension ());
}

return pow_server_filepath.string ();
}

class node_pow_server_config final
{
public:
nano::error serialize_toml (nano::tomlconfig & toml) const;
nano::error deserialize_toml (nano::tomlconfig & toml);

bool enable{ false };
std::string pow_server_path{ nano::get_default_pow_server_filepath () };
};
}