From the point of view Java block chain Practice Series 3 - P2P Network: Bitcoin P2P network, all nodes, the node with the SPV Bloom Bloom filter

Network bits credits

Bitcoin network is a P2P network, the network nodes in different peer relationship to each other, each of the nodes may have different functions. Total is divided into four parts: node routing, database block chain, mining, wallet services.

Four functions: routing nodes, block chain database, mining, wallet services
Four functions: routing nodes, block chain database, mining, wallet services

 Node routing : mainly responsible for the verification and dissemination of transaction involved and block information, and to find and maintain a connection with the peer node;

Block chain database : keep a complete and current copy of the block chain data, these data can independently verify all transactions, without the need to borrow from any external reference;

Mining : proof (proof-of-work) algorithm by running workloads with competing ways to create a new block; (POW section we will detail in a consensus)

Wallet service : Provides key pair generation, signature transactions, transaction services related to broadcasting, etc. wallet; (About the key signature and the signature algorithm we will section details);

We usually say that the Bitcoin network, shall refer communications network running P2P protocol, in fact, Bitcoin network expansion also includes other special operating agreement. P2P network connected to many mineral and protocol gateway server pool, in such a manner that the operation of the other nodes connected protocol, such as cell ore stratum protocol network, early FIBER UDP-based relay networks.

Various types of nodes, gateways and network protocol extension bit credits
Extension bit credits display various network node types, and protocol gateways

Full node

This type of node contains all complete transaction data blocks network. In the early general block chain, all the nodes are all nodes, and are often maintained by the community to build. After a full node starts, the first thing need to do is to improve local block data, therefore, first of all it will interact with the access node last peer connections, and subsequently send getblocks request to receive the latest block data.

Here mention, some node will maintain a trading pits (some of the best public project will have a chain transaction pool), the role of the transaction cache pool is unconfirmed transaction, so that the user wallet node query has been received but not yet been confirmed, belong pre-payment information of the user's wallet. Some nodes also maintain a separate isolated trading pool , if a transaction with an unknown input transactions, such as transaction related to the loss of a parent, which is the parent transaction has not yet been packaged, the isolated transaction will be temporarily stored in isolated trading in the pool until the message reaches the parent transaction.

 

The whole process node synchronization blocks
Full node synchronization block from the search block chains peer

 

SPV light node

SPV called "Easy payment verification node" - "Simplified Payment Verification", was called node is light because he does not need to download the complete block of data is stored, you need only download area header, only the size of a full block 1000, currently as of 2020.3.30 complete data block size GB 314.40 .

Now, let's think about a problem, the whole node can verify UTXO be spent according to a complete block of data, then the SPV how should verify the transaction?

Simply put, SPV transactions in the chain's depth rather than height , to verify the transaction.

What is the depth and height of the block chain?

Height is the distance between the new block to block creation.

Depth, block number and refers to the latest exchange between the sum of the current block number block distance, Bitcoin block confirmation number 6, that is, when a deal was confirmed after six blocks essentially irreversible, and thus also avoiding the double flowers attacks. Corresponds to a depth that, in this transaction after the block and superimposed six blocks.

The deeper the block position in the block chain, the transaction may be changed less.

for example, A full node needs to examine a transaction block No. 300,000, it will start from 300,000 to creation block (Block 1) all linked together, build a UTXO library, and then confirm that the UTXO has been takes to verify the validity of UTXO.

Instead, SPV will use the UTXO information and it established a link between Merkle path block. Then, SPV node into a wait until the height of the block to reach 300,006 block, which is generated later six blocks, will prove the effectiveness of UTXO, can be used to take. According to the proxy gateway protocol, when the block is confirmed six times it is proved that the transaction is not double pay.

SPV will get Merkle path through the request and then by demonstrating and verifying block chain workload proof (mining verify) to determine the transaction is not real .

However, SPV although you can prove the existence of the sex trade, but can not prove whether the transaction is a double payment attack , because it has no record of all transactions.

In order to prevent such vulnerabilities, SPV need to connect multiple random peer nodes, in order to increase the probability of at least a reliable connection to the node, but this node connection means that SPV is also vulnerable to network partitioning attack and Sybil witch attack . (This article relates to block chain attack us will be introduced next one)

In most cases, have a good network connection is secure enough SPV, SPV node in general has been a trade-off between resource requirements, practicality and safety. Of course, if you need to ensure foolproof security, the most reliable way is to run a full node.

