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

Fix unexpected ConnectionDirection update #188

Merged
merged 13 commits into from
Jun 13, 2023

Conversation

ackintosh
Copy link
Member

@ackintosh ackintosh commented Jun 4, 2023

Description

A connection direction can unexpectedly change from Outgoing to Incoming in the scenario shown in this diagram. The diagram shows a specific case in PING/PONG. However, if we generalize this, when an Outgoing connection is established and the other node returns WHOAREYOU, the ConnectionDirection will change to Incoming at the time the new session is established. This could potentially cause some problems. e.g. IpVote doesn't work as IpVote ignores Incoming connections.

This PR makes the service to set only initial connection direction and not update it if a node already exists in the routing table.

Notes & open questions

I have tested this PR with the PING/PONG simulation (#184), and confirmed that the Outgoing connection directions are kept.

sequenceDiagram
    participant Node1
    participant Node2

    rect rgb(10, 10, 10)
    Note left of Node1: <Node1's KBucket><br>[Node2] direction:Outgoing, state:Connected
    end
    Note over Node1,Node2: Session established

    rect rgb(10, 10, 10)
    Note left of Node1: Node1 changes its IP address<br> but doesn't update its ENR.
    end 
    Note over Node1: *** Change its IP address ***

    Node1 ->> Node2: PING
    Note over Node2: No session with the new IP exists
    Node2 ->> Node1: WHOAREYOU
    Note over Node1: Establish new session
    rect rgb(0, 255, 0)
    Note left of Node1: The Outgoing direction is kept<br> when establishing a new session here. 
    end
    rect rgb(0, 255, 0)
    Note left of Node1: <Node1's KBucket><br>[Node2] direction:***Outgoing***, state:Connected
    end
    Node1 ->> Node2: Auth message
    Note over Node2: Establish one-time session with Node1's new IP
    Note over Node2: Respond the PING using the one-time session
    Node2 ->> Node1: PONG
Loading

Change checklist

  • Self-review
  • Documentation updates if relevant
  • Tests if relevant

@ackintosh ackintosh marked this pull request as ready for review June 6, 2023 00:19
@ackintosh
Copy link
Member Author

@AgeManning @divagant-martian Please have a look when you have time.

Copy link
Member

@AgeManning AgeManning left a comment

Choose a reason for hiding this comment

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

On a first review, it seems like we could leave the handler as it is, then in the service, we never update the direction of a node in the routing table, we only ever set the direction for a new node.

This way the code changes would be minimal, and the initial connections are kept as final (until the node is exited from the routing table).

What do you think?

Copy link
Collaborator

@divagant-martian divagant-martian left a comment

Choose a reason for hiding this comment

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

I find this change in the right direction but I missed something on the first review that changes the point of the PR

src/handler/mod.rs Outdated Show resolved Hide resolved
src/handler/mod.rs Outdated Show resolved Hide resolved
src/service.rs Outdated Show resolved Hide resolved
@ackintosh
Copy link
Member Author

@AgeManning @divagant-martian I have tested again with the latest changes, and that was fine. 🙆‍♂️ Please have another look.

Copy link
Collaborator

@divagant-martian divagant-martian left a comment

Choose a reason for hiding this comment

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

LGTM, missing a typo

src/service.rs Outdated Show resolved Hide resolved
Fix typo

Co-authored-by: Divma <[email protected]>
Copy link
Member

@AgeManning AgeManning left a comment

Choose a reason for hiding this comment

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

Yeah nice, looks good.

Much simpler :)

@AgeManning AgeManning merged commit 47844ca into sigp:master Jun 13, 2023
@ackintosh ackintosh deleted the connection-direction branch June 13, 2023 08:35
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.

3 participants