From 3e143acddc31d655de1212b818ef9155c2bbd339 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Wed, 7 Dec 2022 21:08:18 +0100 Subject: [PATCH] Specify account info request target type --- nano/core_test/bootstrap_server.cpp | 14 ++++++++------ nano/node/bootstrap/bootstrap_server.cpp | 22 +++++++++++++++------- nano/node/messages.hpp | 16 ++++++++-------- 3 files changed, 31 insertions(+), 21 deletions(-) diff --git a/nano/core_test/bootstrap_server.cpp b/nano/core_test/bootstrap_server.cpp index 6d0d8a431d..3753c8f008 100644 --- a/nano/core_test/bootstrap_server.cpp +++ b/nano/core_test/bootstrap_server.cpp @@ -171,7 +171,7 @@ TEST (bootstrap_server, serve_account_blocks) nano::asc_pull_req::blocks_payload request_payload; request_payload.start = first_account; request_payload.count = nano::bootstrap_server::max_blocks; - request_payload.start_type = nano::asc_pull_req::blocks_payload::type::account; + request_payload.start_type = nano::asc_pull_req::hash_type::account; request.payload = request_payload; request.update_header (); @@ -218,7 +218,7 @@ TEST (bootstrap_server, serve_hash) nano::asc_pull_req::blocks_payload request_payload; request_payload.start = blocks.front ()->hash (); request_payload.count = nano::bootstrap_server::max_blocks; - request_payload.start_type = nano::asc_pull_req::blocks_payload::type::block; + request_payload.start_type = nano::asc_pull_req::hash_type::block; request.payload = request_payload; request.update_header (); @@ -265,7 +265,7 @@ TEST (bootstrap_server, serve_hash_one) nano::asc_pull_req::blocks_payload request_payload; request_payload.start = blocks.front ()->hash (); request_payload.count = 1; - request_payload.start_type = nano::asc_pull_req::blocks_payload::type::block; + request_payload.start_type = nano::asc_pull_req::hash_type::block; request.payload = request_payload; request.update_header (); @@ -306,7 +306,7 @@ TEST (bootstrap_server, serve_end_of_chain) nano::asc_pull_req::blocks_payload request_payload; request_payload.start = blocks.back ()->hash (); request_payload.count = nano::bootstrap_server::max_blocks; - request_payload.start_type = nano::asc_pull_req::blocks_payload::type::block; + request_payload.start_type = nano::asc_pull_req::hash_type::block; request.payload = request_payload; request.update_header (); @@ -347,7 +347,7 @@ TEST (bootstrap_server, serve_missing) nano::asc_pull_req::blocks_payload request_payload; request_payload.start = nano::test::random_hash (); request_payload.count = nano::bootstrap_server::max_blocks; - request_payload.start_type = nano::asc_pull_req::blocks_payload::type::block; + request_payload.start_type = nano::asc_pull_req::hash_type::block; request.payload = request_payload; request.update_header (); @@ -392,7 +392,7 @@ TEST (bootstrap_server, serve_multiple) nano::asc_pull_req::blocks_payload request_payload; request_payload.start = account; request_payload.count = nano::bootstrap_server::max_blocks; - request_payload.start_type = nano::asc_pull_req::blocks_payload::type::account; + request_payload.start_type = nano::asc_pull_req::hash_type::account; request.payload = request_payload; request.update_header (); @@ -450,6 +450,7 @@ TEST (bootstrap_server, serve_account_info) nano::asc_pull_req::account_info_payload request_payload; request_payload.target = account; + request_payload.target_type = nano::asc_pull_req::hash_type::account; request.payload = request_payload; request.update_header (); @@ -497,6 +498,7 @@ TEST (bootstrap_server, serve_account_info_missing) nano::asc_pull_req::account_info_payload request_payload; request_payload.target = nano::test::random_account (); + request_payload.target_type = nano::asc_pull_req::hash_type::account; request.payload = request_payload; request.update_header (); diff --git a/nano/node/bootstrap/bootstrap_server.cpp b/nano/node/bootstrap/bootstrap_server.cpp index f421a7f654..068dee18c4 100644 --- a/nano/node/bootstrap/bootstrap_server.cpp +++ b/nano/node/bootstrap/bootstrap_server.cpp @@ -176,7 +176,7 @@ nano::asc_pull_ack nano::bootstrap_server::process (nano::transaction const & tr switch (request.start_type) { - case asc_pull_req::blocks_payload::type::block: + case asc_pull_req::hash_type::block: { if (store.block.exists (transaction, request.start.as_block_hash ())) { @@ -184,7 +184,7 @@ nano::asc_pull_ack nano::bootstrap_server::process (nano::transaction const & tr } } break; - case asc_pull_req::blocks_payload::type::account: + case asc_pull_req::hash_type::account: { auto info = store.account.get (transaction, request.start.as_account ()); if (info) @@ -261,13 +261,21 @@ nano::asc_pull_ack nano::bootstrap_server::process (const nano::transaction & tr response.id = id; response.type = nano::asc_pull_type::account_info; - auto target = request.target.as_account (); - // Try to lookup account assuming target is block hash - if (auto account_from_hash = ledger.account_safe (transaction, request.target.as_block_hash ()); !account_from_hash.is_zero ()) + nano::account target{ 0 }; + switch (request.target_type) { - target = account_from_hash; + case asc_pull_req::hash_type::account: + { + target = request.target.as_account (); + } + break; + case asc_pull_req::hash_type::block: + { + // Try to lookup account assuming target is block hash + target = ledger.account_safe (transaction, request.target.as_block_hash ()); + } + break; } - // Otherwise assume target is an actual account nano::asc_pull_ack::account_info_payload response_payload{}; response_payload.account = target; diff --git a/nano/node/messages.hpp b/nano/node/messages.hpp index 2aaae684d2..3395fc5b8e 100644 --- a/nano/node/messages.hpp +++ b/nano/node/messages.hpp @@ -414,15 +414,14 @@ class asc_pull_req final : public message bool verify_consistency () const; public: // Payload definitions - class blocks_payload + enum class hash_type : uint8_t { - public: - enum class type : uint8_t - { - block = 1, - account = 2, - }; + account = 0, + block = 1, + }; + class blocks_payload + { public: void serialize (nano::stream &) const; void deserialize (nano::stream &); @@ -430,7 +429,7 @@ class asc_pull_req final : public message public: nano::hash_or_account start{ 0 }; uint8_t count{ 0 }; - type start_type{ 0 }; + asc_pull_req::hash_type start_type{ 0 }; }; class account_info_payload @@ -441,6 +440,7 @@ class asc_pull_req final : public message public: nano::hash_or_account target{ 0 }; + asc_pull_req::hash_type target_type{ 0 }; }; public: // Payload