Skip to content

Commit

Permalink
Report unique vote count
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Mar 21, 2024
1 parent d05d98e commit 5390cc5
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion nano/node/vote_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,23 @@ void nano::vote_cache::cleanup ()

std::unique_ptr<nano::container_info_component> nano::vote_cache::collect_container_info (const std::string & name) const
{
nano::lock_guard<nano::mutex> guard{ mutex };

auto count_unique_votes = [this] () {
std::unordered_set<std::shared_ptr<nano::vote>> votes;
for (auto const & entry : cache)
{
for (auto const & vote : entry.votes ())
{
votes.insert (vote);
}
}
return votes.size ();
};

auto composite = std::make_unique<container_info_composite> (name);
composite->add_component (std::make_unique<container_info_leaf> (container_info{ "cache", size (), sizeof (ordered_cache::value_type) }));
composite->add_component (std::make_unique<container_info_leaf> (container_info{ "cache", cache.size (), sizeof (ordered_cache::value_type) }));
composite->add_component (std::make_unique<container_info_leaf> (container_info{ "unique", count_unique_votes (), sizeof (nano::vote) }));
return composite;
}

Expand Down

0 comments on commit 5390cc5

Please sign in to comment.