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

Fixed bug with disconnection and max_non_reserved_peers #974

Merged
merged 1 commit into from
Feb 3, 2023

Conversation

xgreenx
Copy link
Collaborator

@xgreenx xgreenx commented Feb 2, 2023

Closes #967

@xgreenx xgreenx added bug Something isn't working fuel-p2p labels Feb 2, 2023
@xgreenx xgreenx requested review from leviathanbeak and a team February 2, 2023 16:26
@xgreenx xgreenx self-assigned this Feb 2, 2023
// disconnect the surplus peer
let _ = self.swarm.disconnect_peer_id(peer_to_disconnect);
// reconnect the reserved peer
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We already have a health timer that connects to disconnected reserved peers. We don't need to duplicate this work here=)

if other_established == 0 {
// this is the first connection to a given Peer
self.peer_manager.handle_initial_connection(peer_id);
}

let addresses = self.addresses_of_peer(&peer_id);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

First, we need to insert the peer into the table in the handle_initial_connection, and after we can add peer addresses=)

// Too many peers already connected, disconnect the Peer
self.pending_events.push_back(PeerInfoEvent::TooManyPeers {
// Too many peers already connected, disconnect the Peer with the first priority.
self.pending_events.push_front(PeerInfoEvent::TooManyPeers {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think we need to disconnect from peers in the first place. Otherwise, we will have a pending task that will receive incoming messages that we plan to drop.

@@ -645,28 +636,33 @@ impl PeerManager {
fn handle_peer_disconnect(&mut self, peer_id: PeerId) {
// try immediate reconnect if it's a reserved peer
let is_reserved = self.reserved_peers.contains(&peer_id);
let is_removed;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In the handle_initial_connection we don't connect to the peer -> it absents in our self.non_reserved_connected_peers map.

We had a bug here that we will allow_new_peers even if the peer was not connected -> we allowed new connections when we had max_non_reserved_peers.

@xgreenx xgreenx changed the title Fixed the small bug with disconnection Fixed bug with disconnection Feb 2, 2023
@xgreenx xgreenx changed the title Fixed bug with disconnection Fixed bug with disconnection and max_non_reserved_peers Feb 2, 2023
Copy link
Contributor

@freesig freesig left a comment

Choose a reason for hiding this comment

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

Nice work

@@ -876,7 +869,7 @@ mod tests {
let jh = tokio::spawn(async move {
while rx.try_recv().is_err() {
futures::stream::iter(node_services.iter_mut())
.for_each_concurrent(10, |node| async move {
.for_each_concurrent(20, |node| async move {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this at least be a const value?

@xgreenx xgreenx merged commit 073ce8f into master Feb 3, 2023
@xgreenx xgreenx deleted the feature/fix-some-issues-with-disconnect-test branch February 3, 2023 09:49
leviathanbeak added a commit that referenced this pull request Feb 7, 2023
During #974 optimistic reconnect was removed from the code as being a
_duplicate_ work.

It was not a duplicate work, more of an optimistic immediate reconnect
if the node is available, while `health_check` tries to reconnect after
a certain Interval (e.g. 30-60 seconds) which is there as a backup only
if the optimistic reconnect was not successful.

I also added a small description comment to `OutboundState`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fuel-p2p
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unite test failed: The node should only connect to the specified reserved nodes!
3 participants