From fe97b2e898e1df84ce1a0742054ad4ec35296ae3 Mon Sep 17 00:00:00 2001 From: clemahieu Date: Tue, 3 Aug 2021 13:45:06 +0100 Subject: [PATCH] Removing the version_min_m member from nano::message_header as unnecessary. Serializing this version number to/from the message_header the same as the other two version_max and version_using. --- nano/core_test/message.cpp | 2 +- nano/node/common.cpp | 11 +++-------- nano/node/common.hpp | 7 ++----- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/nano/core_test/message.cpp b/nano/core_test/message.cpp index 8ef0e1773..579df6ce8 100644 --- a/nano/core_test/message.cpp +++ b/nano/core_test/message.cpp @@ -65,7 +65,7 @@ TEST (message, publish_serialization) 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_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 (nano::message_type::publish, header.type); diff --git a/nano/node/common.cpp b/nano/node/common.cpp index f845bf62e..1b7827a78 100644 --- a/nano/node/common.cpp +++ b/nano/node/common.cpp @@ -53,6 +53,7 @@ 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) { } @@ -71,7 +72,7 @@ void nano::message_header::serialize (nano::stream & stream_a) const nano::write (stream_a, boost::endian::native_to_big (static_cast (network))); nano::write (stream_a, version_max); nano::write (stream_a, version_using); - nano::write (stream_a, get_protocol_constants ().protocol_version_min ()); + nano::write (stream_a, version_min); nano::write (stream_a, type); nano::write (stream_a, static_cast (extensions.to_ullong ())); } @@ -87,7 +88,7 @@ bool nano::message_header::deserialize (nano::stream & stream_a) network = static_cast (boost::endian::big_to_native (network_bytes)); nano::read (stream_a, version_max); nano::read (stream_a, version_using); - nano::read (stream_a, version_min_m); + nano::read (stream_a, version_min); nano::read (stream_a, type); uint16_t extensions_l; nano::read (stream_a, extensions_l); @@ -101,12 +102,6 @@ bool nano::message_header::deserialize (nano::stream & stream_a) return error; } -uint8_t nano::message_header::version_min () const -{ - debug_assert (version_min_m != std::numeric_limits::max ()); - return version_min_m; -} - nano::message::message (nano::message_type type_a) : header (type_a) { diff --git a/nano/node/common.hpp b/nano/node/common.hpp index 2d1517e72..5f4e51c26 100644 --- a/nano/node/common.hpp +++ b/nano/node/common.hpp @@ -198,14 +198,12 @@ public: nano::networks network; uint8_t version_max; uint8_t version_using; - -private: - uint8_t version_min_m{ std::numeric_limits::max () }; + uint8_t version_min; public: nano::message_type type; std::bitset<16> extensions; - static size_t constexpr size = sizeof (nano::networks) + sizeof (version_max) + sizeof (version_using) + sizeof (version_min_m) + sizeof (type) + sizeof (/* extensions */ uint16_t); + static size_t constexpr size = sizeof (nano::networks) + sizeof (version_max) + sizeof (version_using) + sizeof (version_min) + sizeof (type) + sizeof (/* extensions */ uint16_t); void flag_set (uint8_t); static uint8_t constexpr bulk_pull_count_present_flag = 0; @@ -216,7 +214,6 @@ public: static uint8_t constexpr node_id_handshake_response_flag = 1; bool node_id_handshake_is_query () const; bool node_id_handshake_is_response () const; - uint8_t version_min () const; /** Size of the payload in bytes. For some messages, the payload size is based on header flags. */ size_t payload_length_bytes () const;