详解比特币挖矿原理

资讯 2024-07-04 阅读:51 评论:0
很多人知道比特币,区块链。但是整个网络是怎么保证这个去中心化的?可能很多人并不了解,或者说想了解但是不知道从何入手。其实从挖矿这个角度去理解区块链会更能抓住重点,了解了挖矿,你就了解了区块链,了解了去中心化。 可以将区块链看作一本...
美化布局示例

欧易(OKX)最新版本

【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   全球官网 大陆官网

币安(Binance)最新版本

币安交易所app【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址

火币HTX最新版本

火币老牌交易所【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址
很多人知道比特币,区块链。但是整个网络是怎么保证这个去中心化的?可能很多人并不了解,或者说想了解但是不知道从何入手。其实从挖矿这个角度去理解区块链会更能抓住重点,了解了挖矿,你就了解了区块链,了解了去中心化。

可以将区块链看作一本记录所有交易的公开总帐簿(列表),比特币网络中的每个参与者都把它看作一本所有权的权威记录。

The block chain can be seen as a public ledger (list) that records all transactions, and every participant in the Bitcoin network sees it as an authoritative record of ownership.

比特币没有中心机构,几乎所有的完整节点都有一份公共总帐的备份,这份总帐可以被视为认证过的记录。

Bitcoin does not have a central institution, and almost all the full nodes are backed up by a public ledger, which can be considered a certified record.

至今为止,在主干区块链上,没有发生一起成功的攻击,一次都没有。

So far, no successful attack has occurred on the main block chain.

通过创造出新区块,比特币以一个确定的但不断减慢的速率被铸造出来。大约每十分钟产生一个新区块,每一个新区块都伴随着一定数量从无到有的全新比特币。每开采210,000个块,大约耗时4年,货币发行速率降低50%。

By creating new blocks, Bitcoin was forged at a fixed but declining rate. Every new block is created about every ten minutes, with a certain amount of completely new bitcoins. For every 210,000 pieces, it takes about four years for the currency to be released 50% less.

在2016年的某个时刻,在第420,000个区块被“挖掘”出来之后降低到12.5比特币/区块。在第13,230,000个区块(大概在2137年被挖出)之前,新币的发行速度会以指数形式进行64次“二等分”。到那时每区块发行比特币数量变为比特币的最小货币单位——1聪。最终,在经过1,344万个区块之后,所有的共20,999,999.9769亿聪比特币将全部发行完毕。换句话说,到2140年左右,会存在接近2,100万比特币。在那之后,新的区块不再包含比特币奖励,矿工的收益全部来自交易费。

At some point in 2016, after 420,000 blocks were “excavated”, they were reduced to 12.5 bits/blocks. Before the 13,230,000 blocks (which were presumably dug out in 2137), the rate of distribution of the new currency would be 64 “seconds” in index form. By that time, the number of bits issued per block would become the smallest currency unit of bitcoin — one hearing. Eventually, after 13.44 million blocks, all 20,999,997,769 million pieces of money would have been released. In other words, by around 2140, nearly 21 million bits of currency would have existed.

比特币的去中心化共识由所有网络节点的4种独立过程相互作用而产生:
· 每个全节点依据综合标准对每个交易进行独立验证
· 通过完成工作量证明算法的验算,挖矿节点将交易记录独立打包进新区块,
· 每个节点独立的对新区块进行校验并组装进区块链
· 每个节点对区块链进行独立选择,在工作量证明机制下选择累计工作量最大的区块链

一、独立验证

在收到交易后,每一个节点都会在全网广播前对这些交易进行校验,并以接收时的相应顺序,为有效的新交易建立一个池(交易池)。

Upon receipt of the transaction, each node verifies the transaction prior to broadcasting on the Internet and establishes a pool (trading pool) of valid new transactions in the order in which they are received.

每一个节点在校验每一笔交易时,都需要对照一个长长的标准列表:

Each node is checked against a long standard list:

交易的语法和数据结构必须正确。

The syntax and data structure of the transaction must be correct.

输入与输出列表都不能为空。

Neither input nor output list can be empty.

交易的字节大小是小于MAX_BLOCK_SIZE的。

The byte size of the transaction is less than MAX_BLONK_SIZE.

每一个输出值,以及总量,必须在规定值的范围内 (小于2,100万个币,大于0)。

Each output value, as well as the total quantity, must be within the range of the specified value (less than 21 million currency and greater than 0).

没有哈希等于0,N等于-1的输入(coinbase交易不应当被中继)。

