Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inactive cache information to string (easy review) #3730

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions nano/node/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 2 additions & 37 deletions nano/node/active_transactions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -51,43 +53,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;
}
};

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:
Expand Down
17 changes: 17 additions & 0 deletions nano/node/inactive_cache_information.cpp
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 ();
}
36 changes: 36 additions & 0 deletions nano/node/inactive_cache_information.hpp
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;
};

}
19 changes: 19 additions & 0 deletions nano/node/inactive_cache_status.cpp
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 ();
}
26 changes: 26 additions & 0 deletions nano/node/inactive_cache_status.hpp
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;
};

}