From 51235ae3b43745bd7ebdde439e9c5204f7ed4832 Mon Sep 17 00:00:00 2001 From: Dimitrios Siganos Date: Thu, 10 Feb 2022 02:47:39 +0000 Subject: [PATCH 1/4] to_string functions for inactive_cache_information & inactive_cache_status --- nano/node/active_transactions.hpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/nano/node/active_transactions.hpp b/nano/node/active_transactions.hpp index 1411505bd0..c7faf8e42f 100644 --- a/nano/node/active_transactions.hpp +++ b/nano/node/active_transactions.hpp @@ -63,6 +63,16 @@ class inactive_cache_status final { return bootstrap_started != other.bootstrap_started || election_started != other.election_started || confirmed != other.confirmed || tally != other.tally; } + + std::string to_string () const + { + std::stringstream ss; + ss << "bootstrap_started=" << bootstrap_started; + ss << ", election_started=" << election_started; + ss << ", confirmed=" << confirmed; + ss << ", tally=" << nano::uint128_union (tally).to_string (); + return ss.str (); + } }; class inactive_cache_information final @@ -82,10 +92,25 @@ class inactive_cache_information final nano::block_hash hash; nano::inactive_cache_status status; std::vector> voters; + bool needs_eval () const { return !status.bootstrap_started || !status.election_started || !status.confirmed; } + + std::string to_string () const + { + std::stringstream ss; + ss << "hash=" << hash.to_string (); + ss << ", arrival=" << std::chrono::duration_cast (arrival.time_since_epoch ()).count (); + ss << ", " << status.to_string (); + ss << ", " << voters.size () << " voters"; + for (auto const & [rep, timestamp] : voters) + { + ss << " " << rep.to_account () << "/" << timestamp; + } + return ss.str (); + } }; class expired_optimistic_election_info final From c031f7aee24da0c023db8dc2410926426e1164ce Mon Sep 17 00:00:00 2001 From: Dimitrios Siganos Date: Thu, 10 Feb 2022 03:42:30 +0000 Subject: [PATCH 2/4] Move class inactive_cache_status to its own file --- nano/node/CMakeLists.txt | 2 ++ nano/node/active_transactions.hpp | 25 +------------------------ nano/node/inactive_cache_status.cpp | 19 +++++++++++++++++++ nano/node/inactive_cache_status.hpp | 26 ++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 24 deletions(-) create mode 100644 nano/node/inactive_cache_status.cpp create mode 100644 nano/node/inactive_cache_status.hpp diff --git a/nano/node/CMakeLists.txt b/nano/node/CMakeLists.txt index 36e1024bf9..d3c2be7eae 100644 --- a/nano/node/CMakeLists.txt +++ b/nano/node/CMakeLists.txt @@ -14,6 +14,8 @@ endif() add_library( node ${platform_sources} + inactive_cache_status.hpp + inactive_cache_status.cpp active_transactions.hpp active_transactions.cpp blockprocessor.hpp diff --git a/nano/node/active_transactions.hpp b/nano/node/active_transactions.hpp index c7faf8e42f..0fb159f10b 100644 --- a/nano/node/active_transactions.hpp +++ b/nano/node/active_transactions.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -51,30 +52,6 @@ class election_timepoint final nano::qualified_root root; }; -class inactive_cache_status final -{ -public: - bool bootstrap_started{ false }; - bool election_started{ false }; // Did item reach config threshold to start an impromptu election? - bool confirmed{ false }; // Did item reach votes quorum? (minimum config value) - nano::uint128_t tally{ 0 }; // Last votes tally for block - - bool operator!= (inactive_cache_status const other) const - { - return bootstrap_started != other.bootstrap_started || election_started != other.election_started || confirmed != other.confirmed || tally != other.tally; - } - - std::string to_string () const - { - std::stringstream ss; - ss << "bootstrap_started=" << bootstrap_started; - ss << ", election_started=" << election_started; - ss << ", confirmed=" << confirmed; - ss << ", tally=" << nano::uint128_union (tally).to_string (); - return ss.str (); - } -}; - class inactive_cache_information final { public: diff --git a/nano/node/inactive_cache_status.cpp b/nano/node/inactive_cache_status.cpp new file mode 100644 index 0000000000..2ec4bb6398 --- /dev/null +++ b/nano/node/inactive_cache_status.cpp @@ -0,0 +1,19 @@ +#include + +bool nano::inactive_cache_status::operator!= (inactive_cache_status const other) const +{ + return bootstrap_started != other.bootstrap_started + || election_started != other.election_started + || confirmed != other.confirmed + || tally != other.tally; +} + +std::string nano::inactive_cache_status::to_string () const +{ + std::stringstream ss; + ss << "bootstrap_started=" << bootstrap_started; + ss << ", election_started=" << election_started; + ss << ", confirmed=" << confirmed; + ss << ", tally=" << nano::uint128_union (tally).to_string (); + return ss.str (); +} diff --git a/nano/node/inactive_cache_status.hpp b/nano/node/inactive_cache_status.hpp new file mode 100644 index 0000000000..bbd0ffafcf --- /dev/null +++ b/nano/node/inactive_cache_status.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include + +namespace nano +{ +class inactive_cache_status final +{ +public: + bool bootstrap_started{ false }; + + /** Did item reach config threshold to start an impromptu election? */ + bool election_started{ false }; + + /** Did item reach votes quorum? (minimum config value) */ + bool confirmed{ false }; + + /** Last votes tally for block */ + nano::uint128_t tally{ 0 }; + + bool operator!= (inactive_cache_status const other) const; + + std::string to_string () const; +}; + +} From 08583c2af3dc2cab6c7873fa9b7a9449b1a7d7f0 Mon Sep 17 00:00:00 2001 From: Dimitrios Siganos Date: Thu, 10 Feb 2022 04:00:56 +0000 Subject: [PATCH 3/4] Move class inactive_cache_information to its own file --- nano/node/CMakeLists.txt | 2 ++ nano/node/active_transactions.hpp | 39 +----------------------- nano/node/inactive_cache_information.cpp | 17 +++++++++++ nano/node/inactive_cache_information.hpp | 36 ++++++++++++++++++++++ 4 files changed, 56 insertions(+), 38 deletions(-) create mode 100644 nano/node/inactive_cache_information.cpp create mode 100644 nano/node/inactive_cache_information.hpp diff --git a/nano/node/CMakeLists.txt b/nano/node/CMakeLists.txt index d3c2be7eae..644ba588e7 100644 --- a/nano/node/CMakeLists.txt +++ b/nano/node/CMakeLists.txt @@ -14,6 +14,8 @@ endif() add_library( node ${platform_sources} + inactive_cache_information.hpp + inactive_cache_information.cpp inactive_cache_status.hpp inactive_cache_status.cpp active_transactions.hpp diff --git a/nano/node/active_transactions.hpp b/nano/node/active_transactions.hpp index 0fb159f10b..7eb6dcef61 100644 --- a/nano/node/active_transactions.hpp +++ b/nano/node/active_transactions.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -52,44 +53,6 @@ class election_timepoint final nano::qualified_root root; }; -class inactive_cache_information final -{ -public: - inactive_cache_information () = default; - inactive_cache_information (std::chrono::steady_clock::time_point arrival, nano::block_hash hash, nano::account initial_rep_a, uint64_t initial_timestamp_a, nano::inactive_cache_status status) : - arrival (arrival), - hash (hash), - status (status) - { - voters.reserve (8); - voters.emplace_back (initial_rep_a, initial_timestamp_a); - } - - std::chrono::steady_clock::time_point arrival; - nano::block_hash hash; - nano::inactive_cache_status status; - std::vector> voters; - - bool needs_eval () const - { - return !status.bootstrap_started || !status.election_started || !status.confirmed; - } - - std::string to_string () const - { - std::stringstream ss; - ss << "hash=" << hash.to_string (); - ss << ", arrival=" << std::chrono::duration_cast (arrival.time_since_epoch ()).count (); - ss << ", " << status.to_string (); - ss << ", " << voters.size () << " voters"; - for (auto const & [rep, timestamp] : voters) - { - ss << " " << rep.to_account () << "/" << timestamp; - } - return ss.str (); - } -}; - class expired_optimistic_election_info final { public: diff --git a/nano/node/inactive_cache_information.cpp b/nano/node/inactive_cache_information.cpp new file mode 100644 index 0000000000..cf905aaac5 --- /dev/null +++ b/nano/node/inactive_cache_information.cpp @@ -0,0 +1,17 @@ +#include + +using namespace std::chrono; + +std::string nano::inactive_cache_information::to_string () const +{ + std::stringstream ss; + ss << "hash=" << hash.to_string (); + ss << ", arrival=" << std::chrono::duration_cast (arrival.time_since_epoch ()).count (); + ss << ", " << status.to_string (); + ss << ", " << voters.size () << " voters"; + for (auto const & [rep, timestamp] : voters) + { + ss << " " << rep.to_account () << "/" << timestamp; + } + return ss.str (); +} diff --git a/nano/node/inactive_cache_information.hpp b/nano/node/inactive_cache_information.hpp new file mode 100644 index 0000000000..7825990156 --- /dev/null +++ b/nano/node/inactive_cache_information.hpp @@ -0,0 +1,36 @@ +#pragma once + +#include +#include + +#include + +namespace nano +{ +class inactive_cache_information final +{ +public: + inactive_cache_information () = default; + inactive_cache_information (std::chrono::steady_clock::time_point arrival, nano::block_hash hash, nano::account initial_rep_a, uint64_t initial_timestamp_a, nano::inactive_cache_status status) : + arrival (arrival), + hash (hash), + status (status) + { + voters.reserve (8); + voters.emplace_back (initial_rep_a, initial_timestamp_a); + } + + std::chrono::steady_clock::time_point arrival; + nano::block_hash hash; + nano::inactive_cache_status status; + std::vector> voters; + + bool needs_eval () const + { + return !status.bootstrap_started || !status.election_started || !status.confirmed; + } + + std::string to_string () const; +}; + +} From e27b30b9c24bea2863487f82d1c7f9973169d45d Mon Sep 17 00:00:00 2001 From: Dimitrios Siganos Date: Thu, 10 Feb 2022 04:50:31 +0000 Subject: [PATCH 4/4] the list seems to be alphabetical, following the pattern --- nano/node/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/nano/node/CMakeLists.txt b/nano/node/CMakeLists.txt index 644ba588e7..0a737a5592 100644 --- a/nano/node/CMakeLists.txt +++ b/nano/node/CMakeLists.txt @@ -14,10 +14,6 @@ endif() add_library( node ${platform_sources} - inactive_cache_information.hpp - inactive_cache_information.cpp - inactive_cache_status.hpp - inactive_cache_status.cpp active_transactions.hpp active_transactions.cpp blockprocessor.hpp @@ -64,6 +60,10 @@ add_library( election_scheduler.cpp gap_cache.hpp gap_cache.cpp + inactive_cache_information.hpp + inactive_cache_information.cpp + inactive_cache_status.hpp + inactive_cache_status.cpp ipc/action_handler.hpp ipc/action_handler.cpp ipc/flatbuffers_handler.hpp