Skip to content

Commit

Permalink
improve election result logging (#3684)
Browse files Browse the repository at this point in the history
Co-authored-by: fikumikudev <fikumikudev@users.noreply.github.com>
  • Loading branch information
pwojcikdev and fikumikudev authored Feb 1, 2022
1 parent 1cf9d35 commit 1214b2c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
6 changes: 6 additions & 0 deletions nano/lib/stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,12 @@ std::string nano::stat::detail_to_string (uint32_t key)
case nano::stat::detail::election_restart:
res = "election_restart";
break;
case nano::stat::detail::election_confirmed:
res = "election_confirmed";
break;
case nano::stat::detail::election_not_confirmed:
res = "election_not_confirmed";
break;
case nano::stat::detail::blocking:
res = "blocking";
break;
Expand Down
2 changes: 2 additions & 0 deletions nano/lib/stats.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ class stat final
election_drop_overflow,
election_drop_all,
election_restart,
election_confirmed,
election_not_confirmed,

// udp
blocking,
Expand Down
7 changes: 6 additions & 1 deletion nano/node/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,12 @@ void nano::active_transactions::cleanup_election (nano::unique_lock<nano::mutex>
node.network.publish_filter.clear (block);
}
}
node.logger.try_log (boost::str (boost::format ("Election erased for root %1%, confirmed: %2$b") % election.qualified_root.to_string () % election.confirmed ()));

node.stats.inc (nano::stat::type::election, election.confirmed () ? nano::stat::detail::election_confirmed : nano::stat::detail::election_not_confirmed);
if (node.config.logging.election_result_logging ())
{
node.logger.try_log (boost::str (boost::format ("Election erased for root %1%, confirmed: %2$b") % election.qualified_root.to_string () % election.confirmed ()));
}
}

std::vector<std::shared_ptr<nano::election>> nano::active_transactions::list_active (std::size_t max_a)
Expand Down
7 changes: 7 additions & 0 deletions nano/node/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ nano::error nano::logging::serialize_toml (nano::tomlconfig & toml) const
toml.put ("upnp_details", upnp_details_logging_value, "Log UPNP discovery details..\nWarning: this may include information.\nabout discovered devices, such as product identification. Please review before sharing logs.\ntype:bool");
toml.put ("timing", timing_logging_value, "Log detailed timing information for various node operations.\ntype:bool");
toml.put ("active_update", active_update_value, "Log when a block is updated while in active transactions.\ntype:bool");
toml.put ("election_result", election_result_logging_value, "Log election result when cleaning up election from active election container.\ntype:bool");
toml.put ("log_to_cerr", log_to_cerr_value, "Log to standard error in addition to the log file. Not recommended for production systems.\ntype:bool");
toml.put ("max_size", max_size, "Maximum log file size in bytes.\ntype:uint64");
toml.put ("rotation_size", rotation_size, "Log file rotation size in character count.\ntype:uint64");
Expand Down Expand Up @@ -203,6 +204,7 @@ nano::error nano::logging::deserialize_toml (nano::tomlconfig & toml)
toml.get<bool> ("upnp_details", upnp_details_logging_value);
toml.get<bool> ("timing", timing_logging_value);
toml.get<bool> ("active_update", active_update_value);
toml.get<bool> ("election_result", election_result_logging_value);
toml.get<bool> ("log_to_cerr", log_to_cerr_value);
toml.get<bool> ("flush", flush);
toml.get<bool> ("single_line_record", single_line_record_value);
Expand Down Expand Up @@ -341,6 +343,11 @@ bool nano::logging::active_update_logging () const
return active_update_value;
}

bool nano::logging::election_result_logging () const
{
return election_result_logging_value;
}

bool nano::logging::log_to_cerr () const
{
return log_to_cerr_value;
Expand Down
2 changes: 2 additions & 0 deletions nano/node/logging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class logging final
bool callback_logging () const;
bool work_generation_time () const;
bool active_update_logging () const;
bool election_result_logging () const;
bool log_to_cerr () const;
bool single_line_record () const;
void init (boost::filesystem::path const &);
Expand Down Expand Up @@ -91,6 +92,7 @@ class logging final
bool upnp_details_logging_value{ false };
bool timing_logging_value{ false };
bool active_update_value{ false };
bool election_result_logging_value{ false };
bool log_to_cerr_value{ false };
bool flush{ true };
uintmax_t max_size{ 128 * 1024 * 1024 };
Expand Down

0 comments on commit 1214b2c

Please sign in to comment.