Make logging election tally an optional config (#2888)

* Make logging election tally an optional config

One config for logging on expired elections, another for confirmed elections with multiple blocks, both default to false.

* Change prefix in case single line record config is set
This commit is contained in:
Guilherme Lawless 2020-08-25 15:43:03 +01:00 committed by GitHub
commit 4ddcdddf8a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 5 deletions

View file

@ -215,7 +215,10 @@ bool nano::election::transition_time (nano::confirmation_solicitor & solicitor_a
result = true;
state_change (state_m.load (), nano::election::state_t::expired_unconfirmed);
status.type = nano::election_status_type::stopped;
log_votes (tally ());
if (node.config.logging.election_expiration_tally_logging ())
{
log_votes (tally (), "Election expired: ");
}
}
return result;
}
@ -276,7 +279,7 @@ void nano::election::confirm_if_quorum ()
}
if (have_quorum (tally_l, sum))
{
if (node.config.logging.vote_logging () || blocks.size () > 1)
if (node.config.logging.vote_logging () || (node.config.logging.election_fork_tally_logging () && blocks.size () > 1))
{
log_votes (tally_l);
}
@ -284,11 +287,11 @@ void nano::election::confirm_if_quorum ()
}
}
void nano::election::log_votes (nano::tally_t const & tally_a) const
void nano::election::log_votes (nano::tally_t const & tally_a, std::string const & prefix_a) const
{
std::stringstream tally;
std::string line_end (node.config.logging.single_line_record () ? "\t" : "\n");
tally << boost::str (boost::format ("%1%Vote tally for root %2%") % line_end % root.to_string ());
tally << boost::str (boost::format ("%1%%2%Vote tally for root %3%") % prefix_a % line_end % root.to_string ());
for (auto i (tally_a.begin ()), n (tally_a.end ()); i != n; ++i)
{
tally << boost::str (boost::format ("%1%Block %2% weight %3%") % line_end % i->second->hash ().to_string () % i->first.convert_to<std::string> ());

View file

@ -75,7 +75,7 @@ public:
void confirm_once (nano::election_status_type = nano::election_status_type::active_confirmed_quorum);
// Confirm this block if quorum is met
void confirm_if_quorum ();
void log_votes (nano::tally_t const &) const;
void log_votes (nano::tally_t const &, std::string const & = "") const;
bool publish (std::shared_ptr<nano::block> block_a);
size_t last_votes_size ();
size_t insert_inactive_votes_cache (nano::block_hash const &);

View file

@ -149,6 +149,8 @@ nano::error nano::logging::serialize_toml (nano::tomlconfig & toml) const
toml.put ("ledger", ledger_logging_value, "Log ledger related messages.\ntype:bool");
toml.put ("ledger_duplicate", ledger_duplicate_logging_value, "Log when a duplicate block is attempted inserted into the ledger.\ntype:bool");
toml.put ("vote", vote_logging_value, "Vote logging. Enabling this option leads to a high volume.\nof log messages which may affect node performance.\ntype:bool");
toml.put ("election_expiration", election_expiration_tally_logging_value, "Log election tally on expiration.\ntype:bool");
toml.put ("election_fork", election_fork_tally_logging_value, "Log election tally when more than one block is seen.\ntype:bool");
toml.put ("network", network_logging_value, "Log network related messages.\ntype:bool");
toml.put ("network_timeout", network_timeout_logging_value, "Log TCP timeouts.\ntype:bool");
toml.put ("network_message", network_message_logging_value, "Log network errors and message details.\ntype:bool");
@ -182,6 +184,8 @@ nano::error nano::logging::deserialize_toml (nano::tomlconfig & toml)
toml.get<bool> ("ledger", ledger_logging_value);
toml.get<bool> ("ledger_duplicate", ledger_duplicate_logging_value);
toml.get<bool> ("vote", vote_logging_value);
toml.get<bool> ("election_expiration", election_expiration_tally_logging_value);
toml.get<bool> ("election_fork", election_fork_tally_logging_value);
toml.get<bool> ("network", network_logging_value);
toml.get<bool> ("network_timeout", network_timeout_logging_value);
toml.get<bool> ("network_message", network_message_logging_value);
@ -314,6 +318,16 @@ bool nano::logging::vote_logging () const
return vote_logging_value;
}
bool nano::logging::election_expiration_tally_logging () const
{
return election_expiration_tally_logging_value;
}
bool nano::logging::election_fork_tally_logging () const
{
return election_fork_tally_logging_value;
}
bool nano::logging::network_logging () const
{
return network_logging_value;

View file

@ -45,6 +45,8 @@ public:
bool ledger_logging () const;
bool ledger_duplicate_logging () const;
bool vote_logging () const;
bool election_fork_tally_logging () const;
bool election_expiration_tally_logging () const;
bool network_logging () const;
bool network_timeout_logging () const;
bool network_message_logging () const;
@ -70,6 +72,8 @@ public:
bool ledger_logging_value{ false };
bool ledger_duplicate_logging_value{ false };
bool vote_logging_value{ false };
bool election_fork_tally_logging_value{ false };
bool election_expiration_tally_logging_value{ false };
bool network_logging_value{ true };
bool network_timeout_logging_value{ false };
bool network_message_logging_value{ false };