diff --git a/nano/node/active_elections.cpp b/nano/node/active_elections.cpp index bd29634bb2..7564be2cd4 100644 --- a/nano/node/active_elections.cpp +++ b/nano/node/active_elections.cpp @@ -435,6 +435,19 @@ 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 && result.election->behavior () != nano::election_behavior::priority) + { + count_by_behavior[result.election->behavior ()]--; + count_by_behavior[election_behavior_a]++; + result.election->transition_priority (); + + node.logger.debug (nano::log::type::active_elections, "Upgraded election behavior from {} to priority for block: {}", + to_string (previous_behavior), + hash.to_string ()); + } } lock.unlock (); diff --git a/nano/node/election.cpp b/nano/node/election.cpp index ee64237059..7034581e11 100644 --- a/nano/node/election.cpp +++ b/nano/node/election.cpp @@ -183,6 +183,13 @@ void nano::election::transition_active () state_change (nano::election_state::passive, nano::election_state::active); } +void nano::election::transition_priority () +{ + nano::lock_guard guard{ mutex }; + behavior_m = nano::election_behavior::priority; + last_vote = std::chrono::steady_clock::time_point{}; // allow new outgoing votes immediately +} + void nano::election::cancel () { nano::lock_guard guard{ mutex }; @@ -849,4 +856,4 @@ std::string_view nano::to_string (nano::election_state state) nano::stat::detail nano::to_stat_detail (nano::election_state state) { return nano::enum_util::cast (state); -} +} \ No newline at end of file diff --git a/nano/node/election.hpp b/nano/node/election.hpp index 718cbf680c..7e1d7c91d4 100644 --- a/nano/node/election.hpp +++ b/nano/node/election.hpp @@ -87,6 +87,7 @@ class election final : public std::enable_shared_from_this public: // State transitions bool transition_time (nano::confirmation_solicitor &); void transition_active (); + void transition_priority (); void cancel (); public: // Status @@ -180,7 +181,7 @@ class election final : public std::enable_shared_from_this mutable nano::uint128_t final_weight{ 0 }; mutable std::unordered_map last_tally; - nano::election_behavior const behavior_m; + nano::election_behavior behavior_m; std::chrono::steady_clock::time_point const election_start{ std::chrono::steady_clock::now () }; mutable nano::mutex mutex;