Skip to content

Commit fec1f06

Browse files
committed
finish some mining translation
1 parent 4db590d commit fec1f06

File tree

4 files changed

+605
-2
lines changed

4 files changed

+605
-2
lines changed
Lines changed: 170 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,174 @@
11
---
22
sidebar_position: 3
33
---
4-
# Difficulty Adjusting Algorithm
54

5+
# Difficulty Adjusting Algorithm
6+
7+
How to adjust the difficulty target to ensure an average block generation time of 10 minutes.
8+
9+
## What is a Difficulty Adjustment Algorithm?
10+
11+
A difficulty adjustment algorithm adjusts the difficulty target based on the speed of past block production to ensure
12+
that new blocks are generated at an average time of 10 minutes. This algorithm is an important component of the
13+
blockchain network, controlling the block production speed, regulating the issuance rate of new coins, and ensuring the
14+
security and stability of the blockchain.
15+
16+
The following explains Bitcoin's difficulty adjustment algorithm and the ASERT-DAA algorithm used in the MVC network.
17+
18+
## Bitcoin's Difficulty Adjustment Algorithm
19+
20+
Bitcoin adjusts its difficulty every 2016 blocks (approximately every two weeks). Here are the detailed steps of
21+
Bitcoin's difficulty adjustment algorithm:
22+
23+
**Calculate Actual Time Taken**
24+
25+
The actual time taken is the total time taken to generate the last 2016 blocks:
26+
27+
$$
28+
\text{Actual Time} = \text{Time of the Last Block} - \text{Time of the First Block}
29+
$$
30+
31+
**Calculate Target Time**
32+
33+
The target time is the expected time to generate 2016 blocks:
34+
35+
$$
36+
\text{Target Time} = 2016 \times 10 \, \text{minutes}
37+
$$
38+
39+
$$
40+
\text{Target Time} = 2016 \times 600 \, \text{seconds}
41+
$$
42+
43+
$$
44+
\text{Target Time} = 1209600 \, \text{seconds}
45+
$$
46+
47+
**Calculate New Difficulty Target**
48+
49+
The new difficulty target is adjusted based on the ratio of actual time to target time:
50+
51+
$$
52+
\text{New Difficulty Target} = \text{Old Difficulty Target} \times \left( \frac{\text{Actual Time}}{\text{Target Time}}
53+
\right)
54+
$$
55+
56+
**Limit Adjustment Range**
57+
58+
To avoid drastic fluctuations in the difficulty target, the Bitcoin protocol limits the adjustment range to no more than
59+
four times or less than one-quarter of the previous difficulty:
60+
61+
$$
62+
\text{New Difficulty Target} = \min\left(\text{Old Difficulty Target} \times 4, \max\left(\frac{\text{Old Difficulty
63+
Target}}{4}, \text{New Difficulty Target}\right)\right)
64+
$$
65+
66+
The drawback of this method is that the adjustment speed is slow. For a mature and stable blockchain network like
67+
Bitcoin, this adjustment speed is acceptable. However, for emerging blockchain networks, price fluctuations may lead to
68+
significant changes in computing power, seriously affecting block production speed.
69+
70+
When BCH (Bitcoin Cash) first forked from Bitcoin, it faced block production difficulties due to computing power
71+
fluctuations. BCH initially adopted the EDA (Emergency Difficulty Adjustment) algorithm to adjust the difficulty in a
72+
shorter time, ensuring block production speed. However, the EDA algorithm had some issues and was vulnerable to attacks.
73+
Therefore, BCH later adopted the ASERT-DAA algorithm, which performed well in the BCH network. Consequently, the MVC
74+
network also adopted the ASERT-DAA algorithm.
75+
76+
## ASERT-DAA Algorithm
77+
78+
The [ASERT-DAA](https://github.com/bitcoincashorg/bitcoincash.org/blob/master/spec/2020-11-15-asert.md) algorithm is a
79+
difficulty adjustment algorithm used in the BCH network. It is a dynamic difficulty adjustment algorithm based on
80+
computing power that can adjust the difficulty in a short time to ensure an average block production time of 10 minutes.
81+
82+
The Automatic Difficulty Adjustment by Smoothly Updating and Real-Time Targeting (Asert) algorithm was introduced in the
83+
November 15, 2020, upgrade of Bitcoin Cash. Here are the features and calculation steps of the Asert difficulty
84+
adjustment algorithm:
85+
86+
### Features of the Asert Difficulty Adjustment Algorithm
87+
88+
1. **Continuous Adjustment**:
89+
The Asert algorithm employs a continuous difficulty adjustment mechanism instead of adjusting every 2016 blocks. This
90+
allows it to more promptly reflect changes in computing power and maintain a more stable block production time.
91+
92+
2. **Time Parameterization**:
93+
Asert adjusts difficulty directly based on the difference between actual and target block production times, making
94+
the adjustments more flexible and precise.
95+
96+
3. **Exponential Smoothing**:
97+
The Asert algorithm uses exponential smoothing to avoid drastic fluctuations in the difficulty target, ensuring
98+
smooth transitions and stability.
99+
100+
### Asert Difficulty Adjustment Formula
101+
102+
The core formula of the Asert algorithm is as follows:
103+
104+
$$
105+
D_{next} = D_{prior} \times 2^{\left( \frac{t_{actual} - t_{expected}}{T} \right) / \tau}
106+
$$
107+
108+
Where:
109+
110+
- $ D_{next}$ is the difficulty target for the next block.
111+
- $ D_{prior}$ is the current block's difficulty target.
112+
- $ t_{actual}$ is the difference in timestamps between the current block and the last adjusted block.
113+
- $ t_{expected}$ is the target block time interval multiplied by the number of blocks.
114+
- $ T$ is the target block time, usually 600 seconds (10 minutes).
115+
- $ \tau$ is a time constant used for smoothing adjustments, typically 172800 seconds (2 days).
116+
117+
### Calculation Steps
118+
119+
1. **Calculate Time Difference**:
120+
Calculate the difference in timestamps between the current block and the last adjusted block, i.e., $ t_{actual}$.
121+
122+
2. **Calculate Target Time Difference**:
123+
Calculate the target time difference based on the expected block time interval and the actual number of blocks,
124+
i.e., $ t_{expected}$.
125+
126+
3. **Calculate Difficulty Adjustment Factor**:
127+
Use the formula to calculate the difficulty adjustment factor:
128+
129+
$$
130+
\text{Adjustment Factor} = 2^{\left( \frac{t_{actual} - t_{expected}}{T} \right) / \tau}
131+
$$
132+
133+
4. **Calculate Next Block's Difficulty Target**:
134+
Calculate the next block's difficulty target using the adjustment factor:
135+
136+
$$
137+
D_{next} = D_{prior} \times \text{Adjustment Factor}
138+
$$
139+
140+
### Example
141+
142+
Suppose the current block's difficulty target $ D_{prior} $ is 100000, the actual time difference $ t_{actual}$ is 1200
143+
seconds, the target time difference $ t_{expected}$ is 600 seconds, the target block time $ T$ is 600 seconds, and the
144+
time constant $ \tau$ is 172800 seconds.
145+
146+
1. **Calculate Time Difference**:
147+
148+
$$
149+
t_{actual} = 1200
150+
$$
151+
$$
152+
t_{expected} = 600
153+
$$
154+
155+
2. **Calculate Adjustment Factor**:
156+
157+
$$
158+
\text{Adjustment Factor} = 2^{\left( \frac{1200 - 600}{600} \right) / 172800}
159+
$$
160+
$$
161+
\text{Adjustment Factor} = 2^{\left( \frac{600}{600} \right) / 172800}
162+
$$
163+
$$
164+
\text{Adjustment Factor} = 2^{1 / 172800}
165+
$$
166+
167+
3. **Calculate New Difficulty Target**:
168+
169+
$$
170+
D_{next} = 100000 \times 2^{1 / 172800}
171+
$$
172+
173+
This calculation enables the MVC network to more smoothly adjust the difficulty, addressing computing power fluctuations
174+
and ensuring network stability and reliability.
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,179 @@
11
---
22
sidebar_position: 2
33
---
4+
45
# Difficulty Target and Network Hashrate
56

7+
An introduction to the concepts of difficulty target and network-wide difficulty.
8+
9+
> Note: Difficulty target and network-wide difficulty are two different concepts. The difficulty target is the value
10+
> that a block's hash must be less than, while network-wide difficulty is the difficulty of obtaining the next valid
11+
> block. Generally, the smaller the difficulty target, the greater the difficulty; the higher the network-wide difficulty,
12+
> the harder it is to mine.
13+
14+
## Difficulty Target
15+
16+
The difficulty target is the value that a block's hash must be less than. The hash value calculated by the block header
17+
hash algorithm can be viewed as a 256-bit hexadecimal number. The more leading zeros in the hash value, the smaller the
18+
corresponding number of the hash value. The difficulty target specifies that the hash value must be less than a specific
19+
value, and only a hash value that meets this condition will be accepted by the network.
20+
21+
The difficulty target determines the computational difficulty miners need to find a valid block hash. The difficulty
22+
target ensures that new blocks are discovered approximately every 10 minutes, regardless of changes in the network's
23+
total computational power. The entire network adjusts the difficulty target in real-time to control the speed of block
24+
production and the issuance rate of new coins.
25+
26+
## Representation of Difficulty Target
27+
28+
In the Bitcoin and MVC networks, the difficulty target is located in the `bits` field of the block header. The `bits`
29+
field is a 4-byte integer that represents the difficulty target value. The value of the `bits` field is a hexadecimal
30+
number, using a compact format to represent the difficulty target. The compact `bits` value can be calculated into the
31+
actual target value using the following formula:
32+
33+
- **Compact Format**: In the MVC network, the difficulty target is often represented in a compact form called "bits."
34+
This is a 4-byte value from which the actual target hash value can be calculated.
35+
- **Calculating the Actual Target Value**: The actual target value can be calculated from the compact `bits` format
36+
using the following formula:
37+
38+
$$
39+
\text{Target} = \text{Coefficient} \times 2^{(8 \times (\text{Exponent} - 3))}
40+
$$
41+
42+
Where `Coefficient` is the first three bytes of `bits`, and `Exponent` is the last byte of `bits`. For example,
43+
if `bits` is represented as `0x1d00ffff`, then `Coefficient` is `0x00ffff` and `Exponent` is `0x1d`.
44+
45+
![img.png](/img/blockheader-bits.png)
46+
47+
### Example
48+
49+
Suppose the current difficulty target is represented as `0x1b0404cb`. We can calculate the actual difficulty target
50+
value with the following steps:
51+
52+
**Extracting the Coefficient and Exponent**:
53+
54+
$$
55+
\text{Coefficient} = 0x0404cb
56+
$$
57+
$$
58+
\text{Exponent} = 0x1b
59+
$$
60+
61+
**Calculating the Actual Target Value**:
62+
63+
$$
64+
\text{Target} = 0x0404cb \times 2^{(8 \times (0x1b - 3))}
65+
$$
66+
$$
67+
\text{Target} = 0x0404cb \times 2^{(8 \times 0x18)}
68+
$$
69+
$$
70+
\text{Target} = 0x0404cb \times 2^{192}
71+
$$
72+
73+
In hexadecimal form:
74+
$$
75+
\text{Target} = 0x0023AEA3C73B13B193EC4E9D9AD4A03B60000000000000000000000000000000
76+
$$
77+
78+
This value is the actual difficulty target value. The block header's hash value must be less than this value to be
79+
accepted by the network. In other words, if the calculated hash value of the block header is less than this value (
80+
starting with 2 leading zeros), then the block is valid.
81+
82+
## Difficulty Calculation
83+
84+
Network-wide difficulty is the difficulty of obtaining the next valid block. It is determined by the total computational
85+
power of all miners in the network. Network-wide difficulty is a dynamic value that adjusts in real-time based on the
86+
total computational power of miners. The goal of network-wide difficulty is to ensure that new blocks are discovered
87+
approximately every 10 minutes.
88+
89+
You can use the mvc-cli command-line tool to check the current network-wide difficulty:
90+
91+
```bash
92+
mvc-cli getmininginfo
93+
```
94+
95+
```text
96+
{
97+
"blocks": 71434,
98+
"currentblocksize": 339,
99+
"currentblocktx": 1,
100+
"difficulty": 34975994469.53414,
101+
"errors": "",
102+
"networkhashps": 2.409330669323676e+17,
103+
"pooledtx": 1,
104+
"chain": "main"
105+
}
106+
```
107+
108+
In the output above, the `difficulty` field represents the current network-wide difficulty in decimal format. The higher
109+
the difficulty value, the harder it is to mine.
110+
111+
Network-wide difficulty can be calculated inversely from the difficulty target. The smaller the difficulty target, the
112+
higher the difficulty, so it is essential to define what difficulty is.
113+
114+
### Maximum Target (Also Known as Difficulty 1)
115+
116+
In the MVC network, the difficulty value is a relative measure used to indicate the difficulty of finding a valid block
117+
hash. It is calculated by comparing the current target with the maximum target (Max Target). The maximum target is the
118+
target value at the lowest difficulty, which is the initial difficulty target of MVC.
119+
120+
The maximum difficulty target (Max Target) is:
121+
122+
$$
123+
\text{Max Target} = 0x1d00ffff
124+
$$
125+
126+
In decimal format, the maximum target is:
127+
128+
$$
129+
\text{Max Target} = 0x1d00ffff \times 2^{8 \times (0x1d - 3)}
130+
$$
131+
$$
132+
\text{Max Target} = 0x00ffff \times 2^{8 \times 0x1a}
133+
$$
134+
$$
135+
\text{Max Target} = 65535 \times 2^{208}
136+
$$
137+
138+
### Calculating Difficulty Value
139+
140+
The difficulty value is calculated by dividing the maximum target by the current target:
141+
142+
$$
143+
\text{Difficulty} = \frac{\text{Max Target}}{\text{Current Target}}
144+
$$
145+
146+
This aligns with our understanding that the smaller the current target, the higher the difficulty value. As it is a
147+
ratio, the difficulty value of the maximum difficulty target is the smallest, which is 1.
148+
149+
### Steps to Calculate Difficulty Value
150+
151+
**Convert Current Difficulty Target to Decimal**:
152+
153+
$$
154+
\text{Current Target} = 165608837515678774353553029698295978246167310057892115125170688
155+
$$
156+
157+
**Calculate the Decimal Value of the Maximum Target**:
158+
159+
$$
160+
\text{Max Target} = 65535 \times 2^{208}
161+
$$
162+
$$
163+
\text{Max Target} \approx 5.788 \times 10^{49}
164+
$$
165+
166+
**Divide to Calculate the Difficulty Value**:
167+
168+
$$
169+
\text{Difficulty} = \frac{5.788 \times 10^{49}}{165608837515678774353553029698295978246167310057892115125170688}
170+
$$
171+
172+
Approximately, the difficulty value is:
173+
174+
$$
175+
\text{Difficulty} \approx \frac{5.788 \times 10^{49}}{1.656 \times 10^{41}}
176+
$$
177+
$$
178+
\text{Difficulty} \approx 3.493 \times 10^8
179+
$$

0 commit comments

Comments
 (0)