From cb39f8d70b903a3d680fd44a341d7f61719fefe5 Mon Sep 17 00:00:00 2001 From: gr0vity-dev Date: Tue, 3 Dec 2024 08:28:05 +0100 Subject: [PATCH] Make use of transition_priority() in active_elections --- nano/lib/stats_enums.hpp | 2 ++ nano/node/active_elections.cpp | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/nano/lib/stats_enums.hpp b/nano/lib/stats_enums.hpp index 2022b29083..c2fec6a159 100644 --- a/nano/lib/stats_enums.hpp +++ b/nano/lib/stats_enums.hpp @@ -426,6 +426,8 @@ enum class detail // active insert, insert_failed, + transition_priority, + transition_priority_failed, election_cleanup, // active_elections diff --git a/nano/node/active_elections.cpp b/nano/node/active_elections.cpp index bd29634bb2..9735ce1dae 100644 --- a/nano/node/active_elections.cpp +++ b/nano/node/active_elections.cpp @@ -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 ();