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

Split election drop stats to be either overflow or expired #3297

Merged
merged 12 commits into from
May 28, 2021
6 changes: 4 additions & 2 deletions nano/core_test/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ TEST (active_transactions, dropped_cleanup)
ASSERT_FALSE (node.network.publish_filter.apply (block_bytes.data (), block_bytes.size ()));

// An election was recently dropped
ASSERT_EQ (1, node.stats.count (nano::stat::type::election, nano::stat::detail::election_drop));
ASSERT_EQ (1, node.stats.count (nano::stat::type::election, nano::stat::detail::election_drop_all));

// Block cleared from active
ASSERT_EQ (0, node.active.blocks.count (block->hash ()));
Expand All @@ -632,7 +632,7 @@ TEST (active_transactions, dropped_cleanup)
ASSERT_TRUE (node.network.publish_filter.apply (block_bytes.data (), block_bytes.size ()));

// Not dropped
ASSERT_EQ (1, node.stats.count (nano::stat::type::election, nano::stat::detail::election_drop));
ASSERT_EQ (1, node.stats.count (nano::stat::type::election, nano::stat::detail::election_drop_all));

// Block cleared from active
ASSERT_EQ (0, node.active.blocks.count (block->hash ()));
Expand Down Expand Up @@ -1525,6 +1525,8 @@ TEST (active_transactions, fifo)
ASSERT_TIMELY (1s, node.active.election (receive1->qualified_root ()) != nullptr);
// Ensure excess transactions get trimmed
ASSERT_TIMELY (1s, node.active.size () == 1);
// Ensure overflow stats have been incremented
ASSERT_EQ (1, node.stats.count (nano::stat::type::election, nano::stat::detail::election_drop_overflow));
// Ensure the surviving transaction is the least recently inserted
ASSERT_TIMELY (1s, node.active.election (receive1->qualified_root ()) != nullptr);
}
10 changes: 8 additions & 2 deletions nano/lib/stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -739,8 +739,14 @@ std::string nano::stat::detail_to_string (uint32_t key)
case nano::stat::detail::election_difficulty_update:
res = "election_difficulty_update";
break;
case nano::stat::detail::election_drop:
res = "election_drop";
case nano::stat::detail::election_drop_expired:
res = "election_drop_expired";
break;
case nano::stat::detail::election_drop_overflow:
res = "election_drop_overflow";
break;
case nano::stat::detail::election_drop_all:
res = "election_drop_all";
break;
case nano::stat::detail::election_restart:
res = "election_restart";
Expand Down
4 changes: 3 additions & 1 deletion nano/lib/stats.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,9 @@ class stat final
election_start,
election_block_conflict,
election_difficulty_update,
election_drop,
election_drop_expired,
election_drop_overflow,
election_drop_all,
election_restart,

// udp
Expand Down
8 changes: 7 additions & 1 deletion nano/node/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ void nano::active_transactions::request_confirm (nano::unique_lock<nano::mutex>
for (auto const & election_l : elections_l)
{
bool const confirmed_l (election_l->confirmed ());
unconfirmed_count_l += !confirmed_l;

if (election_l->transition_time (solicitor))
{
Expand All @@ -330,6 +331,10 @@ void nano::active_transactions::request_confirm (nano::unique_lock<nano::mutex>
}

// Locks active mutex, cleans up the election and erases it from the main container
if (!confirmed_l)
{
node.stats.inc (nano::stat::type::election, nano::stat::detail::election_drop_expired);
}
erase (election_l->qualified_root);
}
}
Expand All @@ -349,7 +354,7 @@ void nano::active_transactions::cleanup_election (nano::unique_lock<nano::mutex>
{
if (!election.confirmed ())
{
node.stats.inc (nano::stat::type::election, nano::stat::detail::election_drop);
node.stats.inc (nano::stat::type::election, nano::stat::detail::election_drop_all);
}

auto blocks_l = election.blocks ();
Expand Down Expand Up @@ -1049,6 +1054,7 @@ void nano::active_transactions::erase_oldest ()
nano::unique_lock<nano::mutex> lock (mutex);
if (!roots.empty ())
{
node.stats.inc (nano::stat::type::election, nano::stat::detail::election_drop_overflow);
auto item = roots.get<tag_random_access> ().front ();
cleanup_election (lock, *item.election);
}
Expand Down