From 8729fd8c45e3b6df6a9d443b558a7f0ee935a915 Mon Sep 17 00:00:00 2001 From: Ruben De Smet Date: Fri, 9 Jul 2021 12:29:04 +0200 Subject: [PATCH] Return the correct number of remaining bootstrap requests. Fixes #2121 Co-authored-by: Max Inden Co-authored-by: @izolyomi --- protocols/kad/CHANGELOG.md | 3 +++ protocols/kad/src/behaviour.rs | 2 +- protocols/kad/src/behaviour/test.rs | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/protocols/kad/CHANGELOG.md b/protocols/kad/CHANGELOG.md index db0b9f0de5c..18c03d53faf 100644 --- a/protocols/kad/CHANGELOG.md +++ b/protocols/kad/CHANGELOG.md @@ -13,8 +13,11 @@ - Remove false `debug_assert` on `connected_peers` (see [PR 2120]). +- Return correct number of remaining bootstrap requests (see [PR 2125]). + [PR 2087]: https://github.com/libp2p/rust-libp2p/pull/2087 [PR 2120]: https://github.com/libp2p/rust-libp2p/pull/2120 +[PR 2125]: https://github.com/libp2p/rust-libp2p/pull/2125 # 0.30.0 [2021-04-13] diff --git a/protocols/kad/src/behaviour.rs b/protocols/kad/src/behaviour.rs index 6d01950ae9f..b0a2f3ee8db 100644 --- a/protocols/kad/src/behaviour.rs +++ b/protocols/kad/src/behaviour.rs @@ -1113,7 +1113,7 @@ where }).collect::>().into_iter() }); - let num_remaining = remaining.len().saturating_sub(1) as u32; + let num_remaining = remaining.len() as u32; if let Some(target) = remaining.next() { let info = QueryInfo::Bootstrap { diff --git a/protocols/kad/src/behaviour/test.rs b/protocols/kad/src/behaviour/test.rs index 7f73c1d84d3..f22b4b65a7d 100644 --- a/protocols/kad/src/behaviour/test.rs +++ b/protocols/kad/src/behaviour/test.rs @@ -196,6 +196,10 @@ fn bootstrap() { } first = false; if ok.num_remaining == 0 { + assert_eq!( + swarm.behaviour_mut().queries.size(), 0, + "Expect no remaining queries when `num_remaining` is zero.", + ); let mut known = HashSet::new(); for b in swarm.behaviour_mut().kbuckets.iter() { for e in b.iter() {