No Hashi equals 0 and N equals 1 input (coinbase transactions should not be repeated).

nLockTime是小于或等于INT_MAX的。

nLockTime is less than or equal to INT_MAX.

交易的字节大小是大于或等于100的。

The byte size of the transaction is greater than or equal to 100.

交易中的签名数量应小于签名操作数量上限。

The number of signatures in transactions should be less than the maximum number of signature operations.

解锁脚本(Sig)只能够将数字压入栈中,并且锁定脚本(Pubkey)必须要符合isStandard的格式 (该格式将会拒绝非标准交易)。

Unlocking Script (Sig) can only press numbers into the pad, and locking in the script (Pubkey) must be in the form of IsStedard (this format will reject non-standard transactions).

池中或位于主分支区块中的一个匹配交易必须是存在的。

Matching transactions in the pool or in one of the main branch blocks must exist.

对于每一个输入,如果引用的输出存在于池中任何的交易,该交易将被拒绝。

For each input, if the quoted output exists for any transaction in the pool, the transaction will be rejected.

对于每一个输入,在主分支和交易池中寻找引用的输出交易。如果输出交易缺少任何一个输入,该交易将成为一个孤立的交易。如果与其匹配的交易还没有出现在池中,那么将被加入到孤立交易池中。

For each input, look for the quoted export transaction in the main branch and the trading pool. If an output transaction lacks any input, the transaction becomes an isolated transaction. If the matching transaction does not appear in the pool, it will be added to the isolated trading pool.

对于每一个输入,如果引用的输出交易是一个coinbase输出,该输入必须至少获得COINBASE_MATURITY (100)个确认。

For each input, if the quoted output transaction is a coinbase output, the input must be confirmed at least by COINBASE_MATURTY(100).

对于每一个输入,引用的输出是必须存在的,并且没有被花费。

For each input, the quoted output must exist and is not spent.

使用引用的输出交易获得输入值,并检查每一个输入值和总值是否在规定值的范围内 (小于2100万个币,大于0)。

uses the quoted output transaction to obtain input values and check whether each input value and total value is within the range specified (less than 21 million currency and greater than 0 currency).

如果输入值的总和小于输出值的总和,交易将被中止。

If the sum of the input value is less than the sum of the output value, the transaction will be suspended.

如果交易费用太低以至于无法进入一个空的区块,交易将被拒绝。

If transaction costs are too low to allow access to an empty block, the transaction will be rejected.

每一个输入的解锁脚本必须依据相应输出的锁定脚本来验证。

Each input unlocking script must be verified on the basis of the locking foot of the corresponding output.


二、将交易记录独立打包进新区块

以下挖矿节点取名为A挖矿节点

The following excavated node is named A excavated node

挖矿节点时刻监听着传播到比特币网络的新区块。而这些新加入的区块对挖矿节点有着特殊的意义。矿工间的竞争以新区块的传播而结束,如同宣布谁是最后的赢家。对于矿工们来说,获得一个新区块意味着某个参与者赢了,而他们则输了这场竞争。然而,一轮竞争的结束也代表着下一轮竞争的开始。

For miners, acquiring a new block means that one of the participants wins, and they lose the competition. However, the end of the round also represents the beginning of the next round.

验证交易后,比特币节点会将这些交易添加到自己的内存池中。内存池也称作交易池,用来暂存尚未被加入到区块的交易记录。

After validates the transactions, the Bitcoin node adds them to its own memory pool. The memory pool is also known as the trading pool and is used to store records of transactions that have not yet been added to a block.

2.1 交易块龄,矿工费和优先级

A节点需要为内存池中的每笔交易分配一个优先级,并选择较高优先级的交易记录来构建候选区块。

Node A needs to assign a priority to each transaction in the memory pool and select a higher priority transaction log to build a candidate block.

一个交易想要成为“较高优先级”,需满足的条件:优先值大于57,600,000,这个值的生成依赖于3个参数:一个比特币(即1亿聪),年龄为一天(144个区块),交易的大小为250个字节:

A transaction is intended to be a “higher priority” condition to be met: the priority value is greater than 57.6 million, and the value is generated on three parameters: a bitcoin (i.e. 100 million ears), a day old (144 blocks), and a transaction size of 250 bytes:

High Priority > 100,000,000 satoshis * 144 blocks / 250 bytes=57,600,000

区块中用来存储交易的前50K字节是保留给较高优先级交易的。节点在填充这50K字节的时候,会优先考虑这些最高优先级的交易,不管它们是否包含了矿工费。这种机制使得高优先级交易即便是零矿工费,也可以优先被处理。

