为了维持出块时间为一个固定值
To keep a piece of time as a fixed value
出块时间会越来越短
It'll get shorter and shorter.
系统的总算力越来越强,挖矿难度保持不变的话, 出块时间就会越来越短, 出块时间太短会导致过多的分叉。
The system is becoming more and more powerful, and the difficulty of digging remains the same, and the time is getting shorter, and the time being too short can lead to too many forks.
两个节点同时挖到矿,会出现分叉,时间越短, 这种分叉就会成为常态,分叉过多 对于系统达成共识就越困难, 系统中的总算力越强,就越安全。 分叉越多 总算力就会被分散开, 因为每个节点根据网络分布不同,选择不同的分叉进行挖矿, 那么恶意节点就不需要 51%的算力就可以发动攻击了。 为了防止恶意攻击,就需要避免过多的分叉。就需要维持出块时间为一个固定范围。
The more you dig up the mine at the same time, there will be a split fork, the shorter the time, the more common it will be, the more difficult it will be to reach a common understanding of the system, the safer it will be. The more it will be, the more it will be, the more it will be, the more it will be divided, because each node, depending on the distribution of the network, will have to choose different fork to dig, so that the malicious node will not need 51% of the calculus to strike.
H(Block Header) <=target
SHA-256
比特币网络规定每 2016个区块更新一次挖矿难度。 这个大概多长时间呢?
The Bitcoin network provides for the difficulty of re-mining each of the 2016 blocks. How long is this supposed to last?
(2016 * 10) / (24 * 60)=14天 也就是 两个星期左右。
(2016 * 10) / (24 * 60) = 14 days, that is, about two weeks.
target=target * (actual time / expect time)
expect time 就是期望的时间: 2016 * 10
Expect time is the expected time: 2016* 10
actual time 系统中产生的的最近的2016个区块的实际时间
Actual time of the most recent 2016 blocks generated in the actual time system
如果 actual time 比两个星期大, 后面的值就是一个大于1的一个数, target 就变大了,难度相当于减小了。
If the actual time is bigger than two weeks, the value behind is a number greater than one, and the target becomes bigger and less difficult.
如果 actual time 比两个星期小, 后面的值就是一个小于1的一个数, target 就变小了, 难度相当于增加了。
If the actual time is smaller than two weeks, the value behind is a number less than one, and the target is smaller, and the difficulty is equivalent to an increase.
实际的代码中调节是有界限的, 不论是增大还是减小都不会超过4倍。
There are boundaries in the actual code, and neither increase nor decrease more than four times.
例如 实际的时间 比8个星期还要长,那么就按照8个星期来计算, 这样增大为原来的4倍。
For example, the actual time is longer than eight weeks, so it's based on eight weeks, which is four times the original.
实际的时间 比半个星期还要短, 也就是不到半个星期 2016 区块就挖完了, 目标阈值就会取 半个星期。减少原来的 1/4。
The actual time is less than half a week, that's less than half a week, and the 2016 block is finished, and the target threshold is taken for half a week. Reduction by one quarter.
在区块头中有个 nBits 域 4个字节,是 Target 经过编码得到的,诚实的矿工会检测这个nBits 来保证所有的矿工都按照调整后的难度来进行挖矿。
There are four bytes of nBits in the block, which Target has been encoded and the honest mining union has tested the nBits to ensure that all miners dig in accordance with the adjusted difficulty.
区块难度D(H)调整的公式
Formula for D(H) adjustment for block difficulty
参数说明:
Description of parameters:
D(H)本区块难度
D(H) The difficulty of this block
P(H)Hd 父区块难度, 每个区块的难度都是父区块都难度基础之上进行调节
P(H)Hd parent block difficulty, the difficulty of each block is reconciliation based on the difficulty of the parent block
x * ? 用于自适应调节出块难度, 维持稳定的出块速度
x *? used to adjust blocks to the difficulty of maintaining a steady mass velocity
ε 难度炸弹
♪ Hard bomb ♪
基础部分为下界 D0 131072
The base is the lower bound of D0 131072.
x 是调整单位, ? 调整的系数
x is the unit of adjustment,? the factor of adjustment
y 和父区块的uncle数有关,如果父区块包含了uncle 那么 y=2 否则 y=1
y is related to the uncle count of the parent block, if the parent block contains uncle then y=2 or y=1
Hs 是本区块的时间戳, P(H)Hs 是父区块的时间戳,都是以秒为单位,并规定 Hs > P(H)Hs
Hs is the time stamp of this block, P(H)Hs is the time stamp of the parent block, all in seconds, and provides for Hs > P(H)Hs
父区块中包含了uncle时,难度会大一个单位,是因为包含了uncle时,新发行的货币量会变大,
When the parent blocks contain uncle, the difficulty is one unit, because when the uncle is included, the amount of money newly issued becomes larger.
这个时候就需要适当的提高挖矿难度以保持货币发行量的稳定。
At this time, there is a need to properly increase the difficulty of mining in order to maintain the stability of currency distribution.
调节的上界是 -99, 这个主要是为了防止黑客攻击或者一些其他不确定的情况。
The upper limit of the regulation is -99, which is mainly to prevent hacking or some other uncertainty.
我们仔细的看下这个公式, y无论取1 还是 2, 公式都是一个常数减去后面的值, 如果 y 比后面的值大, 减出来就是一个正数,说明难度要上调。 反之是下调。
And we look closely at this formula, y either takes one or two, and the formula is a constant minus the value, and if y is bigger than the value at the back, it's a positive number, indicating that the difficulty is going up, and the reverse is going down.
这部分是稳定出块速度的最重要部分, 出块时间过短调大难度,出块时间过长调小难度。
And this is the most important part of stabilizing the velocity of the pieces, which are too short, too hard, too long, too hard.
我们举个例子
Let's give you an example.
以父区块不带uncle为例:
Take the example of a parent block without an uncle:
出块时间在 1-8 秒之间,出块时间过短, 难度调大一个单位。
The exit time is between 1 and 8 seconds, it's too short, it's too difficult to adjust to one unit.
出块时间在 9-17秒之间, 出块时间可以接受, 保持不变。
The release time is between 9 and 17 seconds, and the release time is acceptable, and remains the same.
出块时间在 18 -26秒之间,出块时间过长, 难度调小一个单位。
The exit time is between 18 and 26 seconds, it's too long, it's too difficult to reduce a unit.
比26秒更长,就会下调更多的单位。
Longer than 26 seconds, you're going to lower more units.
为什么设置难度炸弹?
Why are you setting up a hard bomb?
设置难度炸弹的原因是要降低迁移到Pos协议时,发生fork的风险,到时挖矿难度非常大,所以矿工有意愿迁移到Pos协议。
The difficulty bomb was set up in order to reduce the risk of fork when moving to the Pos agreement, where mining was difficult and the miners were willing to move to the Pos agreement.
ε 是2的指数函数,每十万个区块扩大一倍,后期增长非常快,这就是难度炸弹的由来。
It's an index function of two, doubling every 100,000 blocks and growing very rapidly at a later stage, which is the origin of the difficulty bomb.
Hi‘ 有真正的block number 减去 3000000 得到,这样做的原因是低估来Pos协议开发的难度, 需要延长大概一年半的时间
Hi' there's a real black number minus 3 million, and the reason it's done is to underestimate the difficulty of coming to the Pos protocol, and it's gonna take about a year and a half longer.
15 * 3000000 / (24 * 3600) / 365=1.42年
15 * 3,000,000 / (24 * 3600) / 365 = 1.42 years
EIP100: 也是在这个时间 以太坊的reward从 5ETH 降到了 3ETH
Also at this time, Ether's reward fell from 5 ETH to 3 ETH.
注册有任何问题请添加 微信:MVIP619 拉你进入群
打开微信扫一扫
添加客服
进入交流群
发表评论