Inactive cache information to string (easy review) (#3730)

* to_string functions for inactive_cache_information & inactive_cache_status

* Move class inactive_cache_status to its own file

* Move class inactive_cache_information to its own file
This commit is contained in:
Dimitrios Siganos 2022-02-10 11:24:28 +00:00 committed by GitHub
commit f0bea17f4b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 104 additions and 37 deletions

View file

@ -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

View file

@ -2,6 +2,8 @@
#include <nano/lib/numbers.hpp>
#include <nano/node/election.hpp>
#include <nano/node/inactive_cache_information.hpp>
#include <nano/node/inactive_cache_status.hpp>
#include <nano/node/voting.hpp>
#include <nano/secure/common.hpp>
@ -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<std::pair<nano::account, uint64_t>> voters;
bool needs_eval () const
{
return !status.bootstrap_started || !status.election_started || !status.confirmed;
}
};
class expired_optimistic_election_info final
{
public:

View file

@ -0,0 +1,17 @@
#include <nano/node/inactive_cache_information.hpp>
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<std::chrono::seconds> (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 ();
}

View file

@ -0,0 +1,36 @@
#pragma once
#include <nano/lib/numbers.hpp>
#include <nano/node/inactive_cache_status.hpp>
#include <chrono>
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<std::pair<nano::account, uint64_t>> voters;
bool needs_eval () const
{
return !status.bootstrap_started || !status.election_started || !status.confirmed;
}
std::string to_string () const;
};
}

View file

@ -0,0 +1,19 @@
#include <nano/node/inactive_cache_status.hpp>
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 ();
}

View file

@ -0,0 +1,26 @@
#pragma once
#include <nano/lib/numbers.hpp>
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;
};
}