|
9 | 9 |
|
10 | 10 | # Manage peers
|
11 | 11 |
|
12 |
| -Hyperledger Besu peer-to-peer (P2P) discovery happens periodically based on the number of peers in a network and the node's [peer limit](#limit-peers). |
| 12 | +Hyperledger Besu peer-to-peer (P2P) discovery happens periodically based on the number of peers in a |
| 13 | +network and the node's [peer limit](#limit-peers). |
13 | 14 |
|
14 |
| -The frequency of discovery isn't configurable, but you can [limit remote connections](#limit-remote-connections) in public networks and [randomly prioritize connections](../../reference/cli/options.md#random-peer-priority-enabled) in small, stable networks. |
| 15 | +The frequency of discovery isn't configurable, but you can |
| 16 | +[limit remote connections](#limit-remote-connections) in public networks and |
| 17 | +[randomly prioritize connections](../../reference/cli/options.md#random-peer-priority-enabled) in |
| 18 | +small, stable networks. |
15 | 19 |
|
16 | 20 | :::info
|
| 21 | +You can use [`admin_addPeer`](../../reference/cli/options.md#admin_addpeer) to attempt a specific |
| 22 | +connection, but this isn't P2P discovery. |
| 23 | +::: |
17 | 24 |
|
18 |
| -You can use [`admin_addPeer`](../../reference/cli/options.md#admin_addpeer) to attempt a specific connection, but this isn't P2P discovery. |
| 25 | +In private networks, we recommend |
| 26 | +[using bootnodes](../../../private-networks/how-to/configure/bootnodes.md) to initially discover peers. |
19 | 27 |
|
20 |
| -::: |
| 28 | +## P2P discovery process |
| 29 | + |
| 30 | +The P2P discovery process requires [ports to be open to UDP and TCP traffic](configure-ports.md#p2p-networking). |
| 31 | +If you have a firewall in place, keep those ports open to allow traffic in and out. |
| 32 | +If you are running a node at home on your network, ensure that your router has those ports open. |
| 33 | + |
| 34 | +The `discovery` stack uses UDP to keep peer discovery lightweight and quick. |
| 35 | +It only allows a node to find peers and connect to them, without any additional overhead. |
| 36 | +Once peers have bonded, the data exchange between them is complex and needs a fully featured |
| 37 | +protocol to support error checking and retries, so the `devP2P` stack uses TCP. |
| 38 | + |
| 39 | +Both stacks work in parallel: the `discovery` stack adds new peers to the network, and the `devP2P` |
| 40 | +stack enables interactions and data flow between them. |
| 41 | +In detail, the P2P discovery process is as follows: |
| 42 | + |
| 43 | +1. When Besu starts up it advertises its presence and details (including the enode) using UDP before |
| 44 | + establishing a formal connection with any peer (log messages look like `Enode URL enode://....`). |
| 45 | + |
| 46 | +2. Besu attempts to connect to the network's bootnodes (a set of predefined nodes used to help |
| 47 | + bootstrap discovery). |
| 48 | + |
| 49 | +3. Once a connection with a bootnode is established using UDP (`ping/pong` handshake messages in the |
| 50 | + debug and trace logs), Besu requests a list of neighbors (potential peers) from the bootnode |
| 51 | + (`find node` messages in the debug and trace logs). |
| 52 | + |
| 53 | +4. Besu attempts to connect to each peer using TCP, and get status information from them – such |
| 54 | + as network details, what the peer believes to be the current chain head, and its list of neighbors. |
| 55 | + From this point on any traffic to that peer is only done using TCP. |
| 56 | + |
| 57 | +5. Depending on the [synchronization method](../../get-started/connect/sync-node.md), a common block |
| 58 | + (the pivot block) is selected that all connected peers (default of 5) have, and Besu syncs from |
| 59 | + that block till it gets to chain head. |
| 60 | + Log messages look like `Downloading world state from peers for pivot block .......`. |
| 61 | + |
| 62 | +6. Besu repeats the same process for each peer in step 4, and any new peers that come along |
| 63 | + (regardless of client). |
21 | 64 |
|
22 |
| -In private networks, we recommend [using bootnodes](../../../private-networks/how-to/configure/bootnodes.md) to initially discover peers. |
| 65 | +The more peers Besu is connected to, the more confident it is of having an accurate view of the network. |
23 | 66 |
|
24 | 67 | ## Limit peers
|
25 | 68 |
|
|
0 commit comments