diff --git a/nano/node/messages.cpp b/nano/node/messages.cpp index 042c509fae..5ac44fca38 100644 --- a/nano/node/messages.cpp +++ b/nano/node/messages.cpp @@ -1036,14 +1036,13 @@ bool nano::telemetry_ack::deserialize (nano::stream & stream_a) { if (!is_empty_payload ()) { - data.deserialize (stream_a, nano::narrow_cast (header.extensions.to_ulong ())); + data.deserialize (stream_a, size ()); } } catch (std::runtime_error const &) { - error = true; + // Ignore deserialization errors for backwards compatibility } - return error; } @@ -1083,7 +1082,10 @@ void nano::telemetry_ack::operator() (nano::object_stream & obs) const void nano::telemetry_data::deserialize (nano::stream & stream, uint16_t payload_length) { + version = version_t::unknown; + read (stream, signature); + read (stream, node_id); read (stream, block_count); boost::endian::big_to_native_inplace (block_count); @@ -1118,6 +1120,9 @@ void nano::telemetry_data::deserialize (nano::stream & stream, uint16_t payload_ read (stream, active_difficulty); boost::endian::big_to_native_inplace (active_difficulty); + version = version_t::v1; + + // Added in V27, will throw if not present uint8_t database_backend_l; read (stream, database_backend_l); database_backend = static_cast (database_backend_l); @@ -1126,6 +1131,8 @@ void nano::telemetry_data::deserialize (nano::stream & stream, uint16_t payload_ read (stream, database_version_minor); read (stream, database_version_patch); + version = version_t::v2; + if (payload_length > size) { read (stream, unknown_data, payload_length - size); @@ -1152,10 +1159,17 @@ void nano::telemetry_data::serialize_without_signature (nano::stream & stream) c write (stream, static_cast> (maker)); write (stream, boost::endian::native_to_big (std::chrono::duration_cast (timestamp.time_since_epoch ()).count ())); write (stream, boost::endian::native_to_big (active_difficulty)); + + if (version == version_t::v1) + { + return; + } + write (stream, static_cast> (database_backend)); write (stream, database_version_major); write (stream, database_version_minor); write (stream, database_version_patch); + write (stream, unknown_data); } diff --git a/nano/node/messages.hpp b/nano/node/messages.hpp index cf49dbeb47..bc74997339 100644 --- a/nano/node/messages.hpp +++ b/nano/node/messages.hpp @@ -328,6 +328,14 @@ telemetry_backend to_telemetry_backend (std::string); class telemetry_data { +public: + enum class version_t + { + unknown = 0, + v1, // Pre V27 + v2, // V27+ + }; + public: // Payload nano::signature signature{ 0 }; nano::account node_id{}; @@ -356,6 +364,9 @@ class telemetry_data // TODO: Is supporting re-serialization necessary? std::vector unknown_data; +private: + version_t version{ version_t::v2 }; + public: void serialize (nano::stream &) const; void deserialize (nano::stream &, uint16_t payload_length);