Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NetRpcImpl::get_peers return Remoteaddress.addresses dedup #4795

Merged
merged 1 commit into from
Jan 24, 2025

Conversation

eval-exec
Copy link
Collaborator

@eval-exec eval-exec commented Jan 22, 2025

What is changed and how it works?

get_peers RPC returned RemoteAddress.addresses shouldn't contains duplicate MultiAddr.

Related changes

  • In NetRpcImpl::get_peers, use HashSet to remove duplicate MultiAddr.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code ci-runs-only: [ quick_checks,linters ]

Side effects

  • None

Release note

Title Only: Include only the PR title in the release note.

@eval-exec eval-exec requested a review from a team as a code owner January 22, 2025 16:19
@eval-exec eval-exec requested review from doitian and driftluo and removed request for a team January 22, 2025 16:19
@eval-exec eval-exec added b:rpc Break RPC interface m:network labels Jan 23, 2025
@@ -586,7 +587,7 @@ impl NetRpc for NetRpcImpl {
.connected_peers()
.iter()
.map(|(peer_index, peer)| {
let mut addresses = vec![&peer.connected_addr];
let mut addresses: HashSet<_> = vec![&peer.connected_addr].into_iter().collect();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to create vec and convert to hashet, we may use the iterator to collect directly:

let addresses: HashSet<_> = std::iter::once(peer.connected_addr).chain(peer.listened_addrs.iter()).collect();

@eval-exec eval-exec marked this pull request as draft January 24, 2025 01:45
@eval-exec eval-exec force-pushed the exec/get-peers-dedup branch from dc8b4ec to 9508269 Compare January 24, 2025 01:52
@eval-exec eval-exec marked this pull request as ready for review January 24, 2025 01:52
@eval-exec eval-exec requested a review from quake January 24, 2025 01:52
@quake quake added this pull request to the merge queue Jan 24, 2025
Merged via the queue into nervosnetwork:develop with commit 05aa7b6 Jan 24, 2025
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
b:rpc Break RPC interface m:network
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants