-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add P7 Mining Difficulty notes #34
Open
howiezhao
wants to merge
3
commits into
YoubetDao:main
Choose a base branch
from
howiezhao:add-p7
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# P7 Mining Difficulty | ||
|
||
## Mining and mining difficulty | ||
|
||
**Mining**: Mining is to continuously try the `nonce` value in the block header so that the hash value of the entire block header is less than or equal to the given target threshold. That is, $H(block \; header) \leq target$. The smaller the `target`, the greater the mining difficulty. | ||
|
||
**Mining Difficulty**: The mining difficulty is inversely proportional to the `target`, that is, $difficulty=\frac{difficulty1target}{target}$, where `difficulty_1_target` refers to the `target` corresponding to the mining difficulty of 1. The minimum mining difficulty is 1. | ||
|
||
## Adjust mining difficulty | ||
|
||
The mining difficulty is adjusted to **keep the average block time of BTC stable**. That is, a new block is generated every **10** minutes. | ||
|
||
If the block time cannot remain stable, then as the computing power increases, the block time may become shorter and shorter, which will cause a large number of forks. The more forks there are, the less beneficial it is for the system to reach consensus. This is because a large number of forks disperse the system's computing power. | ||
|
||
## Specific implementation of BTC | ||
|
||
The mining difficulty is adjusted every **2016** blocks. The specific adjustment method is: $target = target \times \frac{actual \; time}{expected \; time}$. | ||
|
||
The *expected time* represents the time required to generate 2016 blocks under ideal circumstances, that is, $2016 \times 10$ minutes (about two weeks). The *actual time* is the time spent mining the last 2016 blocks. | ||
|
||
That is to say, if the time required to generate 2016 blocks is more than two weeks, it means that the mining difficulty is too high. According to the above formula, the `target` will become larger and the mining difficulty will be reduced. Vice versa. | ||
|
||
The above formula is defined in the code of the Bitcoin node, prompting each Bitcoin node to comply with this rule. | ||
|
||
If a Bitcoin node maliciously modifies the code to reduce the difficulty of mining, the blocks it issues will not be recognized by the vast majority of other honest nodes. | ||
|
||
## Resource | ||
|
||
- From the statistical chart in this [URL](https://bitinfocharts.com/comparison/bitcoin-confirmationtime.html#3y), we can see that the average block time of Bitcoin has remained at around 10 minutes. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As good notes, key points should be highlighted for clarity.
Please involve more list with key words highlighted in this note.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please help me review again, thanks.