From a5bf4d76f6ef877a335a5f1359e2590efd64a67f Mon Sep 17 00:00:00 2001 From: gr0vity-dev Date: Mon, 2 Dec 2024 22:35:00 +0100 Subject: [PATCH] Add transition_priority method to election class --- nano/node/election.cpp | 19 +++++++++++++++++++ nano/node/election.hpp | 1 + 2 files changed, 20 insertions(+) diff --git a/nano/node/election.cpp b/nano/node/election.cpp index e0fd27800..fc3a33dc2 100644 --- a/nano/node/election.cpp +++ b/nano/node/election.cpp @@ -183,6 +183,25 @@ void nano::election::transition_active () state_change (nano::election_state::passive, nano::election_state::active); } +bool nano::election::transition_priority () +{ + nano::lock_guard guard{ mutex }; + + if (behavior_m == nano::election_behavior::priority || behavior_m == nano::election_behavior::manual) + { + return false; + } + + behavior_m = nano::election_behavior::priority; + last_vote = std::chrono::steady_clock::time_point{}; // allow new outgoing votes immediately + + node.logger.debug (nano::log::type::election, "Transitioned election behavior to priority from {} for root: {}", + to_string (behavior_m), + qualified_root.to_string ()); + + return true; +} + void nano::election::cancel () { nano::lock_guard guard{ mutex }; diff --git a/nano/node/election.hpp b/nano/node/election.hpp index 9a6850a38..1fe0ad189 100644 --- a/nano/node/election.hpp +++ b/nano/node/election.hpp @@ -87,6 +87,7 @@ private: // State management public: // State transitions bool transition_time (nano::confirmation_solicitor &); void transition_active (); + bool transition_priority (); void cancel (); public: // Status