Skip to content

fix(p2p/pex): respect MaxNumOutboundPeers limit while dialing peers provided by a seed node#3360

Merged
cason merged 10 commits intomainfrom
cason/486-seed-addresses
Jul 2, 2024
Merged

fix(p2p/pex): respect MaxNumOutboundPeers limit while dialing peers provided by a seed node#3360
cason merged 10 commits intomainfrom
cason/486-seed-addresses

Conversation

@cason
Copy link

@cason cason commented Jun 28, 2024

Closes #486.

Commits:

  1. Make TestConnectionSpeedForPeerReceivedFromSeed to fail, as it will make the node to connect to more than the configured MaxNumOutboundPeers
  2. Solve the issue by introducing a channel to wake up ensurePeersRoutine(). In this way, the node will not to wait until the next defaultEnsurePeersPeriod (30s) before attempting again to connect to new peers (ensurePeers() method) whose addresses were provide by the seed node.

PR checklist

  • Tests written/updated
  • Changelog entry added in .changelog (we use unclog to manage our changelog)
  • Updated relevant documentation (docs/ or spec/) and code comments
  • Title follows the Conventional Commits spec

@cason cason changed the title p2p/pex: respect MaxNumOutboundPeers while dialing peers provided by a seed node fix(p2p/pex): respect MaxNumOutboundPeers while dialing peers provided by a seed node Jun 28, 2024
@cason cason force-pushed the cason/486-seed-addresses branch 2 times, most recently from b72bc6c to a8b708c Compare June 28, 2024 10:37
@cason cason self-assigned this Jun 28, 2024
@cason cason added the p2p label Jun 28, 2024
@cason cason marked this pull request as ready for review June 28, 2024 10:50
@cason cason requested a review from a team as a code owner June 28, 2024 10:50
@cason cason requested a review from a team June 28, 2024 10:50
@cason cason requested a review from a team as a code owner June 28, 2024 10:56
@cason cason linked an issue Jun 28, 2024 that may be closed by this pull request
Copy link
Collaborator

@melekes melekes left a comment

Choose a reason for hiding this comment

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

👍

@melekes
Copy link
Collaborator

melekes commented Jun 28, 2024

Not sure whether we should backport this PR. It is not API breaking, but it changes the way that new nodes connect to peers. For instance, the number of peers of nodes in our QA experiments will change with this PR, as all nodes, except seed nodes, will have at most 10 outbound connections and at most 50 peers in total.

But the previous behavior is unintended, isn't it? If so, I think we should backport the fix.

Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
@cason
Copy link
Author

cason commented Jun 28, 2024

Yes, it was unintended.

This also needs a changelog, which folder should I use?

@cason
Copy link
Author

cason commented Jun 28, 2024

Another point is that the removed code was also used when the node is in seed mode. In this case, it runs the crawlPeersRoutine() instead of the ensurePeersRoutine(). I can add the same logic in the crawlPeersRoutine() routine, although no test is failing at the moment.

Actually, when running in seed mode, apparently there is no maximum number of connections or stuff like that.

Copy link
Contributor

@czarcas7ic czarcas7ic left a comment

Choose a reason for hiding this comment

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

Thanks for addressing this so quickly, implementation looks great :)

Copy link
Collaborator

