Network discovery

Network discovery in a P2P network is crucial. No network is defined when a new node boots up. The new node must detect at least one blockchain node to be a part of the network. There are several ways in which a node can identify peers and thus discover a network.

Different blockchain frameworks use their own protocols to perform peer discovery and efficient routing. We're going to start by exploring basic P2P network discovery by taking a look at Bitcoin's original implementation.

The simplest way to find the list of peers to connect to is by hardcoding a few of the well-known peers. Using a central server that maintains a list of peers is another approach. Bitcoin holds information about DNS seeds, which provide a high level of reliability when a node is initially set up, and will respond with a list of the IP addresses of the Bitcoin nodes. Once a seed node is detected, the node will establish a TCP connection to perform a handshake with that node. The handshake validates the node by sending the version, the address, local blockchain information, and any other relevant information.

Once a connection is set up between peers that have been discovered by the node, the node can query for information about other nodes that are connected to its peer. Similarly, the node can broadcast its own address information to the connected peers to improve its reachability. Each node also makes sure to maintain a threshold for the number of active connections in order to avoid unnecessary bandwidth usage.

Some blockchain platforms, such as Ethereum, use a cryptographic P2P networking protocol suite called RLPx, which provides a general-purpose transport and interface for applications to communicate via a P2P network. RLPx utilizes a Kademlia-like routing to ensure uniform network formation. After the initial node handshake, packets are encapsulated as frames, which are then encrypted.