Skip to content

Commit

Permalink
Early return if target rollback count reached
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Nov 28, 2024
1 parent 1c6594a commit 560f5e8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions nano/node/bounded_backlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ void nano::bounded_backlog::run ()
lock.unlock ();

stats.add (nano::stat::type::bounded_backlog, nano::stat::detail::gathered_targets, targets.size ());
auto processed = perform_rollbacks (targets);
auto processed = perform_rollbacks (targets, target_count);

lock.lock ();

Expand Down Expand Up @@ -285,7 +285,7 @@ bool nano::bounded_backlog::should_rollback (nano::block_hash const & hash) cons
return true;
}

std::deque<nano::block_hash> nano::bounded_backlog::perform_rollbacks (std::deque<nano::block_hash> const & targets)
std::deque<nano::block_hash> nano::bounded_backlog::perform_rollbacks (std::deque<nano::block_hash> const & targets, size_t max_rollbacks)
{
stats.inc (nano::stat::type::bounded_backlog, nano::stat::detail::performing_rollbacks);

Expand Down Expand Up @@ -320,6 +320,12 @@ std::deque<nano::block_hash> nano::bounded_backlog::perform_rollbacks (std::dequ
// TODO: Calling block_processor's event here is not ideal, but duplicating these events is even worse
block_processor.rolled_back.notify (rollback_list, root);
});

// Return early if we reached the maximum number of rollbacks
if (processed.size () >= max_rollbacks)
{
break;
}
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion nano/node/bounded_backlog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class bounded_backlog
std::deque<nano::block_hash> gather_targets (size_t max_count) const;
bool should_rollback (nano::block_hash const &) const;

std::deque<nano::block_hash> perform_rollbacks (std::deque<nano::block_hash> const & targets);
std::deque<nano::block_hash> perform_rollbacks (std::deque<nano::block_hash> const & targets, size_t max_rollbacks);

void run_scan ();

Expand Down

0 comments on commit 560f5e8

Please sign in to comment.