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

Removing static initialization of nano::network_params #3413

Merged
merged 17 commits into from
Aug 6, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
4dede6d
Removing unused variable.
clemahieu Aug 1, 2021
e2cd9c7
Removing unnecessary is_dev_network checks and removing unused refere…
clemahieu Aug 1, 2021
02d8673
Removing unused usages of nano::network_params
clemahieu Aug 1, 2021
49d6615
Removing unnecessary checks for is_dev_network in confirmation height…
clemahieu Aug 3, 2021
2068e04
Rewrite reset_confirmation_heights to use a reference to ledger_const…
clemahieu Aug 3, 2021
4a737c4
Converting node_id_handshake from unnecessarily using channel::send_b…
clemahieu Aug 3, 2021
fe97b2e
Removing the version_min_m member from nano::message_header as unnece…
clemahieu Aug 3, 2021
7b7a105
Passing nano::protocol_constants in to message_parser rather than ref…
clemahieu Aug 3, 2021
abdfe15
Sending message via nano::channel::send rather than directly via send…
clemahieu Aug 3, 2021
240b1f8
Moving message header version assignment to nano::channel::send rathe…
clemahieu Aug 3, 2021
5ece01a
Removing unused variables.
clemahieu Aug 3, 2021
0f2c738
Removing unused references to nano::network_params and replacing a st…
clemahieu Aug 3, 2021
624674a
Replacing static network_params with a default inactive node.
clemahieu Aug 3, 2021
0d4f505
Threading is_state_epoch through block callbacks and removing static …
clemahieu Aug 4, 2021
20828e6
Removing default constructor for nano::network_params that uses stati…
clemahieu Aug 4, 2021
7230b1f
Merging protocol_constants in to network_constants.
clemahieu Aug 5, 2021
8460306
Initializing message_header version and network fields from nano::net…
clemahieu Aug 5, 2021
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
15 changes: 9 additions & 6 deletions nano/core_test/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ TEST (message, publish_serialization)
{
nano::publish publish (std::make_shared<nano::send_block> (0, 1, 2, nano::keypair ().prv, 4, 5));
publish.header.network = nano::networks::nano_dev_network;
publish.header.version_max = 6;
publish.header.version_using = 5;
publish.header.version_min = 4;
ASSERT_EQ (nano::block_type::send, publish.header.block_type ());
std::vector<uint8_t> bytes;
{
Expand All @@ -55,19 +58,19 @@ TEST (message, publish_serialization)
ASSERT_EQ (8, bytes.size ());
ASSERT_EQ (0x52, bytes[0]);
ASSERT_EQ (0x41, bytes[1]);
ASSERT_EQ (nano::dev::network_params.protocol.protocol_version, bytes[2]);
ASSERT_EQ (nano::dev::network_params.protocol.protocol_version, bytes[3]);
ASSERT_EQ (nano::dev::network_params.protocol.protocol_version_min (), bytes[4]);
ASSERT_EQ (6, bytes[2]);
ASSERT_EQ (5, bytes[3]);
ASSERT_EQ (4, bytes[4]);
ASSERT_EQ (static_cast<uint8_t> (nano::message_type::publish), bytes[5]);
ASSERT_EQ (0x00, bytes[6]); // extensions
ASSERT_EQ (static_cast<uint8_t> (nano::block_type::send), bytes[7]);
nano::bufferstream stream (bytes.data (), bytes.size ());
auto error (false);
nano::message_header header (error, stream);
ASSERT_FALSE (error);
ASSERT_EQ (nano::dev::network_params.protocol.protocol_version_min (), header.version_min);
ASSERT_EQ (nano::dev::network_params.protocol.protocol_version, header.version_using);
ASSERT_EQ (nano::dev::network_params.protocol.protocol_version, header.version_max);
ASSERT_EQ (4, header.version_min);
ASSERT_EQ (5, header.version_using);
ASSERT_EQ (6, header.version_max);
ASSERT_EQ (nano::message_type::publish, header.type);
}

Expand Down
7 changes: 3 additions & 4 deletions nano/core_test/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -839,12 +839,11 @@ TEST (tcp_listener, tcp_listener_timeout_node_id_handshake)
auto socket (std::make_shared<nano::socket> (*node0));
auto cookie (node0->network.syn_cookies.assign (nano::transport::map_tcp_to_endpoint (node0->bootstrap.endpoint ())));
nano::node_id_handshake node_id_handshake (cookie, boost::none);
auto input (node_id_handshake.to_shared_const_buffer ());
socket->async_connect (node0->bootstrap.endpoint (), [&input, socket] (boost::system::error_code const & ec) {
auto channel = std::make_shared<nano::transport::channel_tcp> (*node0, socket);
socket->async_connect (node0->bootstrap.endpoint (), [&node_id_handshake, channel] (boost::system::error_code const & ec) {
ASSERT_FALSE (ec);
socket->async_write (input, [&input] (boost::system::error_code const & ec, size_t size_a) {
channel->send (node_id_handshake, [] (boost::system::error_code const & ec, size_t size_a) {
ASSERT_FALSE (ec);
ASSERT_EQ (input.size (), size_a);
});
});
ASSERT_TIMELY (5s, node0->stats.count (nano::stat::type::message, nano::stat::detail::node_id_handshake) != 0);
Expand Down
3 changes: 3 additions & 0 deletions nano/node/bootstrap/bootstrap_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,9 @@ class request_response_visitor : public nano::message_visitor
debug_assert (!nano::validate_message (response->first, *message_a.query, response->second));
auto cookie (connection->node->network.syn_cookies.assign (nano::transport::map_tcp_to_endpoint (connection->remote_endpoint)));
nano::node_id_handshake response_message (cookie, response);
response_message.header.version_max = connection->node->network_params.protocol.protocol_version;
response_message.header.version_using = connection->node->network_params.protocol.protocol_version;
response_message.header.version_min = connection->node->network_params.protocol.protocol_version_min ();
auto shared_const_buffer = response_message.to_shared_const_buffer ();
connection->socket->async_write (shared_const_buffer, [connection = std::weak_ptr<nano::bootstrap_server> (connection)] (boost::system::error_code const & ec, size_t size_a) {
if (auto connection_l = connection.lock ())
Expand Down
12 changes: 0 additions & 12 deletions nano/node/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,6 @@ std::chrono::seconds constexpr nano::telemetry_cache_cutoffs::dev;
std::chrono::seconds constexpr nano::telemetry_cache_cutoffs::beta;
std::chrono::seconds constexpr nano::telemetry_cache_cutoffs::live;

namespace
{
nano::protocol_constants const & get_protocol_constants ()
{
static nano::network_params params;
return params.protocol;
}
}

uint64_t nano::ip_address_hash_raw (boost::asio::ip::address const & ip_a, uint16_t port)
{
static nano::random_constants constants;
Expand All @@ -51,9 +42,6 @@ uint64_t nano::ip_address_hash_raw (boost::asio::ip::address const & ip_a, uint1

nano::message_header::message_header (nano::message_type type_a) :
network (nano::network_constants::active_network),
version_max (get_protocol_constants ().protocol_version),
version_using (get_protocol_constants ().protocol_version),
version_min (get_protocol_constants ().protocol_version_min ()),
type (type_a)
{
}
Expand Down
2 changes: 1 addition & 1 deletion nano/node/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ void nano::network::send_node_id_handshake (std::shared_ptr<nano::transport::cha
channel_a->send (message);
}

void nano::network::flood_message (nano::message const & message_a, nano::buffer_drop_policy const drop_policy_a, float const scale_a)
void nano::network::flood_message (nano::message & message_a, nano::buffer_drop_policy const drop_policy_a, float const scale_a)
{
for (auto & i : list (fanout (scale_a)))
{
Expand Down
2 changes: 1 addition & 1 deletion nano/node/network.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class network final
nano::networks id;
void start ();
void stop ();
void flood_message (nano::message const &, nano::buffer_drop_policy const = nano::buffer_drop_policy::limiter, float const = 1.0f);
void flood_message (nano::message &, nano::buffer_drop_policy const = nano::buffer_drop_policy::limiter, float const = 1.0f);
void flood_keepalive (float const scale_a = 1.0f)
{
nano::keepalive message;
Expand Down
5 changes: 4 additions & 1 deletion nano/node/transport/transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,11 @@ nano::transport::channel::channel (nano::node & node_a) :
set_network_version (node_a.network_params.protocol.protocol_version);
}

void nano::transport::channel::send (nano::message const & message_a, std::function<void (boost::system::error_code const &, size_t)> const & callback_a, nano::buffer_drop_policy drop_policy_a)
void nano::transport::channel::send (nano::message & message_a, std::function<void (boost::system::error_code const &, size_t)> const & callback_a, nano::buffer_drop_policy drop_policy_a)
{
message_a.header.version_max = node.network_params.protocol.protocol_version;
message_a.header.version_using = node.network_params.protocol.protocol_version;
message_a.header.version_min = node.network_params.protocol.protocol_version_min ();
callback_visitor visitor;
message_a.visit (visitor);
auto buffer (message_a.to_shared_const_buffer ());
Expand Down
2 changes: 1 addition & 1 deletion nano/node/transport/transport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace transport
virtual ~channel () = default;
virtual size_t hash_code () const = 0;
virtual bool operator== (nano::transport::channel const &) const = 0;
void send (nano::message const & message_a, std::function<void (boost::system::error_code const &, size_t)> const & callback_a = nullptr, nano::buffer_drop_policy policy_a = nano::buffer_drop_policy::limiter);
void send (nano::message & message_a, std::function<void (boost::system::error_code const &, size_t)> const & callback_a = nullptr, nano::buffer_drop_policy policy_a = nano::buffer_drop_policy::limiter);
virtual void send_buffer (nano::shared_const_buffer const &, std::function<void (boost::system::error_code const &, size_t)> const & = nullptr, nano::buffer_drop_policy = nano::buffer_drop_policy::limiter) = 0;
virtual std::string to_string () const = 0;
virtual nano::endpoint get_endpoint () const = 0;
Expand Down