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

Telemetry database backend #4694

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
72 changes: 69 additions & 3 deletions nano/core_test/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ TEST (message, confirm_req_hash_batch_serialization_v2)
/**
* Test that a confirm_ack can encode an empty hash set
*/
TEST (confirm_ack, empty_vote_hashes)
TEST (message, confirm_ack_empty_vote_hashes)
{
nano::keypair key;
auto vote = std::make_shared<nano::vote> (key.pub, key.prv, 0, 0, std::vector<nano::block_hash>{} /* empty */);
Expand Down Expand Up @@ -833,7 +833,7 @@ TEST (message, node_id_handshake_response_v2_serialization)
ASSERT_TRUE (nano::at_end (stream));
}

TEST (handshake, signature)
TEST (message, handshake_signature)
{
nano::keypair node_id{};
nano::keypair node_id_2{};
Expand All @@ -853,7 +853,7 @@ TEST (handshake, signature)
ASSERT_FALSE (response.validate (cookie));
}

TEST (handshake, signature_v2)
TEST (message, handshake_signature_v2)
{
nano::keypair node_id{};
nano::keypair node_id_2{};
Expand Down Expand Up @@ -895,3 +895,69 @@ TEST (handshake, signature_v2)
ASSERT_FALSE (message.validate (cookie));
}
}

TEST (message, telemetry_data_serialization)
{
nano::telemetry_data original;
original.node_id = nano::account{ 11111 };
original.account_count = 22222;
original.block_count = 33333;
original.cemented_count = 44444;
original.bandwidth_cap = 55555;
original.account_count = 66666;
original.bandwidth_cap = 77777;
original.uptime = 88888;
original.peer_count = 99999;
original.protocol_version = 1;
original.genesis_block = nano::block_hash{ 22222 };
original.major_version = 4;
original.minor_version = 3;
original.patch_version = 2;
original.pre_release_version = 1;
original.maker = nano::telemetry_maker::nf_pruned_node;
original.timestamp = std::chrono::system_clock::time_point{ 123456789s };
original.active_difficulty = 42;
original.database_backend = nano::telemetry_backend::rocksdb;
original.database_version_major = 3;
original.database_version_minor = 2;
original.database_version_patch = 1;

// Serialize
std::vector<uint8_t> bytes;
{
nano::vectorstream stream{ bytes };
original.serialize (stream);
}
nano::bufferstream stream{ bytes.data (), bytes.size () };

nano::telemetry_data telemetry;
ASSERT_NO_THROW (telemetry.deserialize (stream, bytes.size ()));

// Compare
ASSERT_EQ (original.node_id, telemetry.node_id);
ASSERT_EQ (original.account_count, telemetry.account_count);
ASSERT_EQ (original.block_count, telemetry.block_count);
ASSERT_EQ (original.cemented_count, telemetry.cemented_count);
ASSERT_EQ (original.bandwidth_cap, telemetry.bandwidth_cap);
ASSERT_EQ (original.account_count, telemetry.account_count);
ASSERT_EQ (original.bandwidth_cap, telemetry.bandwidth_cap);
ASSERT_EQ (original.uptime, telemetry.uptime);
ASSERT_EQ (original.peer_count, telemetry.peer_count);
ASSERT_EQ (original.protocol_version, telemetry.protocol_version);
ASSERT_EQ (original.genesis_block, telemetry.genesis_block);
ASSERT_EQ (original.major_version, telemetry.major_version);
ASSERT_EQ (original.minor_version, telemetry.minor_version);
ASSERT_EQ (original.patch_version, telemetry.patch_version);
ASSERT_EQ (original.pre_release_version, telemetry.pre_release_version);
ASSERT_EQ (original.maker, telemetry.maker);
ASSERT_EQ (original.timestamp, telemetry.timestamp);
ASSERT_EQ (original.active_difficulty, telemetry.active_difficulty);
ASSERT_EQ (original.database_backend, telemetry.database_backend);
ASSERT_EQ (original.database_version_major, telemetry.database_version_major);
ASSERT_EQ (original.database_version_minor, telemetry.database_version_minor);
ASSERT_EQ (original.database_version_patch, telemetry.database_version_patch);
ASSERT_EQ (original, telemetry);

ASSERT_EQ (nano::telemetry_data::size, bytes.size ());
ASSERT_TRUE (nano::at_end (stream));
}
7 changes: 3 additions & 4 deletions nano/core_test/telemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ TEST (telemetry, signatures)
data.minor_version = 1;
data.patch_version = 5;
data.pre_release_version = 2;
data.maker = 1;
data.maker = nano::telemetry_maker::nf_pruned_node;
data.timestamp = std::chrono::system_clock::time_point (100ms);
data.sign (node_id);
ASSERT_FALSE (data.validate_signature ());
auto signature = data.signature;
// Check that the signature is different if changing a piece of data
data.maker = 2;
data.maker = nano::telemetry_maker::nf_node;
data.sign (node_id);
ASSERT_NE (data.signature, signature);
}
Expand All @@ -39,7 +39,6 @@ TEST (telemetry, unknown_data)
data.minor_version = 1;
data.patch_version = 5;
data.pre_release_version = 2;
data.maker = 1;
data.timestamp = std::chrono::system_clock::time_point (100ms);
data.unknown_data.push_back (1);
data.sign (node_id);
Expand Down Expand Up @@ -209,7 +208,7 @@ TEST (telemetry, max_possible_size)
auto node_server = system.add_node (node_flags);

nano::telemetry_data data;
data.unknown_data.resize (nano::message_header::telemetry_size_mask.to_ulong () - nano::telemetry_data::latest_size);
data.unknown_data.resize (nano::message_header::telemetry_size_mask.to_ulong () - nano::telemetry_data::size);

nano::telemetry_ack message{ nano::dev::network_params.network, data };
nano::test::wait_peer_connections (system);
Expand Down
Loading
Loading