diff --git a/nano/core_test/node.cpp b/nano/core_test/node.cpp index 07b2fa5cd1..34db092d75 100644 --- a/nano/core_test/node.cpp +++ b/nano/core_test/node.cpp @@ -4314,19 +4314,19 @@ TEST (node_config, node_id_private_key_persistence) auto priv_key_filename = path / "node_id_private.key"; // check that the key generated is random when the key does not exist - nano::keypair kp1 = nano::load_or_create_node_id (path, system.nlogger); + nano::keypair kp1 = nano::load_or_create_node_id (path); std::filesystem::remove (priv_key_filename); - nano::keypair kp2 = nano::load_or_create_node_id (path, system.nlogger); + nano::keypair kp2 = nano::load_or_create_node_id (path); ASSERT_NE (kp1.prv, kp2.prv); // check that the key persists - nano::keypair kp3 = nano::load_or_create_node_id (path, system.nlogger); + nano::keypair kp3 = nano::load_or_create_node_id (path); ASSERT_EQ (kp2.prv, kp3.prv); // write the key file manually and check that right key is loaded std::ofstream ofs (priv_key_filename.string (), std::ofstream::out | std::ofstream::trunc); ofs << "3F28D035B8AA75EA53DF753BFD065CF6138E742971B2C99B84FD8FE328FED2D9" << std::flush; ofs.close (); - nano::keypair kp4 = nano::load_or_create_node_id (path, system.nlogger); + nano::keypair kp4 = nano::load_or_create_node_id (path); ASSERT_EQ (kp4.prv, nano::keypair ("3F28D035B8AA75EA53DF753BFD065CF6138E742971B2C99B84FD8FE328FED2D9").prv); } diff --git a/nano/lib/logging_enums.hpp b/nano/lib/logging_enums.hpp index 83f49fafa1..0440307823 100644 --- a/nano/lib/logging_enums.hpp +++ b/nano/lib/logging_enums.hpp @@ -22,6 +22,7 @@ enum class type all = 0, // reserved generic, + init, config, logging, node, diff --git a/nano/nano_node/daemon.cpp b/nano/nano_node/daemon.cpp index 08b5108384..4f2f8dffe1 100644 --- a/nano/nano_node/daemon.cpp +++ b/nano/nano_node/daemon.cpp @@ -77,7 +77,9 @@ void nano::daemon::run (std::filesystem::path const & data_path, nano::node_flag nano::network_params network_params{ nano::network_constants::active_network }; nano::daemon_config config{ data_path, network_params }; auto error = nano::read_node_config_toml (data_path, config, flags.config_overrides); + nano::set_use_memory_pools (config.node.use_memory_pools); + if (!error) { error = nano::flags_config_conflicts (flags, config.node); diff --git a/nano/nano_node/daemon.hpp b/nano/nano_node/daemon.hpp index 3b4c232e77..b3d365ce39 100644 --- a/nano/nano_node/daemon.hpp +++ b/nano/nano_node/daemon.hpp @@ -6,7 +6,7 @@ class node_flags; class daemon { - nano::nlogger nlogger; + nano::nlogger nlogger{ "daemon" }; public: void run (std::filesystem::path const &, nano::node_flags const & flags); diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 41322c4bde..a65da21e36 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -104,13 +104,13 @@ std::unique_ptr nano::collect_container_info (re return composite; } -nano::keypair nano::load_or_create_node_id (std::filesystem::path const & application_path, nano::nlogger & nlogger) +nano::keypair nano::load_or_create_node_id (std::filesystem::path const & application_path) { auto node_private_key_path = application_path / "node_id_private.key"; std::ifstream ifs (node_private_key_path.c_str ()); if (ifs.good ()) { - nlogger.debug (nano::log::type::node, "Reading node id from: '{}'", node_private_key_path.string ()); + nano::default_logger ().info (nano::log::type::init, "Reading node id from: '{}'", node_private_key_path.string ()); std::string node_private_key; ifs >> node_private_key; @@ -121,7 +121,7 @@ nano::keypair nano::load_or_create_node_id (std::filesystem::path const & applic else { // no node_id found, generate new one - nlogger.debug (nano::log::type::node, "Generating a new node id, saving to: '{}'", node_private_key_path.string ()); + nano::default_logger ().info (nano::log::type::init, "Generating a new node id, saving to: '{}'", node_private_key_path.string ()); nano::keypair kp; std::ofstream ofs (node_private_key_path.c_str (), std::ofstream::out | std::ofstream::trunc); @@ -139,12 +139,13 @@ nano::node::node (boost::asio::io_context & io_ctx_a, uint16_t peering_port_a, s } nano::node::node (boost::asio::io_context & io_ctx_a, std::filesystem::path const & application_path_a, nano::node_config const & config_a, nano::work_pool & work_a, nano::node_flags flags_a, unsigned seq) : + node_id{ load_or_create_node_id (application_path_a) }, write_database_queue (!flags_a.force_use_write_database_queue && (config_a.rocksdb_config.enable)), io_ctx (io_ctx_a), node_initialized_latch (1), config (config_a), network_params{ config.network_params }, - nlogger{ "node" }, + nlogger{ make_logger_identifier (node_id) }, 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 }, @@ -353,6 +354,7 @@ nano::node::node (boost::asio::io_context & io_ctx_a, std::filesystem::path cons nlogger.info (nano::log::type::node, "Data path: {}", application_path.string ()); nlogger.info (nano::log::type::node, "Work pool threads: {} ({})", work.threads.size (), (work.opencl ? "OpenCL" : "CPU")); nlogger.info (nano::log::type::node, "Work peers: {}", config.work_peers.size ()); + nlogger.info (nano::log::type::node, "Node ID: {}", node_id.pub.to_node_id ()); if (!work_generation_enabled ()) { @@ -403,9 +405,6 @@ nano::node::node (boost::asio::io_context & io_ctx_a, std::filesystem::path cons } } - node_id = nano::load_or_create_node_id (application_path, nlogger); - nlogger.info (nano::log::type::node, "Node ID: {}", node_id.pub.to_node_id ()); - if ((network_params.network.is_live_network () || network_params.network.is_beta_network ()) && !flags.inactive_node) { auto const bootstrap_weights = get_bootstrap_weights (); @@ -1476,6 +1475,12 @@ nano::telemetry_data nano::node::local_telemetry () const return telemetry_data; } +std::string nano::node::make_logger_identifier (const nano::keypair & node_id) +{ + // Only log the last 6 characters of the node ID for readability + return "node_" + node_id.pub.to_account ().substr (60, 6); +} + /* * node_wrapper */ diff --git a/nano/node/node.hpp b/nano/node/node.hpp index e656ad60d5..ee228b0739 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -140,6 +140,7 @@ class node final : public std::enable_shared_from_this nano::telemetry_data local_telemetry () const; public: + const nano::keypair node_id; nano::write_database_queue write_database_queue; boost::asio::io_context & io_ctx; boost::latch node_initialized_latch; @@ -175,7 +176,6 @@ class node final : public std::enable_shared_from_this nano::block_processor block_processor; nano::block_arrival block_arrival; nano::local_vote_history history; - nano::keypair node_id; nano::block_uniquer block_uniquer; nano::vote_uniquer vote_uniquer; nano::confirmation_height_processor confirmation_height_processor; @@ -227,9 +227,11 @@ class node final : public std::enable_shared_from_this private: void long_inactivity_cleanup (); + + static std::string make_logger_identifier (nano::keypair const & node_id); }; -nano::keypair load_or_create_node_id (std::filesystem::path const & application_path, nano::nlogger &); +nano::keypair load_or_create_node_id (std::filesystem::path const & application_path); std::unique_ptr collect_container_info (node & node, std::string const & name);