From 33cd2bfae0311f1bdaca917cc0b9e19cbc94c746 Mon Sep 17 00:00:00 2001 From: gr0vity Date: Wed, 4 Dec 2024 11:00:41 +0100 Subject: [PATCH] erase election immediately on confirmation We need to keep teh current cleanup loop, because elctions can timeout / be cancelled / ... --- nano/node/active_elections.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/nano/node/active_elections.cpp b/nano/node/active_elections.cpp index bd29634bb2..c30615863f 100644 --- a/nano/node/active_elections.cpp +++ b/nano/node/active_elections.cpp @@ -408,7 +408,11 @@ nano::election_insertion_result nano::active_elections::insert (std::shared_ptr< // Representative is defined as online if replying to live votes or rep_crawler queries node.online_reps.observe (rep_a); }; - result.election = nano::make_shared (node, block_a, nullptr, observe_rep_cb, election_behavior_a); + auto confirmation_action_l = [this, root = root] (std::shared_ptr const & winner_a) { + // Immediately erase the election when confirmed + erase (root); + }; + result.election = nano::make_shared (node, block_a, confirmation_action_l, observe_rep_cb, election_behavior_a); roots.get ().emplace (entry{ root, result.election, std::move (erased_callback_a) }); node.vote_router.connect (hash, result.election);