Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Apr 14, 2024
1 parent fa9593f commit 60a3947
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions nano/nano_node/daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ void nano::daemon::run (std::filesystem::path const & data_path, nano::node_flag
logger.info (nano::log::type::daemon, "Database backend: {}", node->store.vendor_get ());
logger.info (nano::log::type::daemon, "Start time: {:%c} UTC", fmt::gmtime (dateTime));

// IO context runner is started first and stopped last
// IO context runner should be started first and stopped last to allow asio handlers to execute during node start/stop
runner = std::make_unique<nano::thread_runner> (io_ctx, node->config.io_threads);

node->start ();
Expand All @@ -162,6 +162,11 @@ void nano::daemon::run (std::filesystem::path const & data_path, nano::node_flag
{
if (!config.rpc.child_process.enable)
{
auto stop_callback = [this, &latch] () {
logger.warn (nano::log::type::daemon, "RPC stop request received, stopping...");
latch.count_down ();
};

// Launch rpc in-process
nano::rpc_config rpc_config{ config.node.network_params.network };
auto error = nano::read_rpc_config_toml (data_path, rpc_config, flags.rpc_config_overrides);
Expand All @@ -172,12 +177,7 @@ void nano::daemon::run (std::filesystem::path const & data_path, nano::node_flag
}

rpc_config.tls_config = tls_config;
rpc_handler = std::make_unique<nano::inprocess_rpc_handler> (*node, *ipc_server, config.rpc,
[this, &latch] () {
logger.warn (nano::log::type::daemon, "RPC stop request received, stopping...");

latch.count_down ();
});
rpc_handler = std::make_unique<nano::inprocess_rpc_handler> (*node, *ipc_server, config.rpc, stop_callback);
rpc = nano::get_rpc (io_ctx, rpc_config, *rpc_handler);
rpc->start ();
}
Expand All @@ -193,12 +193,11 @@ void nano::daemon::run (std::filesystem::path const & data_path, nano::node_flag

rpc_process = std::make_unique<boost::process::child> (config.rpc.child_process.rpc_path, "--daemon", "--data_path", data_path.string (), "--network", network);
}
debug_assert (rpc || rpc_process);
}
debug_assert (rpc || rpc_process);

auto signal_handler = [this, &latch] (int signum) {
logger.warn (nano::log::type::daemon, "Interrupt signal received ({}), stopping...", to_signal_name (signum));

latch.count_down ();
};

Expand All @@ -219,7 +218,6 @@ void nano::daemon::run (std::filesystem::path const & data_path, nano::node_flag
}
ipc_server->stop ();
node->stop ();

io_ctx->stop ();
runner->join ();

Expand Down

0 comments on commit 60a3947

Please sign in to comment.