From 186babe0b0caa658facc0eb092642fcabc349b41 Mon Sep 17 00:00:00 2001 From: clemahieu Date: Mon, 10 May 2021 09:49:35 +0100 Subject: [PATCH] Fixing 3-cycle possible deadlock active_transactions -> election -> mdb_write_mutex. This was introduced with final votes and is alliviated by releasing the election mutex before issuing a final vote which requires the database write mutex. (#3269) --- nano/node/election.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/nano/node/election.cpp b/nano/node/election.cpp index 5dccaa86..97cce2c2 100644 --- a/nano/node/election.cpp +++ b/nano/node/election.cpp @@ -293,7 +293,10 @@ void nano::election::confirm_if_quorum (nano::unique_lock & lock_a) { if (node.ledger.cache.final_votes_confirmation_canary.load () && !is_quorum.exchange (true) && node.config.enable_voting && node.wallets.reps ().voting > 0) { - node.active.final_generator.add (root, status.winner->hash ()); + auto hash = status.winner->hash (); + lock_a.unlock (); + node.active.final_generator.add (root, hash); + lock_a.lock (); } if (!node.ledger.cache.final_votes_confirmation_canary.load () || final_weight >= node.online_reps.delta ()) { @@ -507,10 +510,13 @@ void nano::election::generate_votes () const { if (node.config.enable_voting && node.wallets.reps ().voting > 0) { - nano::lock_guard guard (mutex); + nano::unique_lock lock (mutex); if (confirmed () || have_quorum (tally_impl ())) { - node.active.final_generator.add (root, status.winner->hash ()); + auto hash = status.winner->hash (); + lock.unlock (); + node.active.final_generator.add (root, hash); + lock.lock (); } else {