Skip to content

Commit

Permalink
Fixing 3-cycle possible deadlock active_transactions -> election -> m…
Browse files Browse the repository at this point in the history
…db_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. (nanocurrency#3269)
  • Loading branch information
clemahieu authored May 10, 2021
1 parent 69f7f52 commit 186babe
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions nano/node/election.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,10 @@ void nano::election::confirm_if_quorum (nano::unique_lock<nano::mutex> & 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 ())
{
Expand Down Expand Up @@ -507,10 +510,13 @@ void nano::election::generate_votes () const
{
if (node.config.enable_voting && node.wallets.reps ().voting > 0)
{
nano::lock_guard<nano::mutex> guard (mutex);
nano::unique_lock<nano::mutex> 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
{
Expand Down

0 comments on commit 186babe

Please sign in to comment.