DxChain Wiki
4.6 P2P Decentralized Network Layer
P2P network technology is commonly used in blockchain to connect and propagate information between nodes. Essentially, a P2P network is an overlay network usually built on the Internet and can be viewed as a directed graph from a mathematical point of view, each computer is a peer node in the network. As shown in figure 8, there should be at least one path between all peers to achieve a network connection in an ideal situation. Since each peer has an incomplete view of the whole network topology and other peers, an intermediate node is required to forward the message to the correct peer. This connectivity ensures resilience even if the peer node changes. For each peer node, the connectivity of the graph is reflected by the adjacency to other peers. Adjacent peers may hold incorrect information when peer nodes join or leave the network. Therefore, overlay maintenance mechanisms are required to keep adjacency information updated so that all nodes will remain connectivity.
Figure 8: Directed Graph of P2P Network
DxChain uses Kademlia to implement the peer discovery protocol (RLPx Node Discovery Protocol). A number or enodeID is used to identify each node and locate values. Each peer has a data structure consisting of 256 distinct buckets, where bucket i stores information about 16 peers at a distance 2^(i-1) to 2^i from its own enode ID. To discover a new peer, the node on DxChain chooses itself as target x, find 16 nodes closest to the target x in the buckets, and ask them to return 16 nodes from their buckets “closer” to the target x, resulting in up to 16x16 newly discovered nodes. The process will be repeated until no new nodes are found.
Similarly, when a node joins or leaves DxChain network, Kademlia can quickly perform network maintenance to ensure that all nodes connect with other nodes through the optimal path. After the connection of the peer node is established, the DxChain node exchanges blockchain information with other peers through encrypted and authenticated TCP connections, which include broadcasts of different types of transactions, broadcasts generated by blocks, and data synchronization between nodes, etc., to ensure that all nodes maintain the same set of blockchain ledger, so as to achieve the consistency of node information in the network.
Copy link