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

Extend telemetry data with more node versioning details #2524

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
114 changes: 98 additions & 16 deletions nano/core_test/node_telemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,61 +20,77 @@ TEST (node_telemetry, consolidate_data)
data.account_count = 2;
data.block_count = 1;
data.cemented_count = 1;
data.vendor_version = 20;
data.protocol_version_number = 12;
data.protocol_version = 12;
data.peer_count = 2;
data.bandwidth_cap = 100;
data.unchecked_count = 3;
data.uptime = 6;
data.genesis_block = nano::block_hash (3);
data.major_version = 20;
data.minor_version = 1;
data.patch_version = 4;

nano::telemetry_data data1;
data1.account_count = 5;
data1.block_count = 7;
data1.cemented_count = 4;
data1.vendor_version = 10;
data1.protocol_version_number = 11;
data1.protocol_version = 11;
data1.peer_count = 5;
data1.bandwidth_cap = 0;
data1.unchecked_count = 1;
data1.uptime = 10;
data1.genesis_block = nano::block_hash (4);
data1.major_version = 10;
data1.minor_version = 2;
data1.patch_version = 3;
data1.maker = 2;

nano::telemetry_data data2;
data2.account_count = 3;
data2.block_count = 3;
data2.cemented_count = 2;
data2.vendor_version = 20;
data2.protocol_version_number = 11;
data2.protocol_version = 11;
data2.peer_count = 4;
data2.bandwidth_cap = 0;
data2.unchecked_count = 2;
data2.uptime = 3;
data2.genesis_block = nano::block_hash (4);
data2.major_version = 20;
data2.minor_version = 1;
data2.patch_version = 4;

std::vector<nano::telemetry_data> all_data{ data, data1, data2 };

auto consolidated_telemetry_data = nano::telemetry_data::consolidate (all_data);
ASSERT_EQ (consolidated_telemetry_data.account_count, 3);
ASSERT_EQ (consolidated_telemetry_data.block_count, 3);
ASSERT_EQ (consolidated_telemetry_data.cemented_count, 2);
ASSERT_EQ (consolidated_telemetry_data.vendor_version, 20);
ASSERT_EQ (consolidated_telemetry_data.protocol_version_number, 11);
ASSERT_EQ (consolidated_telemetry_data.protocol_version, 11);
ASSERT_EQ (consolidated_telemetry_data.peer_count, 3);
ASSERT_EQ (consolidated_telemetry_data.bandwidth_cap, 0);
ASSERT_EQ (consolidated_telemetry_data.unchecked_count, 2);
ASSERT_EQ (consolidated_telemetry_data.uptime, 6);
ASSERT_EQ (consolidated_telemetry_data.genesis_block, nano::block_hash (4));
ASSERT_EQ (consolidated_telemetry_data.major_version, 20);
ASSERT_FALSE (consolidated_telemetry_data.minor_version.is_initialized ());
ASSERT_FALSE (consolidated_telemetry_data.patch_version.is_initialized ());
ASSERT_FALSE (consolidated_telemetry_data.maker.is_initialized ());

// Modify the metrics which may be either the mode or averages to ensure all are tested.
all_data[2].bandwidth_cap = 53;
all_data[2].protocol_version_number = 13;
all_data[2].vendor_version = 13;
all_data[2].protocol_version = 13;
all_data[2].genesis_block = nano::block_hash (3);
all_data[2].major_version = 10;
all_data[2].minor_version = 2;
all_data[2].patch_version = 3;
all_data[2].maker = 2;

