Skip to content

Commit

Permalink
Backwards compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Aug 6, 2024
1 parent 009a4ba commit 5791b13
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
20 changes: 17 additions & 3 deletions nano/node/messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1036,14 +1036,13 @@ bool nano::telemetry_ack::deserialize (nano::stream & stream_a)
{
if (!is_empty_payload ())
{
data.deserialize (stream_a, nano::narrow_cast<uint16_t> (header.extensions.to_ulong ()));
data.deserialize (stream_a, size ());
}
}
catch (std::runtime_error const &)
{
error = true;
// Ignore deserialization errors for backwards compatibility
}

return error;
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<nano::telemetry_backend> (database_backend_l);
Expand All @@ -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);
Expand All @@ -1152,10 +1159,17 @@ void nano::telemetry_data::serialize_without_signature (nano::stream & stream) c
write (stream, static_cast<std::underlying_type_t<nano::telemetry_maker>> (maker));
write (stream, boost::endian::native_to_big (std::chrono::duration_cast<std::chrono::milliseconds> (timestamp.time_since_epoch ()).count ()));
write (stream, boost::endian::native_to_big (active_difficulty));

if (version == version_t::v1)
{
return;
}

write (stream, static_cast<std::underlying_type_t<nano::telemetry_backend>> (database_backend));
write (stream, database_version_major);
write (stream, database_version_minor);
write (stream, database_version_patch);

write (stream, unknown_data);
}

Expand Down
11 changes: 11 additions & 0 deletions nano/node/messages.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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{};
Expand Down Expand Up @@ -356,6 +364,9 @@ class telemetry_data
// TODO: Is supporting re-serialization necessary?
std::vector<uint8_t> unknown_data;

private:
version_t version{ version_t::v2 };

public:
void serialize (nano::stream &) const;
void deserialize (nano::stream &, uint16_t payload_length);
Expand Down

0 comments on commit 5791b13

Please sign in to comment.