-
Notifications
You must be signed in to change notification settings - Fork 772
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
Conversation
`calculate_slot_adjustment` Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
reserved Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
substrate/client/network/src/litep2p/shim/notification/peerset.rs
Outdated
Show resolved
Hide resolved
substrate/client/network/src/litep2p/shim/notification/peerset.rs
Outdated
Show resolved
Hide resolved
Co-authored-by: Dmitry Markin <[email protected]>
Co-authored-by: Dmitry Markin <[email protected]>
Co-authored-by: Dmitry Markin <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
There was a problem hiding this 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.
substrate/client/network/src/litep2p/shim/notification/peerset.rs
Outdated
Show resolved
Hide resolved
match direction { | ||
Direction::Inbound(_) => self.num_in >= self.max_in, | ||
Direction::Outbound(_) => self.num_out >= self.max_out, | ||
}; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 🙏
match direction { | ||
Direction::Inbound(_) => self.num_in >= self.max_in, | ||
Direction::Outbound(_) => self.num_out >= self.max_out, | ||
}; |
There was a problem hiding this comment.
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
.
Co-authored-by: Michal Kucharczyk <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
…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]>
Previously, when receiving the
SetReservedPeers { reserved }
all peers not in thereserved
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 peersSetReservedPeers
: 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.Next Steps
cc @paritytech/networking