The first 50 K bytes used to store transactions in blocks are reserved for higher priority transactions. When filling the 50K bytes, the nodes give priority to these top priority transactions, whether or not they include miners’ fees. This mechanism allows high priority transactions to be treated as priority even for petty miners’ fees.

然后,A挖矿节点会选出那些包含最小矿工费的交易,并按照“每千字节矿工费”进行排序,优先选择矿工费高的交易来填充剩下的区块。

Digger Node A then selects those transactions that include minimal miners' fees and prioritizes them according to the “per kilobyte miners' fees” to fill the remaining blocks with high miners' fees.

如区块中仍有剩余空间,A挖矿节点可以选择那些不含矿工费的交易。有些矿工会竭尽全力将那些不含矿工费的交易整合到区块中,而其他矿工也许会选择忽略这些交易。

If there is still room in blocks, point A digs can choose those transactions that do not include miners’ fees. Some mining unions do their best to integrate those that do not include miners’ fees into the blocks, while others may choose to ignore them.

在区块被填满后,内存池中的剩余交易会成为下一个区块的候选交易。因为这些交易还留在内存池中,所以随着新的区块被加到链上,这些交易输入时所引用UTXO的深度(即交易“块龄”)也会随着变大。由于交易的优先值取决于它交易输入的“块龄”,所以这个交易的优先值也就随之增长了。最后,一个零矿工费交易的优先值就有可能会满足高优先级的门槛,被免费地打包进区块。

When blocks are filled, the remaining transactions in the memory pool will be a candidate for the next block. As these transactions remain in the memory pool, as new blocks are added to the chain, the depth of the UTXO (i.e., the “block age” of the transaction) cited when entering into the transaction will also grow. Since the priority value of the transaction depends on the “block age” of the transaction, the priority value of the transaction increases.

UTXO(Unspent Transaction Output) : 每笔交易都有若干交易输入,也就是资金来源,也都有若干笔交易输出,也就是资金去向。一般来说,每一笔交易都要花费(spend)一笔输入,产生一笔输出,而其所产生的输出,就是“未花费过的交易输出”,也就是 UTXO。

UTXO (Unspent Transport Output): Each transaction has a number of transaction inputs, i.e. the source of funds, and a number of transaction outputs, i.e. the destination of the funds. In general, each transaction costs a single input, producing an output, and the output is an “unspent transaction output”, i.e. UTXO.

块龄:UTXO的“块龄”是自该UTXO被记录到区块链为止所经历过的区块数,即这个UTXO在区块链中的深度。

Block age: UTXO's “block age” is the number of blocks experienced since the UTXO was recorded in the block chain, i.e. the depth of the UTXO in the block chain.

2.2 创币交易

区块中的第一笔交易是笔特殊交易,称为创币交易或者coinbase交易。这个交易是由挖矿节点构造并用来奖励矿工们所做的贡献的。假设此时一个区块的奖励是25比特币,A挖矿的节点会创建“向A的地址支付25.1个比特币(包含矿工费0.1个比特币)”这样一个交易,把生成交易的奖励发送到自己的钱包。A挖出区块获得的奖励金额是coinbase奖励(25个全新的比特币)和区块中全部交易矿工费的总和。

The first deal in a block is a special transaction called a coin deal or a coinbase deal. This transaction is constructed by a mining node and is used to reward the miners for their contribution. Assuming that one block is rewarded by 25 bitcoins, the node of A digs will create a transaction of “payment of 25.1 bitcoins (including 0.1 bitcoins for miners) to the address of A” and send the incentive to generate the transaction to its wallet. The incentive to dig block A is the sum of the coinbase reward (25 brand-new bitcoins) and the entire transaction fee for miners in blocks
.



三、构造区块

A节点已经构建了一个候选区块,那么就轮到A的矿机对这个新区块进行“挖掘”,求解工作量证明算法以使这个区块有效。比特币挖矿过程使用的是SHA256哈希函数。

Node A has built a candidate block, so it is the mine's turn to A to “excavate” the new block, and the solver's workload proves the algorithm to make the block effective. Bitcoin digs using the SHA256 Hashi function.

用最简单的术语来说,挖矿节点不断重复进行尝试,直到它找到的随机调整数使得产生的哈希值低于某个特定的目标。哈希函数的结果无法提前得知,也没有能得到一个特定哈希值的模式。举个例子,你一个人在屋里打台球,白球从A点到达B点,但是一个人推门进来看到白球在B点,却无论如何是不知道如何从A到B的。哈希函数的这个特性意味着:得到哈希值的唯一方法是不断的尝试,每次随机修改输入,直到出现适当的哈希值。

