Skip to content

Commit

Permalink
Return early, if stopped, to remove a large level of indentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
dsiganos committed Jan 12, 2024
1 parent 0406a33 commit 35cee07
Showing 1 changed file with 41 additions and 40 deletions.
81 changes: 41 additions & 40 deletions nano/node/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,53 +425,54 @@ nano::election_insertion_result nano::active_transactions::insert (std::shared_p
debug_assert (block_a);
debug_assert (block_a->has_sideband ());
nano::election_insertion_result result;
if (!stopped)

if (stopped)
return result;

auto root (block_a->qualified_root ());
auto existing (roots.get<tag_root> ().find (root));
if (existing == roots.get<tag_root> ().end ())
{
auto root (block_a->qualified_root ());
auto existing (roots.get<tag_root> ().find (root));
if (existing == roots.get<tag_root> ().end ())
if (!recently_confirmed.exists (root))
{
if (!recently_confirmed.exists (root))
result.inserted = true;
auto hash (block_a->hash ());
result.election = nano::make_shared<nano::election> (
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);
},
election_behavior_a);
roots.get<tag_root> ().emplace (nano::active_transactions::conflict_info{ root, result.election });
blocks.emplace (hash, result.election);
// Keep track of election count by election type
debug_assert (count_by_behavior[result.election->behavior ()] >= 0);
count_by_behavior[result.election->behavior ()]++;

lock.unlock ();
if (auto const cache = node.vote_cache.find (hash); cache)
{
result.inserted = true;
auto hash (block_a->hash ());
result.election = nano::make_shared<nano::election> (
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);
},
election_behavior_a);
roots.get<tag_root> ().emplace (nano::active_transactions::conflict_info{ root, result.election });
blocks.emplace (hash, result.election);
// Keep track of election count by election type
debug_assert (count_by_behavior[result.election->behavior ()] >= 0);
count_by_behavior[result.election->behavior ()]++;

lock.unlock ();
if (auto const cache = node.vote_cache.find (hash); cache)
{
cache->fill (result.election);
}
node.stats.inc (nano::stat::type::active_started, nano::to_stat_detail (election_behavior_a));
node.observers.active_started.notify (hash);
vacancy_update ();
lock.lock ();
cache->fill (result.election);
}
node.stats.inc (nano::stat::type::active_started, nano::to_stat_detail (election_behavior_a));
node.observers.active_started.notify (hash);
vacancy_update ();
lock.lock ();
}
else
{
result.election = existing->election;
}
}
else
{
result.election = existing->election;
}

lock.unlock ();
// Votes are generated for inserted or ongoing elections
if (result.election)
{
result.election->broadcast_vote ();
}
trim ();
lock.lock ();
lock.unlock ();
// Votes are generated for inserted or ongoing elections
if (result.election)
{
result.election->broadcast_vote ();
}
trim ();
lock.lock ();
return result;
}

Expand Down

0 comments on commit 35cee07

Please sign in to comment.