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

[Feature] feat: allow-external-peers #3163

Merged
merged 10 commits into from
Mar 18, 2024

Conversation

joske
Copy link
Contributor

@joske joske commented Mar 6, 2024

@ljedrz
Copy link
Collaborator

ljedrz commented Mar 6, 2024

Ok, so if nogossip is set, the node will not be requesting more peers; shouldn't this also mean that the node doesn't "shuffle" its peers, so that it doesn't lose them?

@joske
Copy link
Contributor Author

joske commented Mar 6, 2024

@vicsn ?

@vicsn
Copy link
Contributor

vicsn commented Mar 6, 2024

shouldn't this also mean that the node doesn't "shuffle" its peers, so that it doesn't lose them?

Yes, I did not have this logic in mind. @joske can you analyse and update the PR? Depending on the scope of required changes, we may also need to rename the flag to make it sound appropriate.

Can you also test the behavior manually? One suggested approach: start a network of e.g. 10 validators each having the new flag and the same 10 hardcoded client peers, and after half an hour you can check if all validators still have all client peers connected. Feel free to suggest another approach. Soon™️ this will be an automated integration test in CI, but that will take a few weeks still. :)

@joske joske changed the title feat: nopeergossip feat: peergossip Mar 7, 2024
@joske joske force-pushed the feat/nopeergossip branch 2 times, most recently from 514bb7e to f8274d2 Compare March 7, 2024 09:32
@joske joske marked this pull request as ready for review March 7, 2024 12:53
@howardwu howardwu closed this Mar 7, 2024
@joske joske reopened this Mar 7, 2024
@vicsn vicsn changed the title feat: peergossip feat: allow-outside-peers Mar 7, 2024
@vicsn vicsn self-requested a review March 7, 2024 19:29
Copy link
Contributor

@vicsn vicsn left a comment

Choose a reason for hiding this comment

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

For clarity, can you share with how many validators and clients you tested?

I just tested using the devnet.sh script, without the --allow-outside-peers flag, and the clients still connect, is that expected behaviour? Or is there extra code we need so we can easily test in devnet.sh if this feature works?

Can you also confirm this is not an issue? https://github.com/AleoHQ/snarkOS/pull/3163#issuecomment-1980505760

cli/src/commands/start.rs Outdated Show resolved Hide resolved
@joske joske force-pushed the feat/nopeergossip branch 2 times, most recently from db5a291 to 2485f0a Compare March 8, 2024 09:11
Copy link
Contributor

@vicsn vicsn left a comment

Choose a reason for hiding this comment

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

Logic mostly LGTM.

Test duplicate_disconnect_attempts is failing, I assume because we set the new flag to false when the test expects it to be true.

Can you add the new flag to the validators in the devnet.sh and .devnet/start.sh scripts?

@howardwu
Copy link
Contributor

howardwu commented Mar 9, 2024

I would advocate for allow-external-peers or no-external-peers (preferred) as the default flag

@vicsn
Copy link
Contributor

vicsn commented Mar 9, 2024

I would advocate for allow-external-peers or no-external-peers (preferred) as the default flag

This PR ensures default behaviour WITHOUT flag is to NOT connect with peers. Therefore calling the flag --allow-external-peers sounds good to me, --no-external-peers is confusing.

@howardwu
Copy link
Contributor

--allow-external-peers works for me. This means the default behavior is to not allow external peers.

@joske can you update this PR to reflect this change?

@joske
Copy link
Contributor Author

joske commented Mar 10, 2024

Yes, was waiting for confirmation on the final name :)

@howardwu
Copy link
Contributor

Yes, was waiting for confirmation on the final name :)

Please see above: --allow-external-peers is confirmed

@joske joske changed the title feat: allow-outside-peers feat: allow-external-peers Mar 11, 2024
.devnet/start.sh Outdated Show resolved Hide resolved
devnet.sh Outdated Show resolved Hide resolved
devnet.sh Outdated Show resolved Hide resolved
@@ -117,6 +117,7 @@ impl<N: Network, C: ConsensusStorage<N>> Client<N, C> {
trusted_peers,
Self::MAXIMUM_NUMBER_OF_PEERS as u16,
matches!(storage_mode, StorageMode::Development(_)),
false,
Copy link
Contributor

Choose a reason for hiding this comment

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

I should have spotted this sooner, but this is a bug. I think this should be true, and we should set it true for all the other invocations of Router::new as well, except for the validator where its set by a parameter. Because clients/provers are expected to always do peer discovery.

@@ -110,6 +110,7 @@ impl<N: Network, C: ConsensusStorage<N>> Prover<N, C> {
trusted_peers,
Self::MAXIMUM_NUMBER_OF_PEERS as u16,
matches!(storage_mode, StorageMode::Development(_)),
false,
Copy link
Contributor

@raychu86 raychu86 Mar 14, 2024

Choose a reason for hiding this comment

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

https://github.com/AleoHQ/snarkOS/pull/3163/files#r1525287483

@vicsn Should this be true as well according to your comment above?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes

@howardwu
Copy link
Contributor

@joske can you update all instances of false to true? This includes the tests.

@@ -264,6 +264,12 @@ impl<N: Network> Router<N> {
if self.is_connected(&peer_ip) {
bail!("Dropping connection request from '{peer_ip}' (already connected)")
}
// Only allow trusted peers to connect if we are a validator
// (unless allow_external_peers is set)
let is_validator = self.node_type().is_validator();
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: is_validator is no longer necessary as part of the check (because allow_external_peers takes precedence)

@@ -107,6 +107,12 @@ pub trait Heartbeat<N: Network>: Outbound<N> {
return;
}

let is_validator = self.router().node_type().is_validator();
// Skip if the node is not requesting peers.
if is_validator && !self.router().allow_external_peers() {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: is_validator is no longer necessary as part of the check (because allow_external_peers takes precedence)

for peer_ip in self.router().connected_peers().into_iter().choose_multiple(rng, 3) {
self.send(peer_ip, Message::PeerRequest(PeerRequest));
let is_validator = self.router().node_type().is_validator();
if !is_validator || self.router().allow_external_peers() {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: is_validator is no longer necessary as part of the check (because allow_external_peers takes precedence)

@@ -125,6 +125,9 @@ pub trait Inbound<N: Network>: Reading + Outbound<N> {
if !self.router().cache.contains_outbound_peer_request(peer_ip) {
bail!("Peer '{peer_ip}' is not following the protocol (unexpected peer response)")
}
if self.router().node_type().is_validator() && !self.router().allow_external_peers() {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: is_validator is no longer necessary as part of the check (because allow_external_peers takes precedence)

Comment on lines 151 to 152
#[clap(long = "allow-external-peers")]
/// If the flag is set, the validator will allow untrusted peers to connect
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
#[clap(long = "allow-external-peers")]
/// If the flag is set, the validator will allow untrusted peers to connect
/// If the flag is set, the validator will allow untrusted peers to connect
#[clap(long = "allow-external-peers")]

@raychu86 raychu86 merged commit 1e3eee6 into AleoNet:mainnet-staging Mar 18, 2024
23 of 24 checks passed
@howardwu howardwu changed the title feat: allow-external-peers [Feature] feat: allow-external-peers Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants