Skip to content

Commit

Permalink
Throttled removal of rep crawler targets (#3154)
Browse files Browse the repository at this point in the history
* Throttled removal of rep crawler targets

* Remove recursion
  • Loading branch information
clemahieu committed Mar 17, 2021
1 parent 6a58835 commit 033ad7d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
21 changes: 20 additions & 1 deletion nano/node/repcrawler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ void nano::rep_crawler::query (std::vector<std::shared_ptr<nano::transport::chan
node.alarm.add (std::chrono::steady_clock::now () + std::chrono::seconds (5), [node_w, hash]() {
if (auto node_l = node_w.lock ())
{
node_l->rep_crawler.remove (hash);
auto target_finished_processed (node_l->vote_processor.total_processed + node_l->vote_processor.size ());
node_l->rep_crawler.throttled_remove (hash, target_finished_processed);
}
});
}
Expand All @@ -172,6 +173,24 @@ void nano::rep_crawler::query (std::shared_ptr<nano::transport::channel> const &
query (peers);
}

void nano::rep_crawler::throttled_remove (nano::block_hash const & hash_a, uint64_t const target_finished_processed)
{
if (node.vote_processor.total_processed >= target_finished_processed)
{
remove (hash_a);
}
else
{
std::weak_ptr<nano::node> node_w (node.shared ());
node.alarm.add (std::chrono::steady_clock::now () + std::chrono::seconds (5), [node_w, hash_a, target_finished_processed]() {
if (auto node_l = node_w.lock ())
{
node_l->rep_crawler.throttled_remove (hash_a, target_finished_processed);
}
});
}
}

bool nano::rep_crawler::is_pr (nano::transport::channel const & channel_a) const
{
nano::lock_guard<std::mutex> lock (probable_reps_mutex);
Expand Down
3 changes: 3 additions & 0 deletions nano/node/repcrawler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ class rep_crawler final
/** Remove block hash from list of active rep queries */
void remove (nano::block_hash const &);

/** Remove block hash from with delay depending on vote processor size */
void throttled_remove (nano::block_hash const &, uint64_t const);

/** Attempt to determine if the peer manages one or more representative accounts */
void query (std::vector<std::shared_ptr<nano::transport::channel>> const & channels_a);

Expand Down
1 change: 1 addition & 0 deletions nano/node/vote_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ void nano::vote_processor::process_loop ()

lock.unlock ();
condition.notify_all ();
total_processed += votes_l.size ();
lock.lock ();

if (log_this_iteration && elapsed.stop () > std::chrono::milliseconds (100))
Expand Down
1 change: 1 addition & 0 deletions nano/node/vote_processor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class vote_processor final
bool half_full ();
void calculate_weights ();
void stop ();
std::atomic<uint64_t> total_processed{ 0 };

private:
void process_loop ();
Expand Down

0 comments on commit 033ad7d

Please sign in to comment.