Load node id during node initialization
This commit is contained in:
parent
11eadb000c
commit
035c365edb
6 changed files with 24 additions and 14 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ enum class type
|
|||
all = 0, // reserved
|
||||
|
||||
generic,
|
||||
init,
|
||||
config,
|
||||
logging,
|
||||
node,
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -103,13 +103,13 @@ std::unique_ptr<nano::container_info_component> 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;
|
||||
|
@ -120,7 +120,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);
|
||||
|
@ -138,12 +138,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 },
|
||||
|
@ -348,6 +349,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 ())
|
||||
{
|
||||
|
@ -398,9 +400,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)
|
||||
{
|
||||
// Node identifier consists of first 10 characters of node id
|
||||
return node_id.pub.to_node_id ().substr (0, 10);
|
||||
}
|
||||
|
||||
/*
|
||||
* node_wrapper
|
||||
*/
|
||||
|
|
|
@ -140,6 +140,7 @@ public:
|
|||
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 @@ public:
|
|||
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 @@ public: // Testing convenience functions
|
|||
|
||||
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<container_info_component> collect_container_info (node & node, std::string const & name);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue