diff --git a/nano/node/active_transactions.cpp b/nano/node/active_transactions.cpp index ef4a46bdb7..230d0bb73a 100644 --- a/nano/node/active_transactions.cpp +++ b/nano/node/active_transactions.cpp @@ -405,16 +405,6 @@ void nano::active_transactions::request_loop () } } -nano::election_insertion_result nano::active_transactions::insert (const std::shared_ptr & block, nano::election_behavior behavior) -{ - debug_assert (block != nullptr); - - nano::unique_lock lock{ mutex }; - - auto result = insert_impl (lock, block, behavior); - return result; -} - void nano::active_transactions::trim () { /* @@ -429,10 +419,10 @@ void nano::active_transactions::trim () } } -nano::election_insertion_result nano::active_transactions::insert_impl (nano::unique_lock & lock_a, std::shared_ptr const & block_a, nano::election_behavior election_behavior_a, std::function const &)> const & confirmation_action_a) +nano::election_insertion_result nano::active_transactions::insert (std::shared_ptr const & block_a, nano::election_behavior election_behavior_a) { - debug_assert (!mutex.try_lock ()); - debug_assert (lock_a.owns_lock ()); + nano::unique_lock lock{ mutex }; + debug_assert (block_a); debug_assert (block_a->has_sideband ()); nano::election_insertion_result result; if (!stopped) @@ -446,7 +436,7 @@ nano::election_insertion_result nano::active_transactions::insert_impl (nano::un result.inserted = true; auto hash (block_a->hash ()); result.election = nano::make_shared ( - node, block_a, confirmation_action_a, [&node = node] (auto const & rep_a) { + node, block_a, nullptr, [&node = node] (auto const & rep_a) { // Representative is defined as online if replying to live votes or rep_crawler queries node.online_reps.observe (rep_a); }, @@ -457,7 +447,7 @@ nano::election_insertion_result nano::active_transactions::insert_impl (nano::un debug_assert (count_by_behavior[result.election->behavior ()] >= 0); count_by_behavior[result.election->behavior ()]++; - lock_a.unlock (); + lock.unlock (); if (auto const cache = node.vote_cache.find (hash); cache) { cache->fill (result.election); @@ -465,7 +455,7 @@ nano::election_insertion_result nano::active_transactions::insert_impl (nano::un node.stats.inc (nano::stat::type::active_started, nano::to_stat_detail (election_behavior_a)); node.observers.active_started.notify (hash); vacancy_update (); - lock_a.lock (); + lock.lock (); } } else @@ -473,14 +463,14 @@ nano::election_insertion_result nano::active_transactions::insert_impl (nano::un result.election = existing->election; } - lock_a.unlock (); + lock.unlock (); // Votes are generated for inserted or ongoing elections if (result.election) { result.election->broadcast_vote (); } trim (); - lock_a.lock (); + lock.lock (); } return result; } diff --git a/nano/node/active_transactions.hpp b/nano/node/active_transactions.hpp index fa8f172da0..ac83c4efa8 100644 --- a/nano/node/active_transactions.hpp +++ b/nano/node/active_transactions.hpp @@ -139,7 +139,7 @@ class active_transactions final /** * Starts new election with a specified behavior type */ - nano::election_insertion_result insert (std::shared_ptr const & block, nano::election_behavior behavior = nano::election_behavior::normal); + nano::election_insertion_result insert (std::shared_ptr const &, nano::election_behavior = nano::election_behavior::normal); // Distinguishes replay votes, cannot be determined if the block is not in any election nano::vote_code vote (std::shared_ptr const &); // Is the root of this block in the roots container @@ -181,8 +181,6 @@ class active_transactions final private: // Erase elections if we're over capacity void trim (); - // Call action with confirmed block, may be different than what we started with - nano::election_insertion_result insert_impl (nano::unique_lock &, std::shared_ptr const &, nano::election_behavior = nano::election_behavior::normal, std::function const &)> const & = nullptr); void request_loop (); void request_confirm (nano::unique_lock &); void erase (nano::qualified_root const &);