In the simplest terms, excavated nodes are constantly repeated until they find random adjustments that make the Hashi value lower than a given target. The results of the Hashi function are not known in advance, nor is it able to obtain a specific pattern of Hashi. By way of example, you play billiards alone in the house, white balls reach point B from point A, but one pushes in to see white balls at point B, but in any case does not know how to move from A to B. This feature of the Hashi function means that the only way to get Hashi value is to keep trying, every randomly modifying input until the appropriate Hashi value appears.

需要以下参数

The following parameters are required

? block的版本 version

? Block's version Version

? 上一个block的hash值: prev_hash

?

? 需要写入的交易记录的hash树的值: merkle_root

The value of the ash tree that needs to be written into the transaction record: merkle_root

? 更新时间: ntime

Update: ntime

? 当前难度: nbits

Current difficulty: nbits

挖矿的过程就是找到x使得

The process of mining is to find x to make

SHA256(SHA256(version + prev_hash + merkle_root + ntime + nbits + x )) < TARGET

上式的x的范围是0~2^32, TARGET可以根据当前难度求出的。

The range of x above is zero to two to thirty-two, and TARGET can be found on the basis of the current difficulty.

简单打个比方,想象人们不断扔一对色子以得到小于一个特定点数的游戏。第一局,目标是12。只要你不扔出两个6,你就会赢。然后下一局目标为11。玩家只能扔10或更小的点数才能赢,不过也很简单。假如几局之后目标降低为了5。现在有一半机率以上扔出来的色子加起来点数会超过5,因此无效。随着目标越来越小,要想赢的话,扔色子的次数会指数级的上升。最终当目标为2时(最小可能点数),只有一个人平均扔36次或2%扔的次数中,他才能赢。

A simple analogy, imagines that people keep throwing a pair of colours to get a game smaller than a given number of points. In the first round, target 12. If you don't throw two six, you win. And in the next round, goal 11. Players can only win with 10 or smaller points, but it's easy. If after a few rounds, the goal is reduced to five. Now, half the odds are thrown with more than five points, so it's not valid. As the target gets smaller, the number of times you throw the color increases exponentially. In the end, when the target is 2 (minimum possible points), only one person throws an average of 36 or 2 per cent of the times, he wins.

3.1 难度的调整

如前所述,目标决定了难度,进而影响求解工作量证明算法所需要的时间。那么问题来了:为什么这个难度值是可调整的?由谁来调整?如何调整?

As noted earlier, the objective determines the difficulty, which in turn affects the time needed to solve the workload proof algorithm. So the question arises: Why is this difficulty value adjustable? Who will adjust it? How?

比特币的区块平均每10分钟生成一个。这就是比特币的心跳,是货币发行速率和交易达成速度的基础。不仅是在短期内,而是在几十年内它都必须要保持恒定。在此期间,计算机性能将飞速提升。此外,参与挖矿的人和计算机也会不断变化。为了能让新区块的保持10分钟一个的产生速率,挖矿的难度必须根据这些变化进行调整。事实上,难度是一个动态的参数,会定期调整以达到每10分钟一个新区块的目标。简单地说,难度被设定在,无论挖矿能力如何,新区块产生速率都保持在10分钟一个。

This is the heart beat of Bitcoin, which is the basis for the speed of currency distribution and the speed of transactions. It must be constant not only in the short term, but for decades. During this period, computer performance will increase rapidly. Moreover, people and computers involved in mining will change. In order to keep the new blocks up to 10 minutes of production, the difficulty of digging must be adjusted to these changes. In fact, the difficulty is a dynamic parameter that is regularly adjusted to reach the goal of a new block every 10 minutes. Simply put, the difficulty is set at 10 minutes of production regardless of the mining capacity.

那么,在一个完全去中心化的网络中,这样的调整是如何做到的呢?难度的调整是在每个完整节点中独立自动发生的。每2,016个区块(2周产生的区块)中的所有节点都会调整难度。难度的调整公式是由最新2,016个区块的花费时长与20,160分钟(两周,即这些区块以10分钟一个速率所期望花费的时长)比较得出的。难度是根据实际时长与期望时长的比值进行相应调整的(或变难或变易)。简单来说,如果网络发现区块产生速率比10分钟要快时会增加难度。如果发现比10分钟慢时则降低难度。

