From 7635a582f3de157a369a0e5de2329dcb675591ae Mon Sep 17 00:00:00 2001 From: Brandon Date: Thu, 22 Jun 2023 18:14:41 +0100 Subject: [PATCH 01/10] added to_string() for asc_pull_req --- nano/node/messages.cpp | 36 +++++++++++++++++++++++++++++++++++- nano/node/messages.hpp | 2 ++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/nano/node/messages.cpp b/nano/node/messages.cpp index d98c02f6a2..82cb230eb2 100644 --- a/nano/node/messages.cpp +++ b/nano/node/messages.cpp @@ -1656,6 +1656,31 @@ bool nano::asc_pull_req::verify_consistency () const return true; // Just for convenience of calling from asserts } +std::string nano::asc_pull_req::to_string () const +{ + std::string s = header.to_string() + "\n"; + + if (payload.index() == 0) + { + s += "empty payload"; + } + + if (payload.index() == 1) + { + s += "acc:" + payload.start.to_string(); + s += " max block count:" + nano::to_string_hex(static_cast (payload.count)); + s += " hash type:" + nano::to_string_hex(static_cast (payload.start_type)); + } + + if (payload.index() == 2) + { + s += "target:" + payload.target.to_string (); + s += " hash type:" + nano::to_string_hex(static_cast (payload.target_type)); + } + + return s; + +} /* * asc_pull_req::blocks_payload */ @@ -1809,6 +1834,13 @@ bool nano::asc_pull_ack::verify_consistency () const return true; // Just for convenience of calling from asserts } +std::string nano::asc_pull_ack::to_string () const +{ + std::string s = header.to_string(); + + if +} + /* * asc_pull_ack::blocks_payload */ @@ -1827,7 +1859,9 @@ void nano::asc_pull_ack::blocks_payload::serialize (nano::stream & stream) const void nano::asc_pull_ack::blocks_payload::deserialize (nano::stream & stream) { - auto current = nano::deserialize_block (stream); + auto current = nano::deserialize_b0 + + lock (stream); while (current && blocks.size () < max_blocks) { blocks.push_back (current); diff --git a/nano/node/messages.hpp b/nano/node/messages.hpp index 976ba2b55f..2671319566 100644 --- a/nano/node/messages.hpp +++ b/nano/node/messages.hpp @@ -429,6 +429,7 @@ class asc_pull_req final : public message void serialize_payload (nano::stream &) const; void deserialize_payload (nano::stream &); + std::string to_string () const; private: // Debug /** @@ -504,6 +505,7 @@ class asc_pull_ack final : public message void serialize_payload (nano::stream &) const; void deserialize_payload (nano::stream &); + std::string to_string () const; private: // Debug /** From 05bd07be3e6469f62bfa7c46de65bfa682467973 Mon Sep 17 00:00:00 2001 From: Brandon Date: Thu, 22 Jun 2023 22:10:31 +0100 Subject: [PATCH 02/10] added to_string() for asc_pull_req --- nano/node/messages.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/nano/node/messages.cpp b/nano/node/messages.cpp index 82cb230eb2..072c0c6a29 100644 --- a/nano/node/messages.cpp +++ b/nano/node/messages.cpp @@ -1667,15 +1667,19 @@ std::string nano::asc_pull_req::to_string () const if (payload.index() == 1) { - s += "acc:" + payload.start.to_string(); - s += " max block count:" + nano::to_string_hex(static_cast (payload.count)); - s += " hash type:" + nano::to_string_hex(static_cast (payload.start_type)); + std::visit([&s](auto && arg) { + s += "acc:" + arg.start.to_string(); + s += " max block count:" + nano_to_string_hex(static_cast (arg.count)); + s += " hash type:" + nano::to_string_hex(static_cast (arg.start_type)); + }, payload); } if (payload.index() == 2) { - s += "target:" + payload.target.to_string (); - s += " hash type:" + nano::to_string_hex(static_cast (payload.target_type)); + std::visit([&s](auto && arg) { + s += "target" + arg.target.to_string (); + s += " hash type:" + nano::to_string_hex(static_cast (payload.target_type)); + }, payload) } return s; From 3ef0041739ad6a3685b79a5c87e7fae36670553e Mon Sep 17 00:00:00 2001 From: brandon-bb <41524435+brandon-bb@users.noreply.github.com> Date: Thu, 22 Jun 2023 22:24:10 +0100 Subject: [PATCH 03/10] Update messages.cpp removed duplicate lines --- nano/node/messages.cpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/nano/node/messages.cpp b/nano/node/messages.cpp index c56fbebf03..c23df5fcf5 100644 --- a/nano/node/messages.cpp +++ b/nano/node/messages.cpp @@ -1673,11 +1673,6 @@ std::string nano::asc_pull_req::to_string () const s += " max block count:" + nano_to_string_hex(static_cast (arg.count)); s += " hash type:" + nano::to_string_hex(static_cast (arg.start_type)); }, payload); - - s += "acc:" + payload.start.to_string(); - s += " max block count:" + nano::to_string_hex(static_cast (payload.count)); - s += " hash type:" + nano::to_string_hex(static_cast (payload.start_type)); - } if (payload.index() == 2) @@ -1687,10 +1682,6 @@ std::string nano::asc_pull_req::to_string () const s += "target" + arg.target.to_string (); s += " hash type:" + nano::to_string_hex(static_cast (payload.target_type)); }, payload) - - s += "target:" + payload.target.to_string (); - s += " hash type:" + nano::to_string_hex(static_cast (payload.target_type)); - } return s; From 08e9a203cd10a4b696cc46e8373f029dd54fe729 Mon Sep 17 00:00:00 2001 From: Brandon Date: Fri, 23 Jun 2023 21:26:13 +0100 Subject: [PATCH 04/10] added to_string() for asc_pull_ack --- nano/node/messages.cpp | 55 +++++++++++++++++++++++++++++++++--------- nano/node/messages.hpp | 1 + 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/nano/node/messages.cpp b/nano/node/messages.cpp index 072c0c6a29..a0dd1c67a4 100644 --- a/nano/node/messages.cpp +++ b/nano/node/messages.cpp @@ -1658,27 +1658,27 @@ bool nano::asc_pull_req::verify_consistency () const std::string nano::asc_pull_req::to_string () const { - std::string s = header.to_string() + "\n"; + std::string s = header.to_string () + "\n"; - if (payload.index() == 0) + if (payload.index () == 0) { s += "empty payload"; } - if (payload.index() == 1) + if (payload.index () == 1) { - std::visit([&s](auto && arg) { - s += "acc:" + arg.start.to_string(); - s += " max block count:" + nano_to_string_hex(static_cast (arg.count)); - s += " hash type:" + nano::to_string_hex(static_cast (arg.start_type)); + std::visit([&s] (auto && arg) { + s += "acc:" + arg.start.to_string (); + s += " max block count:" + nano_to_string_hex (static_cast (arg.count)); + s += " hash type:" + nano::to_string_hex (static_cast (arg.start_type)); }, payload); } - if (payload.index() == 2) + if (payload.index () == 2) { - std::visit([&s](auto && arg) { + std::visit([&s] (auto && arg) { s += "target" + arg.target.to_string (); - s += " hash type:" + nano::to_string_hex(static_cast (payload.target_type)); + s += " hash type:" + nano::to_string_hex (static_cast (arg.target_type)); }, payload) } @@ -1840,9 +1840,40 @@ bool nano::asc_pull_ack::verify_consistency () const std::string nano::asc_pull_ack::to_string () const { - std::string s = header.to_string(); + std::string s = header.to_string () + "\n"; + + if (payload.index() == 0) + { + s += "empty payload"; + } + + if (payload.index() == 1) + { + std::visit([&s] (auto && arg) { + std::vector>::iterator block; + + for (block = arg.blocks.begin (); block < arg.blocks.end (); ++block) + { + s += (*block)->to_json (); + } + + }, payload); + } + + if (payload.index() == 2) + { + std::visit([&s] (auto && arg) { + s += "account public key:" + arg.account.to_account (); + s += " account open" + arg.account_open.to_string () + s += " account head" + arg.account_head.to_string (); + s += " block count" + to_string_hex (arg.block_count); + s += " confirmation frontier:" + arg.account_conf_frontier.to_string (); + s += " confirmation height" + to_string_hex (arg.account_conf_height); + }, payload) + } + + return s; - if } /* diff --git a/nano/node/messages.hpp b/nano/node/messages.hpp index 2671319566..5489d107b5 100644 --- a/nano/node/messages.hpp +++ b/nano/node/messages.hpp @@ -18,6 +18,7 @@ #include #include #include +#include namespace nano { From a6fc5b43ea7bb4c22debef8ea9afd986eb3f3e46 Mon Sep 17 00:00:00 2001 From: Brandon Date: Mon, 26 Jun 2023 21:15:12 +0100 Subject: [PATCH 05/10] refactored to_string() in both asc_pull_req and asc_pull_ack. Need to add failsafe for if a type not in payload is initialised --- nano/node/messages.cpp | 91 ++++++++++++++++++++++-------------------- 1 file changed, 47 insertions(+), 44 deletions(-) diff --git a/nano/node/messages.cpp b/nano/node/messages.cpp index fae0ee8c42..7cf6e81d84 100644 --- a/nano/node/messages.cpp +++ b/nano/node/messages.cpp @@ -1660,27 +1660,29 @@ std::string nano::asc_pull_req::to_string () const { std::string s = header.to_string () + "\n"; - if (payload.index () == 0) - { - s += "empty payload"; - } - - if (payload.index () == 1) - { - std::visit([&s](auto && arg) { - s += "acc:" + arg.start.to_string(); - s += " max block count:" + nano_to_string_hex(static_cast (arg.count)); - s += " hash type:" + nano::to_string_hex(static_cast (arg.start_type)); - }, payload); - } - - if (payload.index () == 2) - { - std::visit([&s](auto && arg) { - s += "target" + arg.target.to_string (); - s += " hash type:" + nano::to_string_hex (static_cast (arg.target_type)); - }, payload) - } + std::visit ([&s](auto && arg) + { + using T = std::decay_t; + + if constexpr (std::is_same_v) + { + s += "missing payload"; + } + + else if constexpr (std::is_same_v) + { + s += "acc:" + arg.start.to_string(); + s += " max block count:" + to_string_hex(static_cast (arg.count)); + s += " hash type:" + to_string_hex(static_cast (arg.start_type)); + } + + else if constexpr (std::is_same_v) + { + s += "target:" + arg.target.to_string (); + s += " hash type:" + to_string_hex (static_cast (arg.target_type)); + } + + }, payload); return s; @@ -1842,38 +1844,39 @@ std::string nano::asc_pull_ack::to_string () const { std::string s = header.to_string () + "\n"; - if (payload.index() == 0) - { - s += "empty payload"; - } + std::visit ( [&s](auto && arg) + { + using T = std::decay_t; - if (payload.index() == 1) - { - std::visit([&s] (auto && arg) { - std::vector>::iterator block; + if constexpr (std::is_same_v) + { + s += "missing payload"; + } + + else if constexpr (std::is_same_v) + { + std::vector>::iterator block; for (block = arg.blocks.begin (); block < arg.blocks.end (); ++block) { s += (*block)->to_json (); } - - }, payload); - } - - if (payload.index() == 2) - { - std::visit([&s] (auto && arg) { - s += "account public key:" + arg.account.to_account (); - s += " account open" + arg.account_open.to_string () - s += " account head" + arg.account_head.to_string (); - s += " block count" + to_string_hex (arg.block_count); + } + + else if constexpr (std::is_same_v) + { + s += "account public key:" + arg.account.to_account (); + s += " account open:" + arg.account_open.to_string () + s += " account head:" + arg.account_head.to_string (); + s += " block count:" + to_string_hex (arg.block_count); s += " confirmation frontier:" + arg.account_conf_frontier.to_string (); - s += " confirmation height" + to_string_hex (arg.account_conf_height); - }, payload) - } + s += " confirmation height:" + to_string_hex (arg.account_conf_height); + } + + }, payload); - return s; + return s; } /* From 8d8653864521576680a87c74973ec7f63df316e1 Mon Sep 17 00:00:00 2001 From: Brandon Date: Thu, 29 Jun 2023 12:27:03 +0100 Subject: [PATCH 06/10] final corrections to make this viable for pull request --- nano/node/messages.cpp | 12 +++++------- nano/node/messages.hpp | 3 ++- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/nano/node/messages.cpp b/nano/node/messages.cpp index 7cf6e81d84..1af7593d08 100644 --- a/nano/node/messages.cpp +++ b/nano/node/messages.cpp @@ -1853,7 +1853,7 @@ std::string nano::asc_pull_ack::to_string () const s += "missing payload"; } - else if constexpr (std::is_same_v) + else if constexpr (std::is_same_v) { std::vector>::iterator block; @@ -1863,12 +1863,12 @@ std::string nano::asc_pull_ack::to_string () const } } - else if constexpr (std::is_same_v) + else if constexpr (std::is_same_v) { s += "account public key:" + arg.account.to_account (); - s += " account open:" + arg.account_open.to_string () + s += " account open:" + arg.account_open.to_string (); s += " account head:" + arg.account_head.to_string (); - s += " block count:" + to_string_hex (arg.block_count); + s += " block count:" + to_string_hex (arg.account_block_count); s += " confirmation frontier:" + arg.account_conf_frontier.to_string (); s += " confirmation height:" + to_string_hex (arg.account_conf_height); } @@ -1897,9 +1897,7 @@ void nano::asc_pull_ack::blocks_payload::serialize (nano::stream & stream) const void nano::asc_pull_ack::blocks_payload::deserialize (nano::stream & stream) { - auto current = nano::deserialize_b0 - - lock (stream); + auto current = nano::deserialize_block (stream); while (current && blocks.size () < max_blocks) { blocks.push_back (current); diff --git a/nano/node/messages.hpp b/nano/node/messages.hpp index 5489d107b5..6ebe093738 100644 --- a/nano/node/messages.hpp +++ b/nano/node/messages.hpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -616,4 +617,4 @@ class message_visitor } virtual void default_handler (nano::message const &){}; }; -} \ No newline at end of file +} From d338deb74dcbd08275bb97f78f255cd12fd8b33b Mon Sep 17 00:00:00 2001 From: Brandon Date: Thu, 29 Jun 2023 21:28:26 +0100 Subject: [PATCH 07/10] iterator does not have operator= - changed format of loop. --- nano/node/messages.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/nano/node/messages.cpp b/nano/node/messages.cpp index 1af7593d08..c615a25416 100644 --- a/nano/node/messages.cpp +++ b/nano/node/messages.cpp @@ -1855,12 +1855,24 @@ std::string nano::asc_pull_ack::to_string () const else if constexpr (std::is_same_v) { + std::vector>::iterator block; - for (block = arg.blocks.begin (); block < arg.blocks.end (); ++block) + for (block = arg.blocks.begin (); block != arg.blocks.end (); ++block) { s += (*block)->to_json (); } + + + auto block = std::begin(arg.blocks); + auto end_block = std::end(arg.blocks); + + while (block != end_block) + { + s += (*block)->to_json (); + ++block; + } + } else if constexpr (std::is_same_v) From ca2a785e39403038ac42c648f13d51e7b56532aa Mon Sep 17 00:00:00 2001 From: Brandon Date: Sat, 1 Jul 2023 15:45:41 +0100 Subject: [PATCH 08/10] clang formatted + made small changes to make it work as intended --- nano/node/messages.cpp | 96 ++++++++++++++++++------------------------ nano/node/messages.hpp | 5 +-- 2 files changed, 43 insertions(+), 58 deletions(-) diff --git a/nano/node/messages.cpp b/nano/node/messages.cpp index c615a25416..aa2c69074a 100644 --- a/nano/node/messages.cpp +++ b/nano/node/messages.cpp @@ -1656,36 +1656,34 @@ bool nano::asc_pull_req::verify_consistency () const return true; // Just for convenience of calling from asserts } -std::string nano::asc_pull_req::to_string () const +std::string nano::asc_pull_req::to_string () const { std::string s = header.to_string () + "\n"; - std::visit ([&s](auto && arg) - { - using T = std::decay_t; - - if constexpr (std::is_same_v) - { - s += "missing payload"; - } - - else if constexpr (std::is_same_v) - { - s += "acc:" + arg.start.to_string(); - s += " max block count:" + to_string_hex(static_cast (arg.count)); - s += " hash type:" + to_string_hex(static_cast (arg.start_type)); - } - - else if constexpr (std::is_same_v) - { - s += "target:" + arg.target.to_string (); + std::visit ([&s] (auto && arg) { + using T = std::decay_t; + + if constexpr (std::is_same_v) + { + s += "missing payload"; + } + + else if constexpr (std::is_same_v) + { + s += "acc:" + arg.start.to_string (); + s += " max block count:" + to_string_hex (static_cast (arg.count)); + s += " hash type:" + to_string_hex (static_cast (arg.start_type)); + } + + else if constexpr (std::is_same_v) + { + s += "target:" + arg.target.to_string (); s += " hash type:" + to_string_hex (static_cast (arg.target_type)); - } - - }, payload); + } + }, + payload); return s; - } /* * asc_pull_req::blocks_payload @@ -1844,49 +1842,37 @@ std::string nano::asc_pull_ack::to_string () const { std::string s = header.to_string () + "\n"; - std::visit ( [&s](auto && arg) - { - using T = std::decay_t; + std::visit ([&s] (auto && arg) { + using T = std::decay_t; - if constexpr (std::is_same_v) - { - s += "missing payload"; - } + if constexpr (std::is_same_v) + { + s += "missing payload"; + } - else if constexpr (std::is_same_v) - { - - std::vector>::iterator block; + else if constexpr (std::is_same_v) + { + auto block = std::begin (arg.blocks); + auto end_block = std::end (arg.blocks); - for (block = arg.blocks.begin (); block != arg.blocks.end (); ++block) + while (block != end_block) { s += (*block)->to_json (); + ++block; } - - - auto block = std::begin(arg.blocks); - auto end_block = std::end(arg.blocks); - - while (block != end_block) - { - s += (*block)->to_json (); - ++block; - } - - } + } - else if constexpr (std::is_same_v) - { - s += "account public key:" + arg.account.to_account (); + else if constexpr (std::is_same_v) + { + s += "account public key:" + arg.account.to_account (); s += " account open:" + arg.account_open.to_string (); s += " account head:" + arg.account_head.to_string (); s += " block count:" + to_string_hex (arg.account_block_count); s += " confirmation frontier:" + arg.account_conf_frontier.to_string (); s += " confirmation height:" + to_string_hex (arg.account_conf_height); - } - - }, payload); - + } + }, + payload); return s; } diff --git a/nano/node/messages.hpp b/nano/node/messages.hpp index 6ebe093738..07c954346a 100644 --- a/nano/node/messages.hpp +++ b/nano/node/messages.hpp @@ -14,12 +14,11 @@ #include #include +#include #include #include -#include #include -#include -#include +#include namespace nano { From 1fa126552fe47977079de159ca4ea4774379deed Mon Sep 17 00:00:00 2001 From: Brandon Date: Sat, 1 Jul 2023 16:11:39 +0100 Subject: [PATCH 09/10] added back into messages.hpp --- nano/node/messages.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/nano/node/messages.hpp b/nano/node/messages.hpp index 07c954346a..2bad484366 100644 --- a/nano/node/messages.hpp +++ b/nano/node/messages.hpp @@ -19,6 +19,7 @@ #include #include #include +#include namespace nano { From 48a4bf885f0ae2dba56785fb2271f3c66e0123bc Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Wed, 30 Aug 2023 18:19:26 +0100 Subject: [PATCH 10/10] Cleaning up headers and moving their inclusion to the implementation file. --- nano/node/messages.cpp | 2 ++ nano/node/messages.hpp | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nano/node/messages.cpp b/nano/node/messages.cpp index aa2c69074a..2417eddf18 100644 --- a/nano/node/messages.cpp +++ b/nano/node/messages.cpp @@ -23,7 +23,9 @@ #include #include #include +#include #include +#include #include /* diff --git a/nano/node/messages.hpp b/nano/node/messages.hpp index 2bad484366..bf4ab2b2ab 100644 --- a/nano/node/messages.hpp +++ b/nano/node/messages.hpp @@ -14,10 +14,8 @@ #include #include -#include #include #include -#include #include #include