Analyzing the Bitcoin Network: A Decentralized, Peer-to-Peer Network Architecture

Bitcoin adopts an Internet-based peer-to-peer (P2P: peer-to-peer) distributed network architecture.
The Bitcoin network can be thought of as a collection of nodes operating according to the Bitcoin P2P protocol.
This article analyzes the Bitcoin network to understand how it differs from the traditional centralized network and how the Bitcoin network discovers adjacent nodes.

centralized network

In order to better understand the P2P network, let's first look at the traditional centralized model:
Centralized network model

This is a typical star ("centralized") structure, which is the common B/S and C/S network architecture. There is no direct connection between C1, C2, C3, etc. If the C node wants to The connection must pass through the centralized S node as a bridge.
The centralized node acts as a service provider and an intermediary. For example, we cannot transfer funds directly from one person to another, but must go through the intermediary of a bank.

P2P network

A P2P network means that each computer in the same network is peered to each other, each node provides network services together, there is no "special" node, and each network node is connected to each other in a flat topology.
p2p network model

Compared with the centralized network, there is no server or centralized service in the P2P network.
The nodes of the P2P network are interactively connected and coordinated. While each node provides services to the outside world, it also uses the services provided by other nodes in the network. Each node is both a server and a client.
In addition to the P2P network model applied to the Bitcoin network, the widely used BT download is based on the P2P network.

The P2P network not only removes the risks brought by centralization (centralization may do evil), but also improves the efficiency of transmission. (Centralized network can also have advantages)

How to discover nodes

Since each network node is equal (meaning that the nodes are equal at the network level, but each node can have a different division of labor in functions, such as wallet nodes, mining nodes, etc.), there is no "special" center node, then when a new network node is started, how does it establish a connection with other nodes to join the Bitcoin network?

In a centralized network, newly joined nodes can join the network as long as they connect to a “special” central node.

In order to be able to join the Bitcoin network, a Bitcoin client will do several things:

  1. A node remembers the network node to which it was most recently successfully connected, and when restarted it can quickly reconnect with the previous network of peers.

  2. Nodes will try to discover new nodes when they lose existing connections.

  3. When one or more connections are established, a node sends a message containing its own IP address to its neighbors. The adjacent nodes then forward the message to their respective adjacent nodes in turn, thereby ensuring that the node information is received by multiple nodes and ensuring a more stable connection.

  4. A newly connected node can send a get-address getaddr message to its neighbors, asking them to return a list of IP addresses of their known peers. Nodes can find peers to connect to.

  5. When the node is started, an active node IP can be specified for the node. If not, the client also maintains a list of those nodes that are running stably for a long time. Such a node is also called a seed node (in fact, it is the same as the seed file downloaded by BT), and can quickly discover other nodes in the network through the seed node.

Node Communication Brief

Bitcoin nodes usually use the TCP protocol and use port 8333 to establish connections with adjacent nodes. When establishing a connection, there will also be a communication process of authentication "handshake", which is used to determine the protocol version, software version, node IP, block height, etc.

When a node is connected to an adjacent node, it then starts to synchronize blockchain data with the adjacent node (the lightweight wallet application does not actually synchronize all block data), and the nodes exchange a getblocks message, which contains the local block The hash value at the top of the chain. If a node recognizes that the hash value it receives does not belong to the top block, but belongs to an old block that is not the top block, its own local blockchain is said to be more powerful than the blockchains of other nodes. long, and tell other nodes that the block needs to be supplemented, other nodes send getdata messages to request blocks, and update them to the local blockchain after verification.

 

Explain the blockchain in simple terms  - learn blockchain systematically and create the best blockchain technology blog

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326322282&siteId=291194637