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

P2P: Change ClientPool to PeerSet #337

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

P2P: Change ClientPool to PeerSet #337

wants to merge 12 commits into from

Conversation

Boog900
Copy link
Member

@Boog900 Boog900 commented Nov 3, 2024

What

Changes the ClientPool, a DashMap of unused connected peers to the PeerSet, a service containing all connected peers.

Why

We need access to all connected peers for certain RPC requests + it's just clearer to have all connected peers in one place.

How

A new type WeakClient was created so we can still give out handles from the PeerSet

@github-actions github-actions bot added A-p2p Related to P2P. A-dependency Related to dependencies, or changes to a Cargo.{toml,lock} file. A-workspace Changes to a root workspace file or general repo file. labels Nov 3, 2024
@github-actions github-actions bot added the A-binaries Related to binaries. label Nov 4, 2024
p2p/p2p-core/src/client/weak.rs Show resolved Hide resolved
p2p/p2p/src/peer_set.rs Show resolved Hide resolved
p2p/p2p/src/peer_set/client_wrappers.rs Show resolved Hide resolved
@Boog900 Boog900 marked this pull request as ready for review November 5, 2024 19:59
p2p/p2p/src/lib.rs Outdated Show resolved Hide resolved
pub use client_wrappers::ClientDropGuard;
use client_wrappers::StoredClient;

/// A request to the peer-set.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// A request to the peer-set.
/// A request to the [`PeerSet`].

Copy link
Contributor

Choose a reason for hiding this comment

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

Nvm it's not in scope.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nvm nvm, it's defined in the same file. Same for PeerSetResponse btw.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's in scope but it's private

Comment on lines +29 to +35
/// Peers with more cumulative difficulty than the given cumulative difficulty.
///
/// Returned peers will be remembered and won't be returned from subsequent calls until the guard is dropped.
PeersWithMorePoW(u128),
/// A random outbound peer.
///
/// The returned peer will be remembered and won't be returned from subsequent calls until the guard is dropped.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the returned ... docs could be moved to the response variants.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added them on both to make sure these docs are seen.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay but these are now duplicated and can get out of sync.

Reasoning for comment on the response is that the return type is next to it. Other crates are like this, consensus, address-book, blockchain, txpool, etc.

p2p/p2p/src/peer_set.rs Outdated Show resolved Hide resolved
p2p/p2p/src/peer_set.rs Outdated Show resolved Hide resolved
p2p/p2p/src/peer_set.rs Outdated Show resolved Hide resolved
p2p/p2p/src/peer_set.rs Outdated Show resolved Hide resolved
Comment on lines +58 to +61
config
.max_inbound_connections
.checked_add(config.outbound_connections)
.unwrap(),
Copy link
Contributor

Choose a reason for hiding this comment

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

This is small but I think overflows in these types of cases usually saturate in most programs instead of crashing for UX reasons (better to saturate on already unrealistic and irrelevantly large number over crashing on said irrelevant number).

User input causing overflow is unrealistic yet possible if someone does this in the CLI/config:

max_inbound_connections = 99999999999999999999

which I could imagine at least a few people doing. I think cuprated continuing with MAX over crashing would be expected, or... monerod catches large input during CLI/config in stuff like --out-peers, --limit-rate, etc.

$ ./monerod --out-peers 18446744073709551615
Failed to parse arguments: the argument ('18446744073709551615') for option '--out-peers' is invalid

If we're either saturating or early returning during CLI, these unwraps can be removed.

Comment on lines +29 to +35
/// Peers with more cumulative difficulty than the given cumulative difficulty.
///
/// Returned peers will be remembered and won't be returned from subsequent calls until the guard is dropped.
PeersWithMorePoW(u128),
/// A random outbound peer.
///
/// The returned peer will be remembered and won't be returned from subsequent calls until the guard is dropped.
Copy link
Contributor

Choose a reason for hiding this comment

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

Okay but these are now duplicated and can get out of sync.

Reasoning for comment on the response is that the return type is next to it. Other crates are like this, consensus, address-book, blockchain, txpool, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-binaries Related to binaries. A-dependency Related to dependencies, or changes to a Cargo.{toml,lock} file. A-p2p Related to P2P. A-workspace Changes to a root workspace file or general repo file.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants