A brief introduction to the blockchain network layer

The blockchain network layer mainly realizes the distributed network mechanism through P2P technology. The network layer includes P2P networking mechanism, data dissemination mechanism and data verification mechanism. Therefore, the blockchain is essentially a P2P network with an automatic networking mechanism. , nodes maintain communication by maintaining a common blockchain structure.
There are mainly four different network models of P2P, which also represent four development stages of P2P technology: centralized, purely distributed, hybrid and structured models. However, it should be pointed out that the network model mentioned here mainly refers to the routing query structure, that is, how to establish a connection channel between different nodes. Once a connection is established between two nodes, what data is transmitted between the two nodes something happened.
The simplest routing method is centralized, that is, there is a central node that stores the index information of all other nodes. The index information generally includes node IP addresses, ports, and node resources. The advantages of centralized routing are simple structure and easy implementation. But the disadvantages are also obvious. Since the central node needs to store the routing information of all nodes, when the node scale expands, it is easy to have a performance bottleneck; and there is also a single point of failure problem.
insert image description here

The second routing structure is purely distributed. The central node is removed, and a random network is established between P2P nodes, that is, a connection channel is randomly established between a newly added node and a node in the P2P network, thus forming A random topology. There are many ways for a new node to join the network. The simplest is to randomly select an existing node and establish a neighbor relationship. Like Bitcoin, it uses DNS to query other nodes. DNS is generally hard-coded into the code. These DNS servers will provide a list of IP addresses of Bitcoin nodes, so that new nodes can find other nodes to establish connections aisle. After the new node establishes a connection with the neighbor node, it needs to broadcast the whole network to let the whole network know the existence of the node. The whole network broadcast method is that the node first broadcasts to the neighbor nodes, and after the neighbor nodes receive the broadcast message, they continue to broadcast to their own neighbor nodes, and so on, so as to broadcast to the entire network. This method of broadcasting is also known as the flooding mechanism. The purely distributed structure does not have the single-point performance bottleneck and single-point failure problems of the centralized structure, and has good scalability, but the flooding mechanism introduces new problems, mainly the problem of poor controllability, including two The bigger problem is that it is easy to form a flooding cycle. For example, the message sent by node A passes through node B to node C, and node C then broadcasts to node A, which forms a cycle; another thorny problem is to respond to message storms The problem is, if the resource that node A wants to request is owned by many nodes, then in a short period of time, a large number of nodes will send response messages to node A at the same time, which may cause node A to be paralyzed instantly.
insert image description here

Let's take a look at the third routing structure: hybrid. The hybrid type is actually a mixture of centralized and distributed structures. As shown in the figure below, there are multiple super nodes in the network to form a distributed network, and each super node has multiple ordinary nodes to form a local centralized network with it. When a new ordinary node joins, it first selects a super node for communication, and the super node then pushes a list of other super nodes to the newly joined node, and the joining node decides which specific super node to choose as the parent node according to the state of the super node in the list . The flood broadcast of this structure only occurs between super nodes, which can avoid the problems of large-scale flooding. In practical applications, the hybrid structure is a relatively flexible and effective networking architecture, and the implementation difficulty is relatively small. Therefore, many systems are currently developed and implemented based on the hybrid structure. In fact, the Bitcoin network also has this structure today, which will be elaborated later.
insert image description here

The last network is a structured P2P network, which is also a distributed network structure, but it is different from a purely distributed structure. A purely distributed network is a random network, while a structured network organizes all nodes in an orderly manner according to a certain structure, such as forming a ring network or a tree network. The specific implementation of the structured network is generally based on the idea of ​​DHT (Distributed Hash Table, Distributed Hash Table) algorithm. DHT just proposes a network model and does not involve specific implementation. It mainly wants to solve the problem of how to quickly and accurately route and locate data in a distributed environment. The specific implementation schemes include algorithms such as Chord, Pastry, CAN, and Kademlia. Among them, Kademlia is also the implementation algorithm of the Ethereum network. Many commonly used P2P applications such as BitTorrent and eDonkey also use Kademlia. Due to the limited space, the specific principles of these algorithms will not be discussed. At present, we only need to understand the core idea of ​​DHT.
In P2P network, two kinds of space can be abstracted: resource space and node space. The resource space is the collection of resources saved by all nodes, and the node space is the collection of all nodes. Number all resources and nodes separately, such as turning the resource name or content into a value with the Hash function (this is also a method commonly used by DHT), so that each resource has a corresponding ID, and each node also has a ID, a mapping relationship between resource ID and node ID is established, for example, if all the index information of resource n is stored on node n, then when searching for resource n, just find node n, thus avoiding the general Hong broadcasting can route and locate data more quickly and accurately. Of course, in practical applications, there is no one-to-one correspondence between resource IDs and node IDs, but because IDs are all numbers, there is a size relationship or a partial order relationship, etc. Based on these relationships, the mapping between the two can be established relation. This is the core idea of ​​DHT. The DHT algorithm uses a distributed hash table in the resource number and node number, so that the number of resource space and node space has uniqueness, uniform distribution and other good properties, which can meet the requirements of structured distributed networks.
To sum up, this is the theoretical basis of the P2P network. Different blockchains may use different network models, but the basic principles are the same. The two most representative blockchain networks are explained later: the Bitcoin network and the Ethereum network.

Guess you like

Origin blog.csdn.net/qq_41547320/article/details/130533278