From 210f725e164936f1164efda05f535c22d6fa1750 Mon Sep 17 00:00:00 2001 From: clemahieu Date: Sun, 8 Aug 2021 13:29:42 +0100 Subject: [PATCH] Pulling network_constants reference through rpc_config rather than initializing statically. --- nano/core_test/toml.cpp | 12 ++++++------ nano/lib/rpcconfig.cpp | 23 +++++++++++++---------- nano/lib/rpcconfig.hpp | 8 ++++---- nano/load_test/entry.cpp | 2 +- nano/nano_node/daemon.cpp | 2 +- nano/nano_rpc/entry.cpp | 3 ++- nano/nano_wallet/entry.cpp | 2 +- nano/node/cli.cpp | 2 +- nano/rpc_test/rpc.cpp | 10 +++++----- 9 files changed, 34 insertions(+), 30 deletions(-) diff --git a/nano/core_test/toml.cpp b/nano/core_test/toml.cpp index 905c26af..2b880260 100644 --- a/nano/core_test/toml.cpp +++ b/nano/core_test/toml.cpp @@ -88,8 +88,8 @@ TEST (toml, rpc_config_deserialize_defaults) nano::tomlconfig t; t.read (ss); - nano::rpc_config conf; - nano::rpc_config defaults; + nano::rpc_config conf{ nano::dev::network_params.network }; + nano::rpc_config defaults{ nano::dev::network_params.network }; conf.deserialize_toml (t); ASSERT_FALSE (t.get_error ()) << t.get_error ().get_message (); @@ -717,8 +717,8 @@ TEST (toml, rpc_config_deserialize_no_defaults) nano::tomlconfig toml; toml.read (ss); - nano::rpc_config conf; - nano::rpc_config defaults; + nano::rpc_config conf{ nano::dev::network_params.network }; + nano::rpc_config defaults{ nano::dev::network_params.network }; conf.deserialize_toml (toml); ASSERT_FALSE (toml.get_error ()) << toml.get_error ().get_message (); @@ -752,8 +752,8 @@ TEST (toml, rpc_config_no_required) nano::tomlconfig toml; toml.read (ss); - nano::rpc_config conf; - nano::rpc_config defaults; + nano::rpc_config conf{ nano::dev::network_params.network }; + nano::rpc_config defaults{ nano::dev::network_params.network }; conf.deserialize_toml (toml); ASSERT_FALSE (toml.get_error ()) << toml.get_error ().get_message (); diff --git a/nano/lib/rpcconfig.cpp b/nano/lib/rpcconfig.cpp index b74d2ade..57fa5a5f 100644 --- a/nano/lib/rpcconfig.cpp +++ b/nano/lib/rpcconfig.cpp @@ -54,15 +54,17 @@ nano::error nano::rpc_secure_config::deserialize_toml (nano::tomlconfig & toml) return toml.get_error (); } -nano::rpc_config::rpc_config () : - address (boost::asio::ip::address_v6::loopback ().to_string ()) +nano::rpc_config::rpc_config (nano::network_constants & network_constants) : + rpc_process{ network_constants }, + address{ boost::asio::ip::address_v6::loopback ().to_string () } { } -nano::rpc_config::rpc_config (uint16_t port_a, bool enable_control_a) : - address (boost::asio::ip::address_v6::loopback ().to_string ()), - port (port_a), - enable_control (enable_control_a) +nano::rpc_config::rpc_config (nano::network_constants & network_constants, uint16_t port_a, bool enable_control_a) : + rpc_process{ network_constants }, + address{ boost::asio::ip::address_v6::loopback ().to_string () }, + port{ port_a }, + enable_control{ enable_control_a } { } @@ -183,8 +185,9 @@ nano::error nano::rpc_config::deserialize_toml (nano::tomlconfig & toml) return toml.get_error (); } -nano::rpc_process_config::rpc_process_config () : - ipc_address (boost::asio::ip::address_v6::loopback ().to_string ()) +nano::rpc_process_config::rpc_process_config (nano::network_constants & network_constants) : + network_constants{ network_constants }, + ipc_address{ boost::asio::ip::address_v6::loopback ().to_string () } { } @@ -206,7 +209,7 @@ nano::error read_rpc_config_toml (boost::filesystem::path const & data_path_a, n else { // Migrate - nano::rpc_config config_json_l; + nano::rpc_config config_json_l{ config_a.rpc_process.network_constants }; error = read_and_update_rpc_config (data_path_a, config_json_l); if (!error) @@ -215,7 +218,7 @@ nano::error read_rpc_config_toml (boost::filesystem::path const & data_path_a, n config_json_l.serialize_toml (toml_l); // Only write out non-default values - nano::rpc_config config_defaults_l; + nano::rpc_config config_defaults_l{ config_a.rpc_process.network_constants }; nano::tomlconfig toml_defaults_l; config_defaults_l.serialize_toml (toml_defaults_l); diff --git a/nano/lib/rpcconfig.hpp b/nano/lib/rpcconfig.hpp index 4a9a3e94..59528813 100644 --- a/nano/lib/rpcconfig.hpp +++ b/nano/lib/rpcconfig.hpp @@ -48,8 +48,8 @@ public: class rpc_process_config final { public: - rpc_process_config (); - nano::network_constants network_constants; + rpc_process_config (nano::network_constants & network_constants); + nano::network_constants & network_constants; unsigned io_threads{ (4 < std::thread::hardware_concurrency ()) ? std::thread::hardware_concurrency () : 4 }; std::string ipc_address; uint16_t ipc_port{ network_constants.default_ipc_port }; @@ -69,8 +69,8 @@ public: class rpc_config final { public: - rpc_config (); - explicit rpc_config (uint16_t, bool); + explicit rpc_config (nano::network_constants & network_constants); + explicit rpc_config (nano::network_constants & network_constants, uint16_t, bool); nano::error serialize_json (nano::jsonconfig &) const; nano::error deserialize_json (bool & upgraded_a, nano::jsonconfig &); nano::error serialize_toml (nano::tomlconfig &) const; diff --git a/nano/load_test/entry.cpp b/nano/load_test/entry.cpp index b706b207..042743f3 100644 --- a/nano/load_test/entry.cpp +++ b/nano/load_test/entry.cpp @@ -56,7 +56,7 @@ void write_config_files (boost::filesystem::path const & data_path, int index) daemon_config.serialize_toml (toml); toml.write (nano::get_node_toml_config_path (data_path)); - nano::rpc_config rpc_config; + nano::rpc_config rpc_config{ daemon_config.node.network_params.network }; rpc_config.port = rpc_port_start + index; rpc_config.enable_control = true; rpc_config.rpc_process.ipc_port = ipc_port_start + index; diff --git a/nano/nano_node/daemon.cpp b/nano/nano_node/daemon.cpp index 78d49283..3f37c206 100644 --- a/nano/nano_node/daemon.cpp +++ b/nano/nano_node/daemon.cpp @@ -119,7 +119,7 @@ void nano_daemon::daemon::run (boost::filesystem::path const & data_path, nano:: if (!config.rpc.child_process.enable) { // Launch rpc in-process - nano::rpc_config rpc_config; + 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); if (error) { diff --git a/nano/nano_rpc/entry.cpp b/nano/nano_rpc/entry.cpp index 26f34247..87b4429b 100644 --- a/nano/nano_rpc/entry.cpp +++ b/nano/nano_rpc/entry.cpp @@ -39,8 +39,9 @@ void run (boost::filesystem::path const & data_path, std::vector co boost::system::error_code error_chmod; nano::set_secure_perm_directory (data_path, error_chmod); std::unique_ptr runner; + nano::network_constants network; - nano::rpc_config rpc_config; + nano::rpc_config rpc_config{ network }; auto error = nano::read_rpc_config_toml (data_path, rpc_config, config_overrides); if (!error) { diff --git a/nano/nano_wallet/entry.cpp b/nano/nano_wallet/entry.cpp index e9bdd7da..b37c7e27 100644 --- a/nano/nano_wallet/entry.cpp +++ b/nano/nano_wallet/entry.cpp @@ -167,7 +167,7 @@ int run_wallet (QApplication & application, int argc, char * const * argv, boost if (!config.rpc.child_process.enable) { // Launch rpc in-process - nano::rpc_config rpc_config; + 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); if (error) { diff --git a/nano/node/cli.cpp b/nano/node/cli.cpp index 237764dc..1ab8fb11 100644 --- a/nano/node/cli.cpp +++ b/nano/node/cli.cpp @@ -664,7 +664,7 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map else if (type == "rpc") { valid_type = true; - nano::rpc_config config; + nano::rpc_config config{ nano::dev::network_params.network }; config.serialize_toml (toml); } else diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index f28bd6f2..4cf59f64 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -199,7 +199,7 @@ std::tuple, std::unique_ptr> add_rpc (na auto scoped_thread_name_io (std::make_unique ()); auto node_rpc_config (std::make_unique ()); auto ipc_server (std::make_unique (*node_a, *node_rpc_config)); - nano::rpc_config rpc_config (nano::get_available_port (), true); + nano::rpc_config rpc_config (node_a->network_params.network, nano::get_available_port (), true); rpc_config.rpc_process.ipc_port = node_a->config.ipc_config.transport_tcp.port; auto ipc_rpc_processor (std::make_unique (system.io_ctx, rpc_config)); auto rpc (std::make_shared (system.io_ctx, rpc_config, *ipc_rpc_processor)); @@ -5499,7 +5499,7 @@ TEST (rpc, simultaneous_calls) nano::thread_runner runner (system.io_ctx, node->config.io_threads); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); - nano::rpc_config rpc_config (nano::get_available_port (), true); + nano::rpc_config rpc_config{ nano::dev::network_params.network, nano::get_available_port (), true }; rpc_config.rpc_process.ipc_port = node->config.ipc_config.transport_tcp.port; rpc_config.rpc_process.num_ipc_connections = 8; nano::ipc_rpc_processor ipc_rpc_processor (system.io_ctx, rpc_config); @@ -5553,7 +5553,7 @@ TEST (rpc, in_process) nano::system system; auto node = add_ipc_enabled_node (system); scoped_io_thread_name_change scoped_thread_name_io; - nano::rpc_config rpc_config (nano::get_available_port (), true); + nano::rpc_config rpc_config (nano::dev::network_params.network, nano::get_available_port (), true); rpc_config.rpc_process.ipc_port = node->config.ipc_config.transport_tcp.port; nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); @@ -5572,7 +5572,7 @@ TEST (rpc, in_process) TEST (rpc_config, serialization) { - nano::rpc_config config1; + nano::rpc_config config1{ nano::dev::network_params.network }; config1.address = boost::asio::ip::address_v6::any ().to_string (); config1.port = 10; config1.enable_control = true; @@ -5583,7 +5583,7 @@ TEST (rpc_config, serialization) config1.rpc_process.num_ipc_connections = 99; nano::jsonconfig tree; config1.serialize_json (tree); - nano::rpc_config config2; + nano::rpc_config config2{ nano::dev::network_params.network }; ASSERT_NE (config2.address, config1.address); ASSERT_NE (config2.port, config1.port); ASSERT_NE (config2.enable_control, config1.enable_control);