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

litep2p/peerset: Do not disconnect all peers on SetReservedPeers command #6016

Merged
merged 30 commits into from
Nov 6, 2024

Conversation

lexnv
Copy link
Contributor

@lexnv lexnv commented Oct 10, 2024

Previously, when receiving the SetReservedPeers { reserved } all peers not in the reserved set were removed.

This is incorrect, the intention of SetReservedPeers is to change the active set of reserved peers and disconnect previously reserved peers not in the new set.

While at it, have added a few other improvements to make the peerset more robust:

  • SetReservedPeers: does not disconnect all peers
  • SetReservedPeers: if a reserved peer is no longer reserved, the peerset tries to move the peers to the regular set if the slots allow this move. This ensures the (now regular) peer counts towards slot allocation.
  • every 1 seconds: If we don't have enough connect peers, add the reserved peers to the list that the peerstore ignores. Reserved peers are already connected and the peerstore might return otherwise a reserved peer

Next Steps

  • More testing

cc @paritytech/networking

@lexnv lexnv added T0-node This PR/Issue is related to the topic “node”. I5-enhancement An additional feature request. labels Oct 10, 2024
@lexnv lexnv self-assigned this Oct 10, 2024
Copy link
Contributor

@dmitry-markin dmitry-markin left a comment

Choose a reason for hiding this comment

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

Looks good!

prdoc/pr_6016.prdoc Outdated Show resolved Hide resolved
Copy link
Contributor

@michalkucharczyk michalkucharczyk left a comment

Choose a reason for hiding this comment

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

Not really my domain, made review for learning purposes. From what I can say looks good. Left some nitpicks.

Comment on lines 1002 to 1005
match direction {
Direction::Inbound(_) => self.num_in >= self.max_in,
Direction::Outbound(_) => self.num_out >= self.max_out,
};
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: some of the blocks seems to be duplicated - maybe moving them to small functions would be better.

The same with increasing out/inbound count.

Not sure however if this would increase readability.

Copy link
Member

Choose a reason for hiding this comment

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

This piece of code was replicated three times. Could be moved into one function that takes a disconnect_state and a keep_state.

match peerset.next().await {
Some(PeersetNotificationCommand::CloseSubstream { peers }) => {
// This ensures we don't disconnect peers when receiving `SetReservedPeers`.
assert_eq!(peers.len(), 2);
Copy link
Contributor

Choose a reason for hiding this comment

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

would it make sense to check if common_perr is not in the peers?

event => panic!("invalid event: {event:?}"),
}

// verify all three peers are counted as outbound peers and they don't count towards
Copy link
Contributor

Choose a reason for hiding this comment

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

dumb question: is outbound peer term used as an equivalent of reserved peer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that was a mistake, thanks for pointing that out 🙏

Comment on lines 1002 to 1005
match direction {
Direction::Inbound(_) => self.num_in >= self.max_in,
Direction::Outbound(_) => self.num_out >= self.max_out,
};
Copy link
Member

Choose a reason for hiding this comment

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

This piece of code was replicated three times. Could be moved into one function that takes a disconnect_state and a keep_state.

@lexnv lexnv added this pull request to the merge queue Nov 6, 2024
Merged via the queue into master with commit ccb2a88 Nov 6, 2024
195 of 196 checks passed
@lexnv lexnv deleted the lexnv/litep2p-peerset branch November 6, 2024 10:48
lexnv added a commit that referenced this pull request Nov 15, 2024
…mmand (#6016)

Previously, when receiving the `SetReservedPeers { reserved }` all peers
not in the `reserved` set were removed.

This is incorrect, the intention of `SetReservedPeers` is to change the
active set of reserved peers and disconnect previously reserved peers
not in the new set.

While at it, have added a few other improvements to make the peerset
more robust:
- `SetReservedPeers`: does not disconnect all peers
- `SetReservedPeers`: if a reserved peer is no longer reserved, the
peerset tries to move the peers to the regular set if the slots allow
this move. This ensures the (now regular) peer counts towards slot
allocation.
- every 1 seconds: If we don't have enough connect peers, add the
reserved peers to the list that the peerstore ignores. Reserved peers
are already connected and the peerstore might return otherwise a
reserved peer


### Next Steps

- [x] More testing

cc @paritytech/networking

---------

Signed-off-by: Alexandru Vasile <[email protected]>
Co-authored-by: Dmitry Markin <[email protected]>
Co-authored-by: Michal Kucharczyk <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I5-enhancement An additional feature request. T0-node This PR/Issue is related to the topic “node”.
Projects
Status: Blocked ⛔️
Development

Successfully merging this pull request may close these issues.

4 participants