Skip to content

Commit

Permalink
fix(kad): compute jobs_query_capacity accurately
Browse files Browse the repository at this point in the history
Fixes: #4191.

Pull-Request: #5148.
  • Loading branch information
junekhan authored Mar 27, 2024
1 parent a372723 commit 89c684a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions protocols/kad/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
- Make it mandatory to provide protocol names when creating a `kad::Config`.
Deprecate `kad::Config::default()`, replaced by `kad::Config::new(StreamProtocol)`.
See [PR 5122](https://github.com/libp2p/rust-libp2p/pull/5122).
- Compute `jobs_query_capacity` accurately.
See [PR 5148](https://github.com/libp2p/rust-libp2p/pull/5148).

## 0.45.3

Expand Down
4 changes: 2 additions & 2 deletions protocols/kad/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2502,14 +2502,14 @@ where
// Run the periodic provider announcement job.
if let Some(mut job) = self.add_provider_job.take() {
let num = usize::min(JOBS_MAX_NEW_QUERIES, jobs_query_capacity);
for _ in 0..num {
for i in 0..num {
if let Poll::Ready(r) = job.poll(cx, &mut self.store, now) {
self.start_add_provider(r.key, AddProviderContext::Republish)
} else {
jobs_query_capacity -= i;
break;
}
}
jobs_query_capacity -= num;
self.add_provider_job = Some(job);
}

Expand Down

0 comments on commit 89c684a

Please sign in to comment.