@sergio-mena sergio-mena left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@sergio-mena sergio-mena added the bug Something isn't working label Jul 2, 2024
@melekes melekes added backport-to-v0.37.x backport-to-v0.38.x Tell Mergify to backport the PR to v0.38.x labels Jul 2, 2024
@cason cason changed the title fix(p2p/pex): respect MaxNumOutboundPeers while dialing peers provided by a seed node fix(p2p/pex): respect MaxNumOutboundPeers limit while dialing peers provided by a seed node Jul 2, 2024
@cason cason enabled auto-merge July 2, 2024 09:44
@cason cason added this pull request to the merge queue Jul 2, 2024
Merged via the queue into main with commit 4241776 Jul 2, 2024
@cason cason deleted the cason/486-seed-addresses branch July 2, 2024 09:48
mergify bot pushed a commit that referenced this pull request Jul 2, 2024
…rovided by a seed node (#3360)

Closes #486.

Commits:

1. Make `TestConnectionSpeedForPeerReceivedFromSeed` to fail, as it will
make the node to connect to more than the configured
`MaxNumOutboundPeers`
2. Solve the issue by introducing a channel to wake up
`ensurePeersRoutine()`. In this way, the node will not to wait until the
next `defaultEnsurePeersPeriod` (30s) before attempting again to connect
to new peers (`ensurePeers()` method) whose addresses were provide by
the seed node.

---

#### PR checklist

- [x] Tests written/updated
- [x] Changelog entry added in `.changelog` (we use
[unclog](https://github.com/informalsystems/unclog) to manage our
changelog)
- [x] Updated relevant documentation (`docs/` or `spec/`) and code
comments
- [x] Title follows the [Conventional
Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec

---------

Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
(cherry picked from commit 4241776)

# Conflicts:
#	p2p/pex/pex_reactor.go
mergify bot pushed a commit that referenced this pull request Jul 2, 2024
…rovided by a seed node (#3360)

Closes #486.

Commits:

1. Make `TestConnectionSpeedForPeerReceivedFromSeed` to fail, as it will
make the node to connect to more than the configured
`MaxNumOutboundPeers`
2. Solve the issue by introducing a channel to wake up
`ensurePeersRoutine()`. In this way, the node will not to wait until the
next `defaultEnsurePeersPeriod` (30s) before attempting again to connect
to new peers (`ensurePeers()` method) whose addresses were provide by
the seed node.

---

#### PR checklist

- [x] Tests written/updated
- [x] Changelog entry added in `.changelog` (we use
[unclog](https://github.com/informalsystems/unclog) to manage our
changelog)
- [x] Updated relevant documentation (`docs/` or `spec/`) and code
comments
- [x] Title follows the [Conventional
Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec

---------

Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
(cherry picked from commit 4241776)

# Conflicts:
#	.changelog/v0.38.3/bug-fixes/486-p2p-max-outbound.md
#	p2p/pex/pex_reactor.go
#	p2p/pex/pex_reactor_test.go
mergify bot pushed a commit that referenced this pull request Jul 2, 2024
…rovided by a seed node (#3360)

Closes #486.

Commits:

1. Make `TestConnectionSpeedForPeerReceivedFromSeed` to fail, as it will
make the node to connect to more than the configured
`MaxNumOutboundPeers`
2. Solve the issue by introducing a channel to wake up
`ensurePeersRoutine()`. In this way, the node will not to wait until the
next `defaultEnsurePeersPeriod` (30s) before attempting again to connect
to new peers (`ensurePeers()` method) whose addresses were provide by
the seed node.

---

#### PR checklist

- [x] Tests written/updated
- [x] Changelog entry added in `.changelog` (we use
[unclog](https://github.com/informalsystems/unclog) to manage our
changelog)
- [x] Updated relevant documentation (`docs/` or `spec/`) and code
comments
- [x] Title follows the [Conventional
Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec

---------

Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
(cherry picked from commit 4241776)

# Conflicts:
#	p2p/pex/pex_reactor.go
#	p2p/pex/pex_reactor_test.go
cason pushed a commit that referenced this pull request Jul 2, 2024
…rovided by a seed node (backport #3360) (#3397)

Closes #486.

Commits:

1. Make `TestConnectionSpeedForPeerReceivedFromSeed` to fail, as it will
make the node to connect to more than the configured
`MaxNumOutboundPeers`
2. Solve the issue by introducing a channel to wake up
`ensurePeersRoutine()`. In this way, the node will not to wait until the
next `defaultEnsurePeersPeriod` (30s) before attempting again to connect
to new peers (`ensurePeers()` method) whose addresses were provide by
the seed node.

---

#### PR checklist

- [x] Tests written/updated
- [x] Changelog entry added in `.changelog` (we use
[unclog](https://github.com/informalsystems/unclog) to manage our
changelog)
- [x] Updated relevant documentation (`docs/` or `spec/`) and code
comments
- [x] Title follows the [Conventional
Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec
<hr>This is an automatic backport of pull request #3360 done by
[Mergify](https://mergify.com).

---------

Co-authored-by: Daniel <daniel.cason@informal.systems>
cason pushed a commit that referenced this pull request Jul 2, 2024
…rovided by a seed node (backport #3360) (#3396)

Closes #486.

Commits:

1. Make `TestConnectionSpeedForPeerReceivedFromSeed` to fail, as it will
make the node to connect to more than the configured
`MaxNumOutboundPeers`
2. Solve the issue by introducing a channel to wake up
`ensurePeersRoutine()`. In this way, the node will not to wait until the
next `defaultEnsurePeersPeriod` (30s) before attempting again to connect
to new peers (`ensurePeers()` method) whose addresses were provide by
the seed node.

---

#### PR checklist

- [x] Tests written/updated
- [x] Changelog entry added in `.changelog` (we use
[unclog](https://github.com/informalsystems/unclog) to manage our
changelog)
- [x] Updated relevant documentation (`docs/` or `spec/`) and code
comments
- [x] Title follows the [Conventional
Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec
<hr>This is an automatic backport of pull request #3360 done by
[Mergify](https://mergify.com).

---------

Co-authored-by: Daniel <daniel.cason@informal.systems>
cason pushed a commit that referenced this pull request Jul 2, 2024
…rovided by a seed node (backport #3360) (#3395)

Closes #486.

Commits:

1. Make `TestConnectionSpeedForPeerReceivedFromSeed` to fail, as it will
make the node to connect to more than the configured
`MaxNumOutboundPeers`
2. Solve the issue by introducing a channel to wake up
`ensurePeersRoutine()`. In this way, the node will not to wait until the
next `defaultEnsurePeersPeriod` (30s) before attempting again to connect
to new peers (`ensurePeers()` method) whose addresses were provide by
the seed node.

---

#### PR checklist

- [x] Tests written/updated
- [x] Changelog entry added in `.changelog` (we use
[unclog](https://github.com/informalsystems/unclog) to manage our
changelog)
- [x] Updated relevant documentation (`docs/` or `spec/`) and code
comments
- [x] Title follows the [Conventional
Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec
<hr>This is an automatic backport of pull request #3360 done by
[Mergify](https://mergify.com).

---------

Co-authored-by: Daniel <daniel.cason@informal.systems>
mergify bot added a commit that referenced this pull request Dec 12, 2024
Solves #4620.

Fixes an issue introduced by
#3360.

In short, when receiving addresses from a configured seed node, the peer
immediately dials the received addresses, without waiting for the
`defaultEnsurePeersPeriod` (30s). This is a desired behavior, the "fast
dial mode" in the title.

However, for preventing abuse, a node only accepts PEX requests from a
peer every `minReceiveRequestInterval()` time, set to
`defaultEnsurePeersPeriod/3` (10s). When running this "fast dial mode",
however, a PEX request can be send, in some unlucky setup, to the same
peer without waiting for the full defaultEnsurePeersPeriod` (30s).

The problem is that at the receive side, a node keeps track of the
latest PEX request received from each peer. If two requests are received
with an interval lower than `minReceiveRequestInterval()`, the peer is
considered abusive: it is disconnected with an
`ErrReceivedPEXRequestTooSoon` error and banned from the address book.

This PR proposes a workaround to prevent the above mentioned scenario.

---

#### PR checklist

- [ ] Tests written/updated
- [ ] Changelog entry added in `.changelog` (we use
[unclog](https://github.com/informalsystems/unclog) to manage our
changelog)
- [ ] Updated relevant documentation (`docs/` or `spec/`) and code
comments

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
mergify bot pushed a commit that referenced this pull request Dec 12, 2024
Solves #4620.

Fixes an issue introduced by
#3360.

In short, when receiving addresses from a configured seed node, the peer
immediately dials the received addresses, without waiting for the
`defaultEnsurePeersPeriod` (30s). This is a desired behavior, the "fast
dial mode" in the title.

However, for preventing abuse, a node only accepts PEX requests from a
peer every `minReceiveRequestInterval()` time, set to
`defaultEnsurePeersPeriod/3` (10s). When running this "fast dial mode",
however, a PEX request can be send, in some unlucky setup, to the same
peer without waiting for the full defaultEnsurePeersPeriod` (30s).

The problem is that at the receive side, a node keeps track of the
latest PEX request received from each peer. If two requests are received
with an interval lower than `minReceiveRequestInterval()`, the peer is
considered abusive: it is disconnected with an
`ErrReceivedPEXRequestTooSoon` error and banned from the address book.

This PR proposes a workaround to prevent the above mentioned scenario.

---

#### PR checklist

- [ ] Tests written/updated
- [ ] Changelog entry added in `.changelog` (we use
[unclog](https://github.com/informalsystems/unclog) to manage our
changelog)
- [ ] Updated relevant documentation (`docs/` or `spec/`) and code
comments

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit 491379f)

# Conflicts:
#	p2p/pex/pex_reactor.go
mergify bot added a commit that referenced this pull request Dec 12, 2024
Solves #4620.

Fixes an issue introduced by
#3360.

In short, when receiving addresses from a configured seed node, the peer
immediately dials the received addresses, without waiting for the
`defaultEnsurePeersPeriod` (30s). This is a desired behavior, the "fast
dial mode" in the title.

However, for preventing abuse, a node only accepts PEX requests from a
peer every `minReceiveRequestInterval()` time, set to
`defaultEnsurePeersPeriod/3` (10s). When running this "fast dial mode",
however, a PEX request can be send, in some unlucky setup, to the same
peer without waiting for the full defaultEnsurePeersPeriod` (30s).

The problem is that at the receive side, a node keeps track of the
latest PEX request received from each peer. If two requests are received
with an interval lower than `minReceiveRequestInterval()`, the peer is
considered abusive: it is disconnected with an
`ErrReceivedPEXRequestTooSoon` error and banned from the address book.

This PR proposes a workaround to prevent the above mentioned scenario.

---

#### PR checklist

- [ ] Tests written/updated
- [ ] Changelog entry added in `.changelog` (we use
[unclog](https://github.com/informalsystems/unclog) to manage our
changelog)
- [ ] Updated relevant documentation (`docs/` or `spec/`) and code
comments

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit 491379f)
jmalicevic added a commit that referenced this pull request Dec 12, 2024
…) (#4649)

Solves #4620.

Fixes an issue introduced by
#3360.

---------

Co-authored-by: Daniel <daniel.cason@informal.systems>
Co-authored-by: Jasmina Malicevic <jasmina.dustinac@gmail.com>
jmalicevic pushed a commit that referenced this pull request Dec 12, 2024
…) (#4648)

Solves #4620.

Fixes an issue introduced by
#3360.


Co-authored-by: Daniel <daniel.cason@informal.systems>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-to-v0.38.x Tell Mergify to backport the PR to v0.38.x bug Something isn't working p2p

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

p2p: more peers connect than the maxInbound / maxOutbound set p2p: dialing addresses provided by a seed node disregards MaxNumOutboundPeers parameter

4 participants