-
Notifications
You must be signed in to change notification settings - Fork 795
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
6 changed files
with
104 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 (); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 (); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; | ||
|
||
} |