Skip to content

Commit

Permalink
Make use of transition_priority() in active_elections
Browse files Browse the repository at this point in the history
  • Loading branch information
gr0vity-dev committed Dec 3, 2024
1 parent a5bf4d7 commit cb39f8d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions nano/lib/stats_enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,8 @@ enum class detail
// active
insert,
insert_failed,
transition_priority,
transition_priority_failed,
election_cleanup,

// active_elections
Expand Down
17 changes: 17 additions & 0 deletions nano/node/active_elections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,23 @@ nano::election_insertion_result nano::active_elections::insert (std::shared_ptr<
else
{
result.election = existing->election;

// Upgrade to priority election to enable immediate vote broadcasting.
auto previous_behavior = result.election->behavior ();
if (election_behavior_a == nano::election_behavior::priority && previous_behavior != nano::election_behavior::priority)
{
bool transitioned = result.election->transition_priority ();
if (transitioned)
{
count_by_behavior[previous_behavior]--;
count_by_behavior[election_behavior_a]++;
node.stats.inc (nano::stat::type::active_elections, nano::stat::detail::transition_priority);
}
else
{
node.stats.inc (nano::stat::type::active_elections, nano::stat::detail::transition_priority_failed);
}
}
}

lock.unlock ();
Expand Down

0 comments on commit cb39f8d

Please sign in to comment.