BTC
ETH
HTX
SOL
BNB
View Market
简中
繁中
English
日本語
한국어
ภาษาไทย
Tiếng Việt

Popular Science: The Process of Bitcoin New Block Generation

闲话挖矿
特邀专栏作者
2020-07-07 02:45
This article is about 2939 words, reading the full article takes about 5 minutes
This is the second content of the blogger's mining popular science album. It follows the previous article "The Process of Bitcoin Transactions" and continues to analyze the whole process of Bitcoin transactions from initiation to confirmati
AI Summary
Expand
This is the second content of the blogger's mining popular science album. It follows the previous article "The Process of Bitcoin Transactions" and continues to analyze the whole process of Bitcoin transactions from initiation to confirmati

This is the second content of the blogger's mining popular science album, following the previous one"The Process of a Bitcoin Transaction", continue to see the whole picture of Bitcoin mining by analyzing the whole process of Bitcoin transactions from initiation to confirmation.

exist

exist"The Process of a Bitcoin Transaction"In the first article, we already know how the transaction information of Bitcoin is structured, but how does this information enter the new block of Bitcoin?

Next, the blogger will explain how the Bitcoin block records and confirms transaction information through the process of generating a new Bitcoin block.

transaction pool

transaction pool, English name: mempool, also called memory pool, is used to store transactions to be confirmed. Each Bitcoin mining node has its own independent transaction pool. Due to the size of the transaction pool, the minimum transaction fee ratio (the The fee ratio is the handling fee included in the transaction per unit volume, and the unit is Sat/B, that is, the handling fee for each B-byte transaction is x Satoshi bitcoin, the same below). The transaction pool of each node is different due to different restrictions. Miners (mining pools) need to select transactions to be packaged from the transaction pool when constructing a preliminary block. Since the transaction pool is often called, its data is stored in the RAM of the node server, which means that the volume of the transaction pool will not be too large.

mining node, in the Bitcoin network, participating in the recording and verification of Bitcoin transactions and blocks is a node that saves Bitcoin data. Some of these nodes not only participate in the recording and verification work, but also participate in the creation of new Bitcoin blocks. They construct new blocks and compete for bookkeeping rights through PoW workload proof, and then obtain the authority to create new blocks. These nodes is a mining node. Early mining nodes had miners and mining pools, but currently, due to the high difficulty of Bitcoin mining, it is difficult for a single miner to win the right to bookkeeping and create new blocks. At present, the main Bitcoin mining nodes are mining pools, such as F2Pool, Poolin, BTC.com, Antpool, Slushpool, etc.

UTXO library, the Bitcoin node constructs a UTXO cluster by scanning all transaction information of the node. It contains all unspent UTXOs. Whenever a new block is generated, the UTXO library will delete the UTXO consumed in the new block from its own list, and add the newly generated UTXO to its own list.

Coinbase Rewardssecondary title

Transactions to be confirmed will first enter the transaction pool

When we want to initiate a Bitcoin transaction, the transaction initiator constructs the transaction information, and the transaction information at this time is the transaction to be confirmed, which includesTransaction input information(unspent UTXO signed with correct private key) andTransaction output information(Pending confirmation UTXO to lock the new wallet address).

image description

Figure 1 Transactions to be confirmed enter the transaction pool

Transaction information that needs to be verified includes:

  • Whether the transaction contains valid input and output wallet addresses;

  • Whether the transaction volume is smaller than the maximum volume of the block (the maximum volume of the Bitcoin block is currently 1M);

  • Whether the input UTXO is legal (compared with the UTXO library of the node, the input UTXO has not been used);

  • Whether the total input and output of the transaction are reasonable (total input ≥ total output);

  • Judging whether the input of the transaction has a reward from Coinbase, the currency corresponding to the reward must have at least 100 block confirmations before it can be used;

  • Confirm that there are no duplicate transactions in the transaction pool;

  • secondary title

The mining node selects transactions from the transaction pool and constructs a preliminary block

When the mining node wants to construct a preliminary block and prepare to generate a new block, it will sort the transaction according to the priority and take the transaction to be confirmed from the transaction pool. The reserve block usually reserves a certain space for high-priority transactions, and the remaining space will be used to fill up the block or use up the transactions in the transaction pool according to the transaction fee ratio (Sat/B) from high to low.

image description

in,

in,"Magic number"is a constant whose value is 0xD9B4BEF9;"block size"is the total volume of all data in this block;"block header"It can be regarded as the abbreviated information of the entire block, and the block information used for mining is the block header;"Transaction Counter"Used to record the number of transactions in the block;"Transaction Data"It is all the transaction information contained in the block, including the Coinbase reward part. Generally speaking, this part of data occupies most of the space of the entire block.

In a Bitcoin block, the block header is the most critical piece of information. It contains all characteristic information of the entire block:

  • block version number. The version information of the Bitcoin node that created the block is used to track the upgrade and update of the Bitcoin protocol;

  • Hash of the previous block. Also known as the parent block hash, it is used to locate the previous block. Each block contains the hash value of its previous block, and any slight change to any block will cause a huge change in the hash value of subsequent blocks, so interlocking, ensuring All Bitcoin blocks form a single chain structure, which can effectively prevent malicious tampering of Bitcoin block data.

  • MerkleRoot hashimage description

    Figure 3 Merkle tree structure of transaction data

    timestamp

  • timestamp. The time to create the preparatory block.

  • current target hashrandom number

  • random number. Also called Nonce. We can find that in the block header information, the block version number, the hash value of the previous block, the MerkleRoot hash value, the timestamp, and the current target hash are all known information, relatively fixed, and inconvenient to change at will. Therefore, if you want to adjust the hash value of the preparatory block, you need to introduce a variable data - random number. By modifying the random number, the hash value of the preparatory block can be adjusted.

After the mining node builds the preparatory block, it will send the block header information to the miners. The miners change the hash value of the preparatory block by continuously adjusting the random number in the block header. When the hash value of the preparatory block is low At the current target hashrate of the Bitcoin network, this block is a legitimate new block.

References:

References:

  • Bitcoin source code analysis

  • Bitcoin block header structure analysis:

  • bitcoin target hashrate

  • Bitcoin block structure

  • Mastering Bitcoin

PoW
BTC
矿业