Repository navigation
Description
Migrated from tendermint/tendermint#9548.
The method ensurePeers defines when a node should dial peer addresses in order to establish outbound peer connections. It dials new peers when the number of outbound peers plus the number of ongoing connections attempts is lower than the configured MaxNumOutboundPeers parameter. If the node defines it has to dial peers but it cannot find, in its address book, any suitable peer to dial, this method will submit a PEX request to the configured seed nodes in order to retrieve candidate peer addresses.
The ensurePeers method is invoked periodically, every ensurePeersPeriod = 30s. This means that between requesting peer addresses to a seed node and actually attempting to dial them, a node will wait for this interval, which was considered too long (tendermint/tendermint#2093). A fix was proposed in tendermint/tendermint#2115, where ensurePeers was immediately invoked when a node receives peer addresses provided by a seed node. This solution introduced another issue (tendermint/tendermint#3338): by executing ensurePeers in intervals below ensurePeersPeriod, a node could end up submitting PEX requests too often, which consists on a misbehavior.
To solve this issue, tendermint/tendermint#3762 replaced the invocation of ensurePeers, when receiving addresses from a seed node, by go routines that attempt connecting to all peer addresses received from a seed node. The introduced code excerpt, however, does not takes into consideration the number of connected peers or of connection attempts, nor the MaxNumOutboundPeers parameter. In other words, the logic implemented in ensurePeers to limit the number of outbound peers is ignored. As a result, upon resorting on a seed node to retrieve candidate peers to dial, a node may end up connected to all peers informed by the seed node, which tends to be more than the configured MaxNumOutboundPeers, with default value of 10.
This breach in the limits of outbound peers was identified when writing the spec of the p2p layer (tendermint/tendermint#9089). In testnet experiments (tendermint/tendermint#9499), it was observed that nodes had more peers than the maximum configured number (MaxNumOutboundPeers + MaxNumInboundPeers, 50 by default). This issue represents the suspect that the reason for this is the breach above detailed. Reinforces this suspect the fact that nodes in the testnet resort by default to seed nodes to learn addresses of potential peers.
Suggested fix: restore the solution introduced by tendermint/tendermint#2115, while creating another way to prevent sending PEX requests to often to connected peers or seed nodes.
Metadata
Metadata
Assignees
Type
Projects
- StatusShow more project fieldsTodo
Activity
gaia commentedon Aug 29, 2023
On osmosisd 18.0.0., I removed all seeds from the config file and deleted addrbook.json. Restarted the daemon. 92 peers, despite
if peers from the seeds are to blame, how do they remain after clearing the addrbook? and how do I remove them?
cason commentedon Aug 30, 2023
Hey, can you share the content of the config file, specially the p2p section? It would also be useful to have access to the log produced by the node. If you prefer, you can reach us through Slack.
cason commentedon Aug 30, 2023
Regarding the question itself: if there are no seed nodes configured nor addresses in the address book, the node, a priori, would be unable to dial any other node in the network. Because it just does not know any address to dial. It is possible, however, that other nodes know the node's addresses (maybe from previous executions) and would dial it. Once establishing these inbound connections, the node would learn peer addresses from them via PEX protocol, being from this point able to dial some of the provided addresses. Another possibility is that addresses are manually provided to the node. This can be done using the persistent peers configuration flag or via RPC calls instructing the node to dial some specific addresses.
To understand better what is happening to the node, it would be particularly valuable to get the evolution of the log entries produced by the ensure peers routine. Those entries are produced every 30s, by default:
As observed above, they report the number of peers, with distinction between inbound and outbound peers, plus the number of peers the node is currently dialing or will attempt dialing at each call of this method.
gaia commentedon Aug 30, 2023
best privately via slack/discord/telegram. pls send link.
gaia commentedon Aug 30, 2023
Logs (at this time there were 94 peers)
osmosisd.zip
(ZIP password is your username, david)
cason commentedon Aug 30, 2023
Your config file contains 136 persistent peers, is that correct?
gaia commentedon Aug 30, 2023
yes. 60 max should be respected. i can try removing all of them and see how many peers I end up with (known id@address will get inbound connections any way)
cason commentedon Aug 30, 2023
Yes, I understand your point and I agree with it, but this is not how it works in the current p2p layer implementation.
Persistent peers are addresses to which a node will dial at startup and keep dialing when dialing attempts fail. They are more likely to be set as outbound peers, as we are dialing them (they can be inbound if the peer dials us before or at the same time). When added as outbound peers, they are not filtered out based on the maximum configured number of outbound peers, as it is mentioned in the associated comment in the configuration file:
The limit of outbound peers applies to the peers we learned via PEX protocol and/or are stored in our address book, from which we randomly pick addresses to dial. The PEX reactor is not dialing peers when the logic present here realizes that the number of outbound connections plus the number of ongoing connection attempts is larger than the configured
MaxNumOutboundPeers. In the logs you have sent us, the log message produced by this method is not present, at will probably show that the node is not dialing anyone at each round of this routine.This logic, however, is independent from the logic used to dial persistent peers. Persistent peers are manually configured to be dialed by the node, and do not fall in the category of peers which number of connections is bound the
MaxNumOutboundPeersflag.In fact, if you add all addresses configured as persistent peers to the node's address book (prior from starting it), you will probably realize that the
MaxNumOutboundPeerswill be observed.gaia commentedon Aug 30, 2023
your explanation makes sense.
but MaxNumOutboundPeers + MaxNumInboundPeers should be respected and agnostic to where the peers were sourced from. UnconditionalPeers should be the only exception.
More peers than necessary taxes the HW (CPU + Disk) and the uplink. We run our own HW (add disk wear & tear cost), we use virtualization (need to share CPU+Disk+Uplink) and the limit not being respected becomes an unnecessary burden to our infrastructure (must be noted, without advantages, even for the rest of the network. there is a law of diminishing returns after you add a certain amount of peers)
cason commentedon Aug 31, 2023
I agree with you in general terms. Would you mind to open an issue describing your request? I can follow up and provide context.
The only issue that I have regarding your observation is more conceptual. When you configure a node (address) as persistent peer, you are telling Comet that you want to keep a connection with this peer, no matter what is the connection policy configured. You are manually instructing the node to connect to that address. So the node will dial the peer, continue dialing when attempts fails (there is a limit for that, but we are talking about days), and re-dial the peer if the connection, for any reason, is lost.
If you provide
Xpersistent peers, you manually instructing the node to maintain connections to thoseXpeers. If at the same time you setMaxNumOutboundPeers < X, you are definitely providing contradictory instructions to the node.My main point here is that some users, and maybe this is also your case, are not using the persistent peers manual configuration properly. The point here is to understand what you wanted from this configuration and see whether a different configuration key could be adopted instead. Because if we say that persistent peers are optional connections, what is the point of it? If you say that manual commands should respect the configured bounds, how can we provide a way to overcome the configure bounds by manual action of the operators?
cason commentedon Aug 31, 2023
I am referencing this issue here because I believe that part of the behavior you expect by setting a large number of persistent peers would be achieved with the introduction of the following configuration flag:
#1016
gaia commentedon Aug 31, 2023
I don't see a contradiction. In my mind it makes perfect sense as:
I have a maximum number of peers I'd like my node to use (aside from unconditional)
I have a list of known good peers. It might have 200 peers, and my total maximum be 60. I know that I need 60, so the first 60 are in, the rest will only be retried if a slot opens up. Furthermore, the list quality degrades over time (IDs change, IPs change), so in a couple of years let's throw a number out there, only 120 of the 200 are valid. Give it a couple more years, it degrades further. I don't want to put only 60 in persistent_peers, bc this entails more regular maintenance of this list.
But I only have to worry about updating the peer list when I can't get 60, which is my determined optimal number. And going below 60 is unlikely to happen, bc my node is known.
If you rename persistent_peers to preferred_peers, all of a sudden my explanation above becomes obvious. But the real contradiction lies in having the words Maximum & and (an unlimited) Persistent list as bounds of the same construct.
3 remaining items
cason commentedon Sep 4, 2023
We added this topic to the agenda for the next CometBFT Community call, this Thursday 7th.
gaia commentedon Sep 4, 2023
I sent a request to join. mostly to listen in, I think my PoV is already well explained.
cason commentedon Sep 7, 2023
#1304 (comment)
p2p/pex: make test to fail, in line with issue #486
p2p/pex: make test to fail in CI too (issue #486)
fix(p2p/pex): respect MaxNumOutboundPeers limit while dialing peers p…
fix(p2p/pex): respect MaxNumOutboundPeers limit while dialing peers p…
fix(p2p/pex): respect MaxNumOutboundPeers limit while dialing peers p…
fix(p2p/pex): respect MaxNumOutboundPeers limit while dialing peers p…
fix(p2p/pex): respect MaxNumOutboundPeers limit while dialing peers p…
fix(p2p/pex): respect MaxNumOutboundPeers limit while dialing peers p…
fix(p2p/pex): respect MaxNumOutboundPeers limit while dialing peers p…
0xHansLee commentedon Dec 5, 2024
Hello, @cason.
After fixing this issue (#3397), I guess the
sent next PEX request too soonissue (tendermint/tendermint#3338) occurs again.As I understand, this has been fixed in tenermint by just dialing to peer instead of calling
ensurePeers()(tendermint/tendermint#3762).But #3397 calls
ensurePeers(), so that the PEX request happens too frequently. What do you think of this?