FIG lower, SPV node by transmitting a request to acquire getheaders header area, while SPV node in the process is also provided a filter.

SPV header node synchronization area
SPV header node synchronization area

 

Since the SPV and peer nodes getheaders interaction, it is also creating new privacy risks, SPV to address privacy risks by Bloom Bloom filter (us about privacy issues later).

Bloom filter

"Mastering bit credits" in the description of this channel: Bloom filter is to allow a user to describe a specific keyword combinations need not be precisely expressed filtering method based on probability. It allows users to protect their privacy at the same time effective search keywords. In SPV node where this method is used to transmit transaction information query request to a peer node, while the transaction address will not be exposed.

Bloom filter works

1, we have a first array of length N and M of the hash function, the hash function result of M between 1 ~ N, where each element in the array initially zero. Here to demonstrate a 16-bit array and three hash functions.

Bloom filter
Bloom filter structure

2, the process of adding a keyword, the keyword is a hash computation of M, respectively, results in an index, if the index position is 0, 1 is modified, or not change, N is provided to the array. Add keywords: "A".

Add keywords: "A"
Add keywords: "A"

 

Add keywords B
Add keywords: "B"

3, if the verification keys in the filter, it is far from the calculation result of the keyword hash of M, respectively, the array N to see if the corresponding bits are 1 is set, if all the keywords of a exist, or keyword does not exist. Next, we continue to add keywords: "B".

 

Verify that the keyword "X" already exists in the Bloom filter
Verify that the keyword "X" already exists in the Bloom filter

4, based on this design, when the entire array is set to 0, the error rate of the Bloom filter becomes extremely high. Nevertheless, it still can not cover up the Bloom filter in space utilization and query time outstanding aspects of time complexity insert data and data queries are O (M). SPV node Bloom filter is used bits coins, the Ethernet Square contract also has applications, such as targeting to find logs.

SPV Bloom filter how to use it?

SPV primarily through node key (including the address, key, hash) to tell the Bloom filters to transactions received from other nodes (including block information). Next we detail the entire process:

1, SPV node initializes an "empty" and "filter", it is empty if the filter will filter all available;

2, lists all the addresses, and hash keys SPV wallet;

3, this information is added as keywords to the Bloom filter, the filter will after the transaction Bloom filter based on these keywords;

4, SPV node to a peer node sends a request to load filteradd Bloom filter, and then send the message to obtain the desired getdata transactions;

5, peer filtering based on Bloom filter for every incoming transaction, content matching include: transaction ID, Bloom can filter the public key hash, script, OP_RETURN value, the signature of the public key, intelligent or complex contract any future component of the script (scripts in the signature section discussed in detail);

6, peer node in response to a request getdata, including: a message related merkleblock Tx transaction information, the message contains only the matched filter block and each matching transaction merkle path (discussed in the next section) of the header area;

7, SPV node receives a response message, will update the local wallet balances and UTXO set, then also modifies the Bloom filter, before repeating the process.

SPV privacy issues

SPV in order to ensure privacy, the address information does not tell the full Bloom filter, usually with partial address information as a key. In addition we can also guarantee privacy SPV node in the following ways:

1, encrypted connection authentication: Tor onion network transmission. If students understand the dark net may soon understand, here a brief introduction to the following. Tor anonymity network is to ensure that by way of a multi-layer proxy, and random untraceable online privacy, and provides encryption and data package, requesting the real server will need to break the layers of proxy servers, more if you want to track forwarding proxy server , the greater the difficulty of crack;

2, encrypted connection authentication: authentication and encryption and the like. Credits increased bit BIP-150 and two kinds of bit BIP-151 credits refinement of the P2P support authentication and encryption, BIP-150 before the authentication requirements, two established encryption communication nodes according BIP-151, we can With these two proposals to strengthen privacy protection of the SPV.

to sum up

In this section we introduce the concept of Bitcoin P2P network, after the introduction of the all-node, node SPV detailed, full node stores the complete data, and SPV node only partially saved header data block area, SPV node and to a certain extent not very safe, the Exchange will generally 2+ full node without using a separate node. Finally, we introduce the applications and solutions SPV privacy issues Bloom filter through which the concept of knowledge you will block chain "chain" have a certain understanding.

If you think this article have any shortcomings, welcome to comment! I will do my best to be perfect ~

 

references:

"Mastering Bitcoin Second Edition"

 

Published 21 original articles · won praise 11 · views 20000 +

Guess you like

Origin blog.csdn.net/weixin_38652136/article/details/105198046