auto consolidated_telemetry_data1 = nano::telemetry_data::consolidate (all_data);
ASSERT_TRUE (consolidated_telemetry_data1.vendor_version == 10 || consolidated_telemetry_data1.vendor_version == 13 || consolidated_telemetry_data1.vendor_version == 20);
ASSERT_TRUE (consolidated_telemetry_data1.protocol_version_number == 11 || consolidated_telemetry_data1.protocol_version_number == 12 || consolidated_telemetry_data1.protocol_version_number == 13);
ASSERT_EQ (consolidated_telemetry_data1.major_version, 10);
ASSERT_EQ (*consolidated_telemetry_data1.minor_version, 2);
ASSERT_EQ (*consolidated_telemetry_data1.patch_version, 3);
ASSERT_EQ (*consolidated_telemetry_data1.maker, 2);
ASSERT_TRUE (consolidated_telemetry_data1.protocol_version == 11 || consolidated_telemetry_data1.protocol_version == 12 || consolidated_telemetry_data1.protocol_version == 13);
ASSERT_EQ (consolidated_telemetry_data1.bandwidth_cap, 51);
ASSERT_EQ (consolidated_telemetry_data1.genesis_block, nano::block_hash (3));

Expand All @@ -83,6 +99,66 @@ TEST (node_telemetry, consolidate_data)
ASSERT_EQ (consolidated_telemetry_data, consolidated_telemetry_data);
}

TEST (node_telemetry, consolidate_data_optional_data)
{
nano::telemetry_data data;
data.major_version = 20;
data.minor_version = 1;
data.patch_version = 4;
data.maker = 2;

nano::telemetry_data missing_minor;
missing_minor.major_version = 20;
missing_minor.patch_version = 4;

nano::telemetry_data missing_all_optional;

std::vector<nano::telemetry_data> all_data{ data, data, missing_minor, missing_all_optional };
auto consolidated_telemetry_data = nano::telemetry_data::consolidate (all_data);
ASSERT_EQ (consolidated_telemetry_data.major_version, 20);
ASSERT_EQ (*consolidated_telemetry_data.minor_version, 1);
ASSERT_EQ (*consolidated_telemetry_data.patch_version, 4);
ASSERT_EQ (*consolidated_telemetry_data.maker, 2);
}

TEST (node_telemetry, serialize_deserialize_json_optional)
{
nano::telemetry_data data;
data.minor_version = 1;
data.patch_version = 4;
data.maker = 2;

nano::jsonconfig config;
data.serialize_json (config);

uint8_t val;
ASSERT_FALSE (config.get ("minor_version", val).get_error ());
ASSERT_EQ (val, 1);
ASSERT_FALSE (config.get ("patch_version", val).get_error ());
ASSERT_EQ (val, 4);
ASSERT_FALSE (config.get ("maker", val).get_error ());
ASSERT_EQ (val, 2);

nano::telemetry_data data1;
data1.deserialize_json (config);
ASSERT_EQ (*data1.minor_version, 1);
ASSERT_EQ (*data1.patch_version, 4);
ASSERT_EQ (*data1.maker, 2);

nano::telemetry_data no_optional_data;
nano::jsonconfig config1;
no_optional_data.serialize_json (config1);
ASSERT_FALSE (config1.get_optional<uint8_t> ("minor_version").is_initialized ());
ASSERT_FALSE (config1.get_optional<uint8_t> ("patch_version").is_initialized ());
ASSERT_FALSE (config1.get_optional<uint8_t> ("maker").is_initialized ());

nano::telemetry_data no_optional_data1;
no_optional_data1.deserialize_json (config1);
ASSERT_FALSE (no_optional_data1.minor_version.is_initialized ());
ASSERT_FALSE (no_optional_data1.patch_version.is_initialized ());
ASSERT_FALSE (no_optional_data1.maker.is_initialized ());
}