So, in a completely decentralised network, how is this adjustment possible? The difficulty adjustment occurs independently and automatically in each complete node. Every node of 2,016 blocks (2 weeks) is adjusted for difficulty. The difficulty adjustment formula is a comparison of the last 2,016 blocks with 20,160 minutes (two weeks, that is, the amount of time they are expected to be spent at a rate of 10 minutes). The difficulty is a function of the actual length of time adjusted to the expected length of time.

为了防止难度的变化过快,每个周期的调整幅度必须小于一个因子(值为4)。如果要调整的幅度大于4倍,则按4倍调整。由于在下一个2,016区块的周期不平衡的情况会继续存在,所以进一步的难度调整会在下一周期进行。因此平衡哈希计算能力和难度的巨大差异有可能需要花费几个2,016区块周期才会完成。

In order to prevent difficulty from changing too quickly, the range of adjustments per cycle must be less than one factor (value 4. If the adjustment is more than four times greater, the adjustment should be four times more. Since the imbalance in the next 2,016 blocks will continue, further difficulty adjustments will take place in the next cycle.

3.2 成功构建区块

举个例子,当前A节点在挖277,316个区块,A挖矿节点一旦完成计算,立刻将这个区块发给它的所有相邻节点。这些节点在接收并验证这个新区块后,也会继续传播此区块。当这个新区块在网络中扩散时,每个节点都会将它作为第277,316个区块(父区块为277,315)加到自身节点的区块链副本中。当挖矿节点收到并验证了这个新区块后,它们会放弃之前对构建这个相同高度区块的计算,并立即开始计算区块链中下一个区块的工作。

For example, node A currently digs 277,316 blocks, and once the node A excavates, once calculated, distributes the block to all its adjacent nodes. These nodes also continue to spread the block after receiving and validating the new block. When the new block spreads through the network, each node adds it as a copy of its 277,316 blocks (277,315) to its own node. When the node digs receive and authenticate the new node, they abandon the calculation of the building of the same high block and immediately begin the calculation of the next block in the block chain.

3.3 校验新区块

比特币共识机制的第三步是通过网络中的每个节点独立校验每个新区块。当新区块在网络中传播时,每一个节点在将它转发到其节点之前,会进行一系列的测试去验证它。这确保了只有有效的区块会在网络中传播。

The third step of the Bitcoin Consensus mechanism is to independently verify each new block through each node in the network. When a new block is distributed in the network, each node conducts a series of tests to verify it before it is forwarded to its node. This ensures that only valid blocks are disseminated in the network.

每一个节点对每一个新区块的独立校验,确保了矿工无法欺诈。在前面的章节中,我们看到了矿工们如何去记录一笔交易,以获得在此区块中创造的新比特币和交易费。为什么矿工不为他们自己记录一笔交易去获得数以千计的比特币?这是因为每一个节点根据相同的规则对区块进行校验。一个无效的coinbase交易将使整个区块无效,这将导致该区块被拒绝,因此,该交易就不会成为总账的一部分。

Each node's independent verification of each new block ensures that the miners are not fraudulent. In the preceding chapter, we see how miners can record a transaction to get the new bitcoins and the transaction fees created in this block. Why don't miners record a transaction for themselves to get thousands of bitcoins? This is because each node verifies the block according to the same rules. An invalid coinbase deal would render the whole block ineffective, which would result in the block being rejected, so that the transaction would not be part of the ledger.


四、区块链的组装与选择

比特币去中心化的共识机制的最后一步是将区块集合至有最大工作量证明的链中。一旦一个节点验证了一个新的区块,它将尝试将新的区块连接到到现存的区块链,将它们组装起来。

The final step of the consensus mechanism for the centralization of Bitcoin is to assemble blocks into a chain with maximum workload proof. Once a node has validated a new block, it will attempt to connect new blocks to the existing chain of blocks and assemble them.

节点维护三种区块:

Node maintains three blocks:


· 第一种是连接到主链上的,

The first is connected to the main chain, .


· 第二种是从主链上产生分支的(备用链),

. The second is to produce branches from the main chain (back-up chain), .


· 第三种是在已知链中没有找到已知父区块的。

. The third is that no known parent blocks have been found in the known chain.

有时候,新区块所延长的区块链并不是主链,这一点我们将在下面“ 区块链分叉”中看到。

Sometimes the chain of blocks extended by the new blocks is not the main chain, as we will see below in the “block chain fork”.

如果节点收到了一个有效的区块,而在现有的区块链中却未找到它的父区块,那么这个区块被认为是“孤块”。孤块会被保存在孤块池中,直到它们的父区块被节点收到。一旦收到了父区块并且将其连接到现有区块链上,节点就会将孤块从孤块池中取出,并且连接到它的父区块,让它作为区块链的一部分。当两个区块在很短的时间间隔内被挖出来,节点有可能会以相反的顺序接收到它们,这个时候孤块现象就会出现。

If node receives a valid block and does not find its parent in the existing block chain, the block is considered to be “separated”. The node is preserved in the pool until its parent block is received by the node. Once it is received and connected to the existing node, the node is removed from the pool and connected to its parent block as part of the chain. When the two blocks are dug up at very short intervals, the node is likely to receive them in the opposite order, the node will then appear.

选择了最大难度的区块链后,所有的节点最终在全网范围内达成共识。随着更多的工作量证明被添加到链中,链的暂时性差异最终会得到解决。挖矿节点通过“投票”来选择它们想要延长的区块链,当它们挖出一个新块并且延长了一个链,新块本身就代表它们的投票。

After selecting the most difficult block chains, all nodes eventually reach a consensus on the whole web. As more workload proves to be added to the chain, the temporary differences in the chain will eventually be resolved. The mining nodes choose by “voting” the chain of blocks they want to extend, and when they dig a new block and extend a chain, the new node itself represents their vote.

区块链分叉

因为区块链是去中心化的数据结构,所以不同副本之间不能总是保持一致。区块有可能在不同时间到达不同节点,导致节点有不同的区块链视角。解决的办法是,每一个节点总是选择并尝试延长代表累计了最大工作量证明的区块链,也就是最长的或最大累计难度的链。

Because the block chain is a decentralised data structure, there is no consistency between the different copies. Blocks may reach different nodes at different times, leading to different nodes with different block chain perspectives. The solution is that each node of always selects and attempts to extend the chain of blocks that represents the maximum amount of work to prove, that is, the longest or maximum difficulty to accumulate.

当有两个候选区块同时想要延长最长区块链时,分叉事件就会发生。正常情况下,分叉发生在两名矿工在较短的时间内,各自都算得了工作量证明解的时候。两个矿工在各自的候选区块一发现解,便立即传播自己的“获胜”区块到网络中,先是传播给邻近的节点而后传播到整个网络。每个收到有效区块的节点都会将其并入并延长区块链。如果该节点在随后又收到了另一个候选区块,而这个区块又拥有同样父区块,那么节点会将这个区块连接到候选链上。其结果是,一些节点收到了一个候选区块,而另一些节点收到了另一个候选区块,这时两个不同版本的区块链就出现了。

When two candidate blocks simultaneously want to extend the maximum block chain, the fork event occurs. Normally, the fork happens when the two miners are able to account for their workload in a relatively short period of time. As soon as the two miners solve their respective candidate blocks, they spread their own “winner” blocks to the network, first to a nearby node, and then to the entire network. Each node to which the valid block is received integrates and extends the node. If the node receives another node at a later stage, and the block has the same parent block, the node links the block to the node. As a result, some nodes receive one node, while others receive another node, and two different versions of the nodes appear.

分叉之前

before the fork

分叉开始

Forks to start

我们看到两个矿工几乎同时挖到了两个不同的区块。为了便于跟踪这个分叉事件,我们设定有一个被标记为红色的、来自加拿大的区块,还有一个被标记为绿色的、来自澳大利亚的区块。

We saw two miners digging up almost two different blocks at the same time. To facilitate the tracking of this fork, we set up a red block from Canada and a green block from Australia.

假设有这样一种情况,一个在加拿大的矿工发现了“红色”区块的工作量证明解,在“蓝色”的父区块上延长了块链。几乎同一时刻,一个澳大利亚的矿工找到了“绿色”区块的解,也延长了“蓝色”区块。那么现在我们就有了两个区块:一个是源于加拿大的“红色”区块;另一个是源于澳大利亚的“绿色”。这两个区块都是有效的,均包含有效的工作量证明解并延长同一个父区块。这个两个区块可能包含了几乎相同的交易,只是在交易的排序上有些许不同。

Assuming that there is a situation where a miner in Canada discovers a “red” block of work that proves that the chain has been extended on the “Blue” parent block. Almost the same time, an Australian miner has found a “green” block that has also extended the “Blue” block. Now we have two blocks: a “red” block from Canada; and a “green” block from Australia. Both blocks are valid and contain valid workload proof that the same parent block has been removed and extended.

分叉导致网络分裂

比特币网络中邻近(网络拓扑上的邻近,而非地理上的)加拿大的节点会首先收到“红色”区块,并建立一个最大累计难度的区块,“红色”区块为这个链的最后一个区块(蓝色-红色),同时忽略晚一些到达的“绿色”区块。相比之下,离澳大利亚更近的节点会判定“绿色”区块胜出,并以它为最后一个区块来延长区块链(蓝色-绿色),忽略晚几秒到达的“红色”区块。那些首先收到“红色”区块的节点,会即刻以这个区块为父区块来产生新的候选区块,并尝试寻找这个候选区块的工作量证明解。同样地,接受“绿色”区块的节点会以这个区块为链的顶点开始生成新块,延长这个链。

By contrast, the node near the Bitcoin network (neighbour on top of the network, not geographically) would first receive a “red” block and create one of the most cumulatively difficult blocks, the “red” block being the last of the chain (blue-red), while ignoring the late arrival of the “green” block. By contrast, the node closer to Australia would determine that the “green” block would win, and use it as the last block to extend the chain (blue-green), ignoring the red block that arrives a few seconds later. The node that first receives the red block would carve it as a parent block to produce a new candidate block and attempt to find proof of the workload of the node. Similarly, the node accepting the “green” block would begin to generate a new block by using it as the top of the chain, extending the chain.

新区块延长了分支

分叉问题几乎总是在一个区块内就被解决了。网络中的一部分算力专注于“红色”区块为父区块,在其之上建立新的区块;另一部分算力则专注在“绿色”区块上。即便算力在这两个阵营中平均分配,也总有一个阵营抢在另一个阵营前发现工作量证明解并将其传播出去。在这个例子中我们可以打个比方,假如工作在“绿色”区块上的矿工找到了一个“粉色”区块延长了区块链(蓝色-绿色-粉色),他们会立刻传播这个新区块,整个网络会都会认为这个区块是有效的,如上图所示。

The fork problem is almost always solved in one block. Some of the algorithms in the network focus on the “red” block being the parent block, with new blocks built on it; the other part concentrates on the “green” block. Even if the algorithms are evenly distributed between the two camps, there is always a field where the workload proves to be solved and spreads out before the other camp. In this example, if the miners working on the “green” block find a “gold” block that extends the chain (blue-green-colour), they will immediately disseminate the new block, which the entire network will consider effective, as shown in the
above.

重新共识

所有在上一轮选择“绿色”区块为胜出者的节点会直接将这条链延长一个区块。然而,那些选择“红色”区块为胜出者的节点现在会看到两个链:“蓝色-绿色-粉色”和“蓝色-红色”。如上图所示,这些节点会根据结果将“蓝色-绿色-粉色”这条链设置为主链,将“蓝色-红色”这条链设置为备用链。这些节点接纳了新的更长的链,被迫改变了原有对区块链的观点,这就叫做链的重新共识。因为“红”区块做为父区块已经不在最长链上,导致了他们的候选区块已经成为了“孤块”,所以现在任何原本想要在“蓝色-红色”链上延长区块链的矿工都会停下来。全网将“蓝色-绿色-粉色”这条链识别为主链,“粉色”区块为这条链的最后一个区块。全部矿工立刻将他们产生的候选区块的父区块切换为“粉色”,来延长“蓝色-绿色-粉色”这条链。

All the nodes that selected the “green” block as the winner of the previous round will directly extend the chain to a block. However, the nodes that chose the red block as the winner now see two chains: “Blue-Green-Pink” and “Blue-Red” as shown in the figure above. These nodes will, as a result, set the chain as a back-up. .

从理论上来说,两个区块的分叉是有可能的,这种情况发生在因先前分叉而相互对立起来的矿工,又几乎同时发现了两个不同区块的解。然而,这种情况发生的几率是很低的。单区块分叉每周都会发生,而双块分叉则非常罕见。

Theoretically, the fork of the two blocks is possible, in the case of miners who were opposed to each other because of the previous fork, and almost simultaneously discovered the break-up of two different blocks. However, the likelihood is very low. The fork of the single block happens every week, while the fork of the two is very rare.

比特币将区块间隔设计为10分钟,是在更快速的交易确认和更低的分叉概率间作出的妥协。更短的区块产生间隔会让交易清算更快地完成,也会导致更加频繁地区块链分叉。与之相对地,更长的间隔会减少分叉数量,却会导致更长的清算时间。

Bitcoin designs block spacing for 10 minutes, which is a compromise between faster transaction recognition and lower likelihood of splits. Shorter blocks create intervals that allow the transactions to be settled more quickly and more frequently. By contrast, longer intervals reduce the number of splits and lead to longer liquidation times.

美化布局示例

欧易(OKX)最新版本

【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   全球官网 大陆官网

币安(Binance)最新版本

币安交易所app【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址

火币HTX最新版本

火币老牌交易所【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址
文字格式和图片示例

注册有任何问题请添加 微信:MVIP619 拉你进入群

弹窗与图片大小一致 文章转载注明

分享:

扫一扫在手机阅读、分享本文

发表评论
平台列表
美化布局示例

欧易(OKX)

  全球官网 大陆官网

币安(Binance)

  官网

火币(HTX)

  官网

Gate.io

  官网

Bitget

  官网

deepcoin

  官网
热门文章
  • 0.00006694个比特币等于多少人民币/美金

    0.00006694个比特币等于多少人民币/美金
    0.00006694比特币等于多少人民币?根据比特币对人民币的最新汇率,0.00006694比特币等于4.53424784美元/32.5436 16人民币。比特币(BTC)美元(USDT)人民币(CNY)0.000066944.53424784【比特币密码】32.82795436 16比特币对人民币的最新汇率为:490408.64 CNY(1比特币=490408.64人民币)(1美元=7.24人民币)(0.00006694USDT=0.0004846456 CNY)汇率更新时...
  • 0.00003374个比特币等于多少人民币/美金

    0.00003374个比特币等于多少人民币/美金
    0.00003374比特币等于多少人民币?根据比特币对人民币的最新汇率,0.00003374比特币等于2.2826 1222美元/16.5261124728人民币。比特币(BTC)美元(USDT)人民币(CNY)0.00003374克洛克-0/22216.5261124728比特币对人民币的最新汇率为:489807.72 CNY(1比特币=489807.72人民币)(1美元=7.24人民币)(0.00003374USDT=0.0002442776 CNY)。汇率更新于2024...
  • 1983年,山西老人致信央行:人民币上的“中国人民银行”是我写的

    1983年,山西老人致信央行:人民币上的“中国人民银行”是我写的
    阅读本文前,请点击红色“关注”按钮,方便大家讨论和分享,给您带来不一样的参与感。谢谢大家的支持!1983年,山西日报发表了一篇异常简短的文章,主要内容是:“人民币的字体作者是纪。“不久后,上海《新民晚报》也发表了一篇报道,主要内容与《山西日报》基本相同。二人转文章的排版只占一小部分,但不妨碍大家关注此事。一位家住山西的老人看完文章后显得有些不解:“不是啊,人民币上的字明明是我写的。我怎么能把它戴在别人头上呢?”本着尊重历史的原则,老人的女儿给报社写了两封“澄清信”,分别寄给了...
  • 1929经济大萧条或许即将重演?

    1929经济大萧条或许即将重演?
    人类似乎陷入了一个历史悖论,即我们总是重复同样的错误,无法真正从过去的错误中吸取教训。近年来,我们对世界各地接连不断的挑战和危机深感不安。20 19年突如其来的疫情,乌克兰的战火硝烟,欧洲的天然气供应危机以及全球少数国家的饥荒,所有这些问题都像洪水一样,一个接一个地涌来。如果你今天感到心情沉重,不要失去希望,因为明天可能会带来更严峻的挑战。首先,让我们深入讨论名为1929大萧条的时期。这场大萧条实际上是指从1929到1933的一场影响深远的经济危机。这场危机首先起源于美国,然...
  • 2000年美国GDP占世界的304%,中国GDP仅占35%,现在呢?

    2000年美国GDP占世界的304%,中国GDP仅占35%,现在呢?
    GDP作为全球公认的实力基准,就像是一个大国实力的代言人,它是布雷顿森林体系下全球团结的声音。它不仅仅是数字的累积,更是大国综合实力的人格化,默默诉说着每个国家的辉煌与荣耀。虽然GDP不是衡量一个国家综合实力的唯一标准,但无疑是最关键的指标之一。作为一面镜子,它反映了国家的经济实力和发展水平,是国家综合实力的重要体现,不容忽视。2000年,中国GDP迈过/克洛克-0/万亿美元的重要门槛,达到/克洛克-0/。2/克洛克-0/万亿美元(折合人民币7。7万亿元)。然而,在全球经济的...
标签列表