Skip to content

HPB P2P NetWork

BlockGeek edited this page Apr 24, 2019 · 2 revisions

1 Introduction to P2P network

Peer-to-peer network (P2P network) is the combination product of distributed system and computer network. It can be defined as: network participants share part of their hardware resources (processing power, storage capability, network connectivity, printer, etc.) which provide services and content via the network that can be directly accessed by other peer nodes without going through any intermediate entities. The participants in this network are resources. They are providers of services and content as well as acquirers of resources, services and content.

In HPB main network, the computer running HPB public chain program is used as a single node. These nodes are connected via the network to form a P2P network, providing network connection, database storage and processing capabilities (such as mining, consensus, contracts execution, etc.)

The following is the introduction to the network structure diagram of HPB main network and the nodes.

2 Features of P2P Network

P2P network is an extension of distributed concept. Compared with traditional centralized network, it is featured by the following characteristics:

Decentralization: The resources and services in the network are scattered on all nodes. The information transmission and server implementation are realized directly between the nodes without the intervention of intermediate links or servers.

Expandability: In P2P network, nodes can be easily accessed and deleted. With the increase of nodes, the overall resource and service capabilities of the system are also expanded synchronously. It is considered to have infinite expandability in theory.

Robustness: P2P network is comprised of peer-to-peer network nodes and services are also distributed among nodes. Even if some nodes are damaged, the impact on the entire network is trivial.

Final Consistency: Under the influence of consensus algorithm, each node requires its own database to be consistent with other nodes in the main network. Therefore, in the process of continuous synchronization and forwarding, the database of each node will eventually be consistent.

3 P2P Network Chart

The following chart shows the network structure of P2P network in HPB main network. As we can see, except for the disconnection between bootnode and bootnode as well as snode and snode, all other nodes are connected. In HPB main network, the node is divided into three different categories according to the consensus algorithm. In the chart, Bnode represents static nodes bootnode, hnode represents high performance nodes, pnode represents candidate nodes, and snode represents synchronization nodes. The generation of three different nodes is introduced in the next section.

node

4 Node Introduction

In P2P network, from the perspective of node communication, it can be divided into two categories: neighbor nodes and Peer nodes.

Neighbor node

Neighbor nodes refer to nodes that has passed the udp ping-pong communication, which is used to detect whether the counterpart node is online.

Peer node

Peer nodes refer to nodes that has passed the communication handshake in the network. Only neighbor node may be called as peer node. The communication handshake is used to confirm the legitimacy of counterpart node. Since peer nodes are mutual, node A is the peer of node B while node B is also the peer of node A. In P2P network, each newly accessed node has a potential peer node.

From consensus perspective, nodes can be divided into three categories: high-performance nodes (hpnode), candidate nodes (prenode), and synchronous nodes (synnode).

High-performance nodes (hpnode): are elected from candidate nodes and are used to generate block. The maximum number for now is 31.

Candidate nodes (prenode): are generated by community voting.

Synchronous nodes (synnode): are used only to synchronize database and do not participate in election or generating block.

Note: Both high-performance nodes and candidate nodes are nodes with boe.

5 Node Management

In a P2P network, nodes can join or leave the network without any restriction, which requires each node to manage the information of other nodes, including how to discover other nodes and how to add nodes and delete nodes.

6 Node Discovery

Since there is no such a centralized server for connection in P2P network, if a new node wants to join P2P network, it has to know the node information in P2P network. Therefore, in order for the new node to join the network, the information of static nodes is searched when the node starts. The network is accessed by connecting static nodes, and then the information of other nodes in the network is acquired by interacting with static node (bootnode). Static nodes are nodes whose startup must be connected. The node information is directly written into the code. The following is a timetable of node discovery:

reqnodemsg

In the above figure, node A has already connected with bootnode nodes. The connection is the same as that with other nodes.Please refer to the next section for the specific procedure.

7 Node Addition

7.1 Add a neighbor node

In the node discovery, after the successful connection with static nodes, the new node requests the bootnode for its neighbor node information. Then it performs udp ping-pong request based on the node information returned by the bootnode. If the communication is smooth, the node information is added to the neighbor node. Please refer to the figure below ​nodeA-nodeB

7.2 Add a peer node

The previous section introduces how to add a neighbor node. This process is ongoing. After the node starts, it also continuously check bootnode list and neighbor node list. Then it selects the information of unconnected nodes to perform handshake communication. After successful connection, the node information is added into the peer node list. This is the peer node list can be see when using admin.peers command. Please refer to the following figure for the specific process of three handshakes communication. If there is any error during the handshake process, the connection would fail, then it wait for a while before initiating another handshake communication.

connect

First handshake: The node generates authentication information and sends it to the counterpart.

Second handshake: Receives the authentication information from counterpart and use boe to sign (no signature is needed if without boe) and send it to the counterpart. Check whether the signature sent by the counterpart is used with boe signature. If it is not boe signature or the information of counterpart node is not in the hardware information table, the counterpart node is considered as a snode.

Third handshake: Updates the hardware information table.

After the above three steps, node A adds node B into its peer list. Similarly, node B also adds node A into its peer list. So far, the connection between node A and node B is successful and the node is added.

8 Node deletion

Nodes can be deleted in the way they are added. The following describes several situations in which the counterpart node is removed from the peers.

  1. Failure to verify genesis.
  2. In synchronizing data, when the block information sent by the counterpart is invalid, the connection would be actively cut off and the peer will be deleted.
  3. In network communication, when it fails to send or read data.
  4. When receiving a request for disconnection from the counterpart node.

9 Data Forwarding Rules

In P2P network of HPB main network, since each node is connected to other nodes as much as possible, in order to ensure the final consistency of data, each node is obliged to forward the data it generates or receives to other nodes.

There are two types of data forwarding. One is directional transmission, i.e. one-to-one, and the other is broadcast transmission, i.e. one-to-multiple.

a. Directional transmission: For example, in the node data synchronization, the requesting node and the sending node is one-to-one.

b. Broadcast transmission: For example, the node sends broadcast to all connected nodes after verification of new transaction and new block has passed. In order to save bandwidth, reduce data redundancy and improve the performance of public chain in HPB main network, the forwarding rules are optimized according to the node type. The rules are as follows:

For new transaction:

The present node is snode: transaction broadcasts cover pnode node and hnode node

The present node is pnode: transaction broadcasts cover pnode node and hnode node

The present node is hnode: transaction broadcasts cover hnode node.

For new block:

The current node is snode: no need to make new block broadcast.

The current node is pnode: new block broadcast covers pnode node and snode node.

The current node is hnode: new block broadcast covers hnode node and pnode node.

The above rules aims to reduce the forwarding number of new blocks generated by the high-performance node hnode so as to improve hnode performance.

10 Conclusion

The information above can be compared with other blockchains in the public chain. Take Ethereum as an example. These two are similar in P2P network. HPB has two different aspects in P2P network and it can be said that the adjustment is based on its own node features:

  1. The division of the node type, by adding boe signature and signature check in the three handshakes during node connection, it can judge whether the other node belongs to the synchronization node. If it is also a synchronization node, useless connection could be reduced.
  2. In terms of block broadcasting, each broadcast in Ethereum covers the square root node of pre-connection in the peer list. In the worst case, the block only covers few nodes while this would not happen to node type based broadcast in HPB.

The above is a brief introduction to P2P network in HPB main network.

Clone this wiki locally