Election locks fix

This commit is contained in:
Piotr Wójcik 2024-01-23 00:30:39 +01:00
commit 7ac49e8ffd
2 changed files with 9 additions and 9 deletions

View file

@ -165,16 +165,16 @@ void nano::election::transition_active ()
state_change (nano::election::state_t::passive, nano::election::state_t::active);
}
bool nano::election::confirmed_locked (nano::unique_lock<nano::mutex> & lock) const
bool nano::election::confirmed_locked () const
{
debug_assert (lock.owns_lock ());
debug_assert (!mutex.try_lock ());
return state_m == nano::election::state_t::confirmed || state_m == nano::election::state_t::expired_confirmed;
}
bool nano::election::confirmed () const
{
nano::unique_lock<nano::mutex> lock{ mutex };
return confirmed_locked (lock);
return confirmed_locked ();
}
bool nano::election::failed () const
@ -245,7 +245,7 @@ bool nano::election::transition_time (nano::confirmation_solicitor & solicitor_a
break;
}
if (!confirmed_locked (lock) && time_to_live () < std::chrono::steady_clock::now () - election_start)
if (!confirmed_locked () && time_to_live () < std::chrono::steady_clock::now () - election_start)
{
// It is possible the election confirmed while acquiring the mutex
// state_change returning true would indicate it
@ -383,7 +383,7 @@ boost::optional<nano::election_status_type> nano::election::try_confirm (nano::b
if (winner && winner->hash () == hash)
{
// Determine if the block was confirmed explicitly via election confirmation or implicitly via confirmation height
if (!confirmed_locked (election_lock))
if (!confirmed_locked ())
{
confirm_once (election_lock, nano::election_status_type::active_confirmation_height);
status_type = nano::election_status_type::active_confirmation_height;
@ -466,7 +466,7 @@ nano::election_vote_result nano::election::vote (nano::account const & rep, uint
node.stats.inc (nano::stat::type::election, vote_source_a == vote_source::live ? nano::stat::detail::vote_new : nano::stat::detail::vote_cached);
if (!confirmed_locked (lock))
if (!confirmed_locked ())
{
confirm_if_quorum (lock);
}
@ -478,7 +478,7 @@ bool nano::election::publish (std::shared_ptr<nano::block> const & block_a)
nano::unique_lock<nano::mutex> lock{ mutex };
// Do not insert new blocks if already confirmed
auto result (confirmed_locked (lock));
auto result (confirmed_locked ());
if (!result && last_blocks.size () >= max_blocks && last_blocks.find (block_a->hash ()) == last_blocks.end ())
{
if (!replace_by_weight (lock, block_a->hash ()))
@ -544,7 +544,7 @@ void nano::election::broadcast_vote_locked (nano::unique_lock<nano::mutex> & loc
{
node.stats.inc (nano::stat::type::election, nano::stat::detail::generate_vote);
if (confirmed_locked (lock) || have_quorum (tally_impl ()))
if (confirmed_locked () || have_quorum (tally_impl ()))
{
node.stats.inc (nano::stat::type::election, nano::stat::detail::generate_vote_final);
node.final_generator.add (root, status.winner->hash ()); // Broadcasts vote to the network

View file

@ -168,7 +168,7 @@ public: // Information
private:
nano::tally_t tally_impl () const;
bool confirmed_locked (nano::unique_lock<nano::mutex> & lock) const;
bool confirmed_locked () const;
// lock_a does not own the mutex on return
void confirm_once (nano::unique_lock<nano::mutex> & lock_a, nano::election_status_type = nano::election_status_type::active_confirmed_quorum);
void broadcast_block (nano::confirmation_solicitor &);