Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the default peering port for daemon start up #3662

Merged
merged 5 commits into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions nano/nano_node/daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ void nano_daemon::daemon::run (boost::filesystem::path const & data_path, nano::
logger.always_log (boost::format ("Open file descriptors limit is %1%") % file_descriptor_limit);
}

// for the daemon start up, if the user hasn't specified a port in
// the config, we must use the default peering port for the network
//
if (!config.node.peering_port.has_value ())
{
config.node.peering_port = network_params.network.default_node_port;
}

auto node (std::make_shared<nano::node> (io_ctx, data_path, config.node, opencl_work, flags));
if (!node->init_error ())
{
Expand Down
11 changes: 10 additions & 1 deletion nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ nano::node::node (boost::asio::io_context & io_ctx_a, boost::filesystem::path co
gap_cache (*this),
ledger (store, stats, network_params.ledger, flags_a.generate_cache),
checker (config.signature_checker_threads),
network (*this, config.peering_port),
// empty `config.peering_port` means the user made no port choice at all;
// otherwise, any value is considered, with `0` having the special meaning of 'let the OS pick a port instead'
//
network (*this, config.peering_port.has_value () ? *config.peering_port : 0),
telemetry (std::make_shared<nano::telemetry> (network, workers, observers.telemetry, stats, network_params, flags.disable_ongoing_telemetry_requests)),
bootstrap_initiator (*this),
// BEWARE: `bootstrap` takes `network.port` instead of `config.peering_port` because when the user doesn't specify
Expand Down Expand Up @@ -631,7 +634,10 @@ void nano::node::start ()
{
network.port = bootstrap.port;
}

logger.always_log (boost::str (boost::format ("Node started with peering port `%1%`.") % network.port));
}

if (!flags.disable_backup)
{
backup_wallet ();
Expand Down Expand Up @@ -702,6 +708,9 @@ void nano::node::keepalive_preconfigured (std::vector<std::string> const & peers
{
for (auto i (peers_a.begin ()), n (peers_a.end ()); i != n; ++i)
{
// can't use `network.port` here because preconfigured peers are referenced
// just by their address, so we rely on them listening on the default port
//
keepalive (*i, network_params.network.default_node_port);
}
}
Expand Down
18 changes: 14 additions & 4 deletions nano/node/nodeconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ std::string const default_test_peer_network = nano::get_env_or_default ("NANO_DE
}

nano::node_config::node_config (nano::network_params & network_params) :
node_config (0, nano::logging (), network_params)
node_config (std::nullopt, nano::logging (), network_params)
{
}

nano::node_config::node_config (uint16_t peering_port_a, nano::logging const & logging_a, nano::network_params & network_params) :
nano::node_config::node_config (const std::optional<uint16_t> & peering_port_a, nano::logging const & logging_a, nano::network_params & network_params) :
network_params{ network_params },
peering_port{ peering_port_a },
logging{ logging_a },
Expand Down Expand Up @@ -81,7 +81,11 @@ nano::node_config::node_config (uint16_t peering_port_a, nano::logging const & l

nano::error nano::node_config::serialize_toml (nano::tomlconfig & toml) const
{
toml.put ("peering_port", peering_port, "Node peering port.\ntype:uint16");
if (peering_port.has_value ())
{
toml.put ("peering_port", *peering_port, "Node peering port.\ntype:uint16");
}

toml.put ("bootstrap_fraction_numerator", bootstrap_fraction_numerator, "Change bootstrap threshold (online stake / 256 * bootstrap_fraction_numerator).\ntype:uint32");
toml.put ("receive_minimum", receive_minimum.to_string_dec (), "Minimum receive amount. Only affects node wallets. A large amount is recommended to avoid automatic work generation for tiny transactions.\ntype:string,amount,raw");
toml.put ("online_weight_minimum", online_weight_minimum.to_string_dec (), "When calculating online weight, the node is forced to assume at least this much voting weight is online, thus setting a floor for voting weight to confirm transactions at online_weight_minimum * \"quorum delta\".\ntype:string,amount,raw");
Expand Down Expand Up @@ -316,7 +320,13 @@ nano::error nano::node_config::deserialize_toml (nano::tomlconfig & toml)
toml.get ("tcp_io_timeout", tcp_io_timeout_l);
tcp_io_timeout = std::chrono::seconds (tcp_io_timeout_l);

toml.get<uint16_t> ("peering_port", peering_port);
if (toml.has_key ("peering_port"))
{
std::uint16_t peering_port_l{};
toml.get_required<uint16_t> ("peering_port", peering_port_l);
peering_port = peering_port_l;
}

toml.get<unsigned> ("bootstrap_fraction_numerator", bootstrap_fraction_numerator);
toml.get<unsigned> ("election_hint_weight_percent", election_hint_weight_percent);
toml.get<unsigned> ("password_fanout", password_fanout);
Expand Down
5 changes: 3 additions & 2 deletions nano/node/nodeconfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <nano/secure/common.hpp>

#include <chrono>
#include <optional>
#include <vector>

namespace nano
Expand All @@ -34,13 +35,13 @@ class node_config
{
public:
node_config (nano::network_params & network_params = nano::dev::network_params);
node_config (uint16_t, nano::logging const &, nano::network_params & network_params = nano::dev::network_params);
node_config (const std::optional<uint16_t> &, nano::logging const &, nano::network_params & network_params = nano::dev::network_params);
nano::error serialize_toml (nano::tomlconfig &) const;
nano::error deserialize_toml (nano::tomlconfig &);
bool upgrade_json (unsigned, nano::jsonconfig &);
nano::account random_representative () const;
nano::network_params & network_params;
uint16_t peering_port{ 0 };
std::optional<uint16_t> peering_port{};
nano::logging logging;
std::vector<std::pair<std::string, uint16_t>> work_peers;
std::vector<std::pair<std::string, uint16_t>> secondary_work_peers{ { "127.0.0.1", 8076 } }; /* Default of nano-pow-server */
Expand Down