diff --git a/nano/node/CMakeLists.txt b/nano/node/CMakeLists.txt index 36e1024b..0a737a55 100644 --- a/nano/node/CMakeLists.txt +++ b/nano/node/CMakeLists.txt @@ -60,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 diff --git a/nano/node/active_transactions.hpp b/nano/node/active_transactions.hpp index 1411505b..7eb6dcef 100644 --- a/nano/node/active_transactions.hpp +++ b/nano/node/active_transactions.hpp @@ -2,6 +2,8 @@ #include #include +#include +#include #include #include @@ -51,43 +53,6 @@ public: 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; - } -}; - -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; - } -}; - 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 00000000..cf905aaa --- /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 00000000..78259901 --- /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; +}; + +} diff --git a/nano/node/inactive_cache_status.cpp b/nano/node/inactive_cache_status.cpp new file mode 100644 index 00000000..2ec4bb63 --- /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 00000000..bbd0ffaf --- /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; +}; + +}