TEST (node_telemetry, no_peers)
{
nano::system system (1);
Expand Down Expand Up @@ -223,10 +299,13 @@ TEST (node_telemetry, many_nodes)
ASSERT_LE (data.peer_count, 9);
ASSERT_EQ (data.account_count, 1);
ASSERT_TRUE (data.block_count == 2);
ASSERT_EQ (data.protocol_version_number, params.protocol.telemetry_protocol_version_min);
ASSERT_EQ (data.protocol_version, params.protocol.telemetry_protocol_version_min);
ASSERT_GE (data.bandwidth_cap, 100000);
ASSERT_LT (data.bandwidth_cap, 100000 + system.nodes.size ());
ASSERT_EQ (data.vendor_version, nano::get_major_node_version ());
ASSERT_EQ (data.major_version, nano::get_major_node_version ());
ASSERT_EQ (*data.minor_version, nano::get_minor_node_version ());
ASSERT_EQ (*data.patch_version, nano::get_patch_node_version ());
ASSERT_EQ (*data.maker, 0);
ASSERT_LT (data.uptime, 100);
ASSERT_EQ (data.genesis_block, genesis.hash ());
}
Expand Down Expand Up @@ -743,10 +822,13 @@ void compare_default_test_result_data (nano::telemetry_data & telemetry_data_a,
ASSERT_EQ (telemetry_data_a.cemented_count, 1);
ASSERT_EQ (telemetry_data_a.bandwidth_cap, node_server_a.config.bandwidth_limit);
ASSERT_EQ (telemetry_data_a.peer_count, 1);
ASSERT_EQ (telemetry_data_a.protocol_version_number, node_server_a.network_params.protocol.telemetry_protocol_version_min);
ASSERT_EQ (telemetry_data_a.protocol_version, node_server_a.network_params.protocol.telemetry_protocol_version_min);
ASSERT_EQ (telemetry_data_a.unchecked_count, 0);
ASSERT_EQ (telemetry_data_a.account_count, 1);
ASSERT_EQ (telemetry_data_a.vendor_version, nano::get_major_node_version ());
ASSERT_EQ (telemetry_data_a.major_version, nano::get_major_node_version ());
ASSERT_EQ (*telemetry_data_a.minor_version, nano::get_minor_node_version ());
ASSERT_EQ (*telemetry_data_a.patch_version, nano::get_patch_node_version ());
ASSERT_EQ (*telemetry_data_a.maker, 0);
ASSERT_LT (telemetry_data_a.uptime, 100);
ASSERT_EQ (telemetry_data_a.genesis_block, nano::genesis ().hash ());
}
Expand Down
2 changes: 2 additions & 0 deletions nano/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ endif ()
target_compile_definitions(nano_lib
PRIVATE
-DMAJOR_VERSION_STRING=${CPACK_PACKAGE_VERSION_MAJOR}
-DMINOR_VERSION_STRING=${CPACK_PACKAGE_VERSION_MINOR}
-DPATCH_VERSION_STRING=${CPACK_PACKAGE_VERSION_PATCH}
PUBLIC
-DACTIVE_NETWORK=${ACTIVE_NETWORK}
)
8 changes: 8 additions & 0 deletions nano/lib/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ uint8_t get_major_node_version ()
{
return boost::numeric_cast<uint8_t> (boost::lexical_cast<int> (NANO_MAJOR_VERSION_STRING));
}
uint8_t get_minor_node_version ()
{
return boost::numeric_cast<uint8_t> (boost::lexical_cast<int> (NANO_MINOR_VERSION_STRING));
}
uint8_t get_patch_node_version ()
{
return boost::numeric_cast<uint8_t> (boost::lexical_cast<int> (NANO_PATCH_VERSION_STRING));
}

void force_nano_test_network ()
{
Expand Down
4 changes: 4 additions & 0 deletions nano/lib/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ namespace filesystem
*/
const char * const NANO_VERSION_STRING = xstr (TAG_VERSION_STRING);
const char * const NANO_MAJOR_VERSION_STRING = xstr (MAJOR_VERSION_STRING);
const char * const NANO_MINOR_VERSION_STRING = xstr (MINOR_VERSION_STRING);
const char * const NANO_PATCH_VERSION_STRING = xstr (PATCH_VERSION_STRING);

const char * const BUILD_INFO = xstr (GIT_COMMIT_HASH BOOST_COMPILER) " \"BOOST " xstr (BOOST_VERSION) "\" BUILT " xstr (__DATE__);

Expand All @@ -38,6 +40,8 @@ const bool is_sanitizer_build = false;
namespace nano
{
uint8_t get_major_node_version ();
uint8_t get_minor_node_version ();
uint8_t get_patch_node_version ();

/**
* Network variants with different genesis blocks and network parameters
Expand Down
Loading