Skip to content

p2p: dialing addresses provided by a seed node disregards MaxNumOutboundPeers parameter  #486

Closed

Description

@cason

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.

Activity

  1. gaia commented on Aug 29, 2023

    @gaia

    On osmosisd 18.0.0., I removed all seeds from the config file and deleted addrbook.json. Restarted the daemon. 92 peers, despite

    cat config.toml | grep _num_ && curl -s http://localhost:26657/net_info | jq -r .result.n_peers && /home/ubuntu/bin/osmosisd version
     && systemctl status osmosisd | grep 'Active:' &&  ps aux | grep [o]smosisd && ll config.toml
    max_num_inbound_peers = 40
    max_num_outbound_peers = 20
    109
    18.0.0
         Active: active (running) since Tue 2023-08-29 16:25:20 UTC; 4min 18s ago
    ubuntu     43320  0.0  7.7 5585304 3013036 ?     Ssl  16:25   5:15 /home/ubuntu/bin/osmosisd start
    -rw-rw-r-- 1 ubuntu ubuntu 24K Aug 29 16:23 config.toml
    

    if peers from the seeds are to blame, how do they remain after clearing the addrbook? and how do I remove them?

  2. cason commented on Aug 30, 2023

    @cason
    Author

    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.

  3. cason commented on Aug 30, 2023

    @cason
    Author

    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:

    r.Logger.Info(
                    "Ensure peers",
                    "numOutPeers", out,
                    "numInPeers", in, 
                    "numDialing", dial,
                    "numToDial", numToDial,
            )
    

    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.

  4. gaia commented on Aug 30, 2023

    @gaia

    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.

    best privately via slack/discord/telegram. pls send link.

  5. gaia commented on Aug 30, 2023

    @gaia
    [p2p]
    
    # Address to listen for incoming connections
    laddr = "tcp://0.0.0.0:26656"
    
    # Address to advertise to peers for them to dial
    # If empty, will use the same port as the laddr,
    # and will introspect on the listener or use UPnP
    # to figure out the address.
    external_address = ""
    
    # Comma separated list of seed nodes to connect to
    seeds = ""
    
    # Comma separated list of nodes to keep persistent connections to
    persistent_peers = "[email protected]:12556,[email protected]:26656,[email protected]:12000,[email protected]:26629,[email protected]:30438,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:12556,[email protected]:27656,[email protected]:12000,[email protected]:26656,[email protected]:32668,[email protected]:26656,[email protected]:26656,[email protected]:46656,[email protected]:26656,[email protected]:26656,[email protected]:56656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:12556,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:2000,[email protected]:14100,[email protected]:26656,[email protected]:2000,[email protected]:26656,[email protected]:33656,[email protected]:56656,[email protected]:26656,[email protected]:12000,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:36656,[email protected]:26656,[email protected]:16656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:38656,[email protected]:12556,[email protected]:26656,[email protected]:16190,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:2000,[email protected]:2000,[email protected]:26656,[email protected]:26656,[email protected]:34656,[email protected]:26656,[email protected]:26656,[email protected]:65535,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:2000,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26679,[email protected]:56656,[email protected]:26656,[email protected]:26656,[email protected]:30263,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:32323,[email protected]:46656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:36656,[email protected]:26656,[email protected]:26756,[email protected]:26656,[email protected]:26656,[email protected]:26624,[email protected]:26656,[email protected]:26656,[email protected]:30022,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:31693,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:24856,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:12656,[email protected]:26656,[email protected]:26656,[email protected]:12956"
    
    # UPNP port forwarding
    upnp = false
    
    # Path to address book
    addr_book_file = "config/addrbook.json"
    
    # Set true for strict address routability rules
    # Set false for private or local networks
    addr_book_strict = true
    
    # Maximum number of inbound peers
    max_num_inbound_peers = 40
    
    # Maximum number of outbound peers to connect to, excluding persistent peers
    max_num_outbound_peers = 20
    
    # List of node IDs, to which a connection will be (re)established ignoring any existing limits
    unconditional_peer_ids = ""
    
    # Maximum pause when redialing a persistent peer (if zero, exponential backoff is used)
    persistent_peers_max_dial_period = "0s"
    
    # Time to wait before flushing messages out on the connection
    flush_throttle_timeout = "100ms"
    
    # Maximum size of a message packet payload, in bytes
    max_packet_msg_payload_size = 1024
    
    # Rate at which packets can be sent, in bytes/second
    send_rate = 5120000
    
    # Rate at which packets can be received, in bytes/second
    recv_rate = 5120000
    
    # Set true to enable the peer-exchange reactor
    pex = true
    
    # Seed mode, in which node constantly crawls the network and looks for
    # peers. If another node asks it for addresses, it responds and disconnects.
    #
    # Does not work if the peer-exchange reactor is disabled.
    seed_mode = true
    
    # Comma separated list of peer IDs to keep private (will not be gossiped to other peers)
    private_peer_ids = ""
    
    # Toggle to disable guard against peers connecting from the same ip.
    allow_duplicate_ip = false
    
    # Peer connection configuration.
    handshake_timeout = "20s"
    dial_timeout = "3s"
    

    Logs (at this time there were 94 peers)
    osmosisd.zip
    (ZIP password is your username, david)

  6. cason commented on Aug 30, 2023

    @cason
    Author

    Your config file contains 136 persistent peers, is that correct?

    % grep 'persistent_peers' /tmp/config | tr , '\n' | wc -l
         136
    
  7. gaia commented on Aug 30, 2023

    @gaia

    Your config file contains 136 persistent peers, is that correct?

    % grep 'persistent_peers' /tmp/config | tr , '\n' | wc -l
         136
    

    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)

  8. cason commented on Aug 30, 2023

    @cason
    Author

    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:

    # Maximum number of outbound peers to connect to, excluding persistent peers
    max_num_outbound_peers = 20
    

    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 MaxNumOutboundPeers flag.

    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 MaxNumOutboundPeers will be observed.

  9. gaia commented on Aug 30, 2023

    @gaia

    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)

  10. cason commented on Aug 31, 2023

    @cason
    Author

    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 X persistent peers, you manually instructing the node to maintain connections to those X peers. If at the same time you set MaxNumOutboundPeers < 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?

  11. cason commented on Aug 31, 2023

    @cason
    Author

    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

  12. gaia commented on Aug 31, 2023

    @gaia

    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.

  13. 3 remaining items

  14. cason commented on Sep 4, 2023

    @cason
    Author

    We added this topic to the agenda for the next CometBFT Community call, this Thursday 7th.

  15. gaia commented on Sep 4, 2023

    @gaia

    We added this topic to the agenda for the next CometBFT Community call, this Thursday 7th.

    I sent a request to join. mostly to listen in, I think my PoV is already well explained.

  16. cason commented on Sep 7, 2023

    @cason
    Author
  17. added
    bug
    on Jul 2, 2024
  18. added a commit that references this issue on Jul 2, 2024
    4241776
  19. added 3 commits that reference this issue on Jul 2, 2024
    5ba29dd
    891c62b
    18f1f86
  20. added 3 commits that reference this issue on Jul 2, 2024
    25841d8
    ecd56ec
    c4fa9a6
  21. 0xHansLee commented on Dec 5, 2024

    @0xHansLee

    Hello, @cason.

    After fixing this issue (#3397), I guess the sent next PEX request too soon issue (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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugp2p

    Type

    No type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions