Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Jan 16, 2024
1 parent 848bc99 commit 29747e8
Show file tree
Hide file tree
Showing 16 changed files with 41 additions and 31 deletions.
2 changes: 1 addition & 1 deletion nano/core_test/core_test_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void force_nano_dev_network ();

GTEST_API_ int main (int argc, char ** argv)
{
nano::initialize_logging (nano::log::preset::tests);
nano::nlogger::initialize (nano::load_log_config (nano::log_config::tests_default ()));
nano::set_file_descriptor_limit (OPEN_FILE_DESCRIPTORS_LIMIT);
nano::force_nano_dev_network ();
nano::node_singleton_memory_pool_purge_guard memory_pool_cleanup_guard;
Expand Down
4 changes: 4 additions & 0 deletions nano/lib/config.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <nano/lib/blocks.hpp>
#include <nano/lib/config.hpp>
#include <nano/lib/logging.hpp>

#include <boost/format.hpp>
#include <boost/lexical_cast.hpp>
Expand Down Expand Up @@ -403,10 +404,12 @@ nano::tomlconfig nano::load_toml_file (const std::filesystem::path & config_file
// First try to load config from the current working directory, then from the node data directory
if (auto toml = try_load_toml (config_filename); toml)
{
nano::default_logger ().info (nano::log::type::config, "Config for `{}` loaded from current working directory", config_filename.string ());
return *toml;
}
if (auto toml = try_load_toml (data_path / config_filename); toml)
{
nano::default_logger ().info (nano::log::type::config, "Config for `{}` loaded from node data directory ({})", config_filename.string (), data_path.string ());
return *toml;
}

Expand All @@ -417,5 +420,6 @@ nano::tomlconfig nano::load_toml_file (const std::filesystem::path & config_file
{
throw std::runtime_error (error.get_message ());
}
nano::default_logger ().info (nano::log::type::config, "Config for `{}` not found, using default configuration", config_filename.string ());
return toml;
}
2 changes: 1 addition & 1 deletion nano/load_test/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ account_info account_info_rpc (boost::asio::io_context & ioc, tcp::resolver::res
/** This launches a node and fires a lot of send/recieve RPC requests at it (configurable), then other nodes are tested to make sure they observe these blocks as well. */
int main (int argc, char * const * argv)
{
nano::initialize_logging (nano::log::preset::tests);
nano::nlogger::initialize (nano::load_log_config (nano::log_config::tests_default ()));
nano::force_nano_dev_network ();

boost::program_options::options_description description ("Command line options");
Expand Down
5 changes: 3 additions & 2 deletions nano/nano_node/daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ constexpr std::size_t OPEN_FILE_DESCRIPTORS_LIMIT = 16384;

void nano::daemon::run (std::filesystem::path const & data_path, nano::node_flags const & flags)
{
nano::initialize_logging (nano::log::preset::daemon);
nano::nlogger::initialize (nano::load_log_config (nano::log_config::daemon_default (), data_path, flags.config_overrides));

nlogger.info (nano::log::type::daemon, "Daemon started");

Expand All @@ -72,6 +72,7 @@ void nano::daemon::run (std::filesystem::path const & data_path, nano::node_flag
std::filesystem::create_directories (data_path);
boost::system::error_code error_chmod;
nano::set_secure_perm_directory (data_path, error_chmod);

std::unique_ptr<nano::thread_runner> runner;
nano::network_params network_params{ nano::network_constants::active_network };
nano::daemon_config config{ data_path, network_params };
Expand Down Expand Up @@ -229,5 +230,5 @@ void nano::daemon::run (std::filesystem::path const & data_path, nano::node_flag
nlogger.critical (nano::log::type::daemon, "Error deserializing config: {}", error.get_message ());
}

nlogger.info (nano::log::type::daemon, "Daemon exiting...");
nlogger.info (nano::log::type::daemon, "Daemon exiting");
}
4 changes: 2 additions & 2 deletions nano/nano_node/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class address_library_pair

int main (int argc, char * const * argv)
{
nano::set_umask ();
nano::initialize_logging ();
nano::set_umask (); // Make sure the process umask is set before any files are created
nano::nlogger::initialize (nano::log_config::cli_default ());

nano::node_singleton_memory_pool_purge_guard memory_pool_cleanup_guard;

Expand Down
16 changes: 9 additions & 7 deletions nano/nano_rpc/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@

namespace
{
nano::nlogger nlogger;

volatile sig_atomic_t sig_int_or_term = 0;

nano::nlogger nlogger{ "rpc_daemon" };

void run (std::filesystem::path const & data_path, std::vector<std::string> const & config_overrides)
{
nano::initialize_logging (nano::log::preset::daemon);

nlogger.info (nano::log::type::daemon, "Daemon started (RPC)");
nlogger.info (nano::log::type::daemon_rpc, "Daemon started (RPC)");

std::filesystem::create_directories (data_path);

boost::system::error_code error_chmod;
nano::set_secure_perm_directory (data_path, error_chmod);

std::unique_ptr<nano::thread_runner> runner;

nano::network_params network_params{ nano::network_constants::active_network };
Expand Down Expand Up @@ -83,13 +83,15 @@ void run (std::filesystem::path const & data_path, std::vector<std::string> cons
{
nlogger.critical (nano::log::type::daemon, "Error deserializing config: {}", error.get_message ());
}

nlogger.info (nano::log::type::daemon_rpc, "Daemon stopped (RPC)");
}
}

int main (int argc, char * const * argv)
{
nano::set_umask ();
nano::initialize_logging ();
nano::set_umask (); // Make sure the process umask is set before any files are created
nano::nlogger::initialize (nano::log_config::cli_default ());

boost::program_options::options_description description ("Command line options");

Expand Down
14 changes: 9 additions & 5 deletions nano/nano_wallet/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <nano/crypto_lib/random_pool.hpp>
#include <nano/lib/cli.hpp>
#include <nano/lib/errors.hpp>
#include <nano/lib/logging.hpp>
#include <nano/lib/rpcconfig.hpp>
#include <nano/lib/thread_runner.hpp>
#include <nano/lib/tlsconfig.hpp>
Expand All @@ -25,7 +26,7 @@

namespace
{
nano::nlogger nlogger;
nano::nlogger nlogger{ "wallet_daemon" };

void show_error (std::string const & message_a)
{
Expand Down Expand Up @@ -73,9 +74,9 @@ nano::error read_wallet_config (nano::wallet_config & config_a, std::filesystem:

int run_wallet (QApplication & application, int argc, char * const * argv, std::filesystem::path const & data_path, nano::node_flags const & flags)
{
nano::initialize_logging (nano::log::preset::daemon);
nano::nlogger::initialize (nano::load_log_config (nano::log_config::daemon_default (), data_path, flags.config_overrides));

nlogger.info (nano::log::type::daemon, "Daemon started (wallet)");
nlogger.info (nano::log::type::daemon_wallet, "Daemon started (wallet)");

int result (0);
nano_qt::eventloop_processor processor;
Expand Down Expand Up @@ -237,13 +238,16 @@ int run_wallet (QApplication & application, int argc, char * const * argv, std::
splash->hide ();
show_error ("Error deserializing config: " + error.get_message ());
}

nlogger.info (nano::log::type::daemon_wallet, "Daemon exiting (wallet)");

return result;
}

int main (int argc, char * const * argv)
{
nano::set_umask ();
nano::initialize_logging ();
nano::set_umask (); // Make sure the process umask is set before any files are created
nano::nlogger::initialize (nano::log_config::cli_default ());

nano::node_singleton_memory_pool_purge_guard memory_pool_cleanup_guard;

Expand Down
2 changes: 0 additions & 2 deletions nano/node/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,6 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map

if (vm.count ("initialize"))
{
nano::initialize_logging (nano::log::preset::daemon);

auto node_flags = nano::inactive_node_flag_defaults ();
node_flags.read_only = false;
nano::update_flags (node_flags, vm);
Expand Down
6 changes: 4 additions & 2 deletions nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ nano::node::node (boost::asio::io_context & io_ctx_a, std::filesystem::path cons
node_initialized_latch (1),
config (config_a),
network_params{ config.network_params },
nlogger{ "node" },
stats (config.stats_config),
workers{ config.background_threads, nano::thread_role::name::worker },
bootstrap_workers{ config.bootstrap_serving_threads, nano::thread_role::name::bootstrap_worker },
Expand Down Expand Up @@ -1484,13 +1485,14 @@ nano::node_wrapper::node_wrapper (std::filesystem::path const & path_a, std::fil
io_context (std::make_shared<boost::asio::io_context> ()),
work{ network_params.network, 1 }
{
boost::system::error_code error_chmod;

/*
* @warning May throw a filesystem exception
*/
std::filesystem::create_directories (path_a);

boost::system::error_code error_chmod;
nano::set_secure_perm_directory (path_a, error_chmod);

nano::daemon_config daemon_config{ path_a, network_params };
auto error = nano::read_node_config_toml (config_path_a, daemon_config, node_flags_a.config_overrides);
if (error)
Expand Down
4 changes: 1 addition & 3 deletions nano/node/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ outbound_bandwidth_limiter::config outbound_bandwidth_limiter_config (node_confi

class node final : public std::enable_shared_from_this<nano::node>
{
public:
nano::nlogger nlogger;

public:
node (boost::asio::io_context &, uint16_t, std::filesystem::path const &, nano::work_pool &, nano::node_flags = nano::node_flags (), unsigned seq = 0);
node (boost::asio::io_context &, std::filesystem::path const &, nano::node_config const &, nano::work_pool &, nano::node_flags = nano::node_flags (), unsigned seq = 0);
Expand Down Expand Up @@ -148,6 +145,7 @@ class node final : public std::enable_shared_from_this<nano::node>
boost::latch node_initialized_latch;
nano::node_config config;
nano::network_params & network_params;
nano::nlogger nlogger;
nano::stats stats;
nano::thread_pool workers;
nano::thread_pool bootstrap_workers;
Expand Down
2 changes: 2 additions & 0 deletions nano/node/nodeconfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <nano/lib/diagnosticsconfig.hpp>
#include <nano/lib/errors.hpp>
#include <nano/lib/lmdbconfig.hpp>
#include <nano/lib/logging.hpp>
#include <nano/lib/numbers.hpp>
#include <nano/lib/rocksdbconfig.hpp>
#include <nano/lib/stats.hpp>
Expand Down Expand Up @@ -45,6 +46,7 @@ class node_config

bool upgrade_json (unsigned, nano::jsonconfig &);
nano::account random_representative () const;

nano::network_params network_params;
std::optional<uint16_t> peering_port{};
nano::scheduler::optimistic_config optimistic_scheduler;
Expand Down
2 changes: 1 addition & 1 deletion nano/qt_test/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void force_nano_dev_network ();

int main (int argc, char ** argv)
{
nano::initialize_logging (nano::log::preset::tests);
nano::nlogger::initialize (nano::load_log_config (nano::log_config::tests_default ()));
nano::force_nano_dev_network ();
nano::node_singleton_memory_pool_purge_guard memory_pool_cleanup_guard;
QApplication application (argc, argv);
Expand Down
2 changes: 1 addition & 1 deletion nano/rpc/rpc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class rpc
return acceptor.local_endpoint ().port ();
}

nano::nlogger nlogger;
nano::nlogger nlogger{ "rpc" };
nano::rpc_config config;
boost::asio::ip::tcp::acceptor acceptor;
boost::asio::io_context & io_ctx;
Expand Down
2 changes: 1 addition & 1 deletion nano/rpc_test/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void force_nano_dev_network ();

int main (int argc, char ** argv)
{
nano::initialize_logging (nano::log::preset::tests);
nano::nlogger::initialize (nano::load_log_config (nano::log_config::tests_default ()));
nano::force_nano_dev_network ();
nano::set_use_memory_pools (false);
nano::node_singleton_memory_pool_purge_guard cleanup_guard;
Expand Down
2 changes: 1 addition & 1 deletion nano/slow_test/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void force_nano_dev_network ();

int main (int argc, char ** argv)
{
nano::initialize_logging (nano::log::preset::tests);
nano::nlogger::initialize (nano::load_log_config (nano::log_config::tests_default ()));
nano::force_nano_dev_network ();
nano::node_singleton_memory_pool_purge_guard memory_pool_cleanup_guard;
testing::InitGoogleTest (&argc, argv);
Expand Down
3 changes: 1 addition & 2 deletions nano/test_common/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -618,10 +618,9 @@ uint16_t nano::test::system::get_available_port (bool can_be_zero)
}
}

// Makes sure everything is cleaned up
void nano::test::cleanup_dev_directories_on_exit ()
{
// Makes sure everything is cleaned up
nano::logging::release_file_sink ();
// Clean up tmp directories created by the tests. Since it's sometimes useful to
// see log files after test failures, an environment variable is supported to
// retain the files.
Expand Down

0 comments on commit 29747e8

Please sign in to comment.