Block chain development: mining and mining pools based on the block chain

Source: Internet
Author: User
What is digging a mine.

When we talk about Bitcoin, a noun that is often referred to is "digging", so what is it about digging a mine? What is the detailed process of it? Personally, I used to know that the so-called mining is about to find a random number, so that the hash value of the block is less than a certain number, but what is the specific. I don't know... And, of course, not only that, many other concepts like the structure of blocks, the structure of transactions, the type of scripts, the p2sh of what these concepts are, and what they are, are vague enough to know that there is some content, so the summary of this series is also to give yourself a more accurate understanding of these basic concepts.

There is a nonce in the block header, the structure of the chunk head can refer to the previous article, the goal of the mining is to find this nonce, so that the following equation is met: SHA256 (SHA256 (block header)) < target. And the size of the nonce is 4 bytes, the range that can be represented is [0,2^32-1], which is too different from the final hash value, so what happens when Nonce enumerates 2^32-1. The method of Bitcoin is to have a special input called "Coinbase" in the first transaction in each block, that is, the Coinbase transaction, which can save any content without being used. So bitcoin sets a new parameter called Extranonce (2-100 bytes) in this parameter, and when the nonce in the block header overflows, the extranonce changes. When the extranonce changes, the hash value of the Coinbase transaction changes and passes to the Merkle tree, and the root of the Merkle tree changes, causing another variable in the block header to change, Then nonce can be enumerated again. In addition, the miners can also enumerate nonce by modifying the timestamp. These parameters are combined to make this equation necessarily have a solution. difficulty in digging ore

The difficulty of digging is a description of the above current target, which is used to indicate how difficult it is for miners to look for nonce to meet the conditions, and that the difficulty will change once every 2016 blocks, 10 minutes per block, or about two weeks. The calculation formula of the difficulty is:
Difficulty=difficulty_1_target/current_target difficulty = Difficulty{\_1\_target/current{\_target}}
Where Difficulty_1_target represents a target hash value of 1 o'clock difficulty, divided by the current target hash, is the current difficulty. The formula is easy to understand, the difficulty is 1 equivalent to all the size of the solution space, divided by the size of the current solution space, to indicate difficulty. In Bitcoin, the difficulty 1 is defined as 0X1D00FFFF, and the bitcoin converts this 32-bit integer to a 256-bit value in a custom format.

0X00FFFF * 2** (8* (0x1d-3)) = 0x00000000ffff0000000000000000000000000000000000000000000000000000

In the previous chapter we know that there is a field called bits in the block header that is used to save the current difficulty, 32 bits in length, in fact it is a compressed form of a 256-bit hash, assuming that current bits is 0X1B0404CB, then the corresponding 256-bit hash is

0X0404CB * 2** (8* (0x1b-3)) = 0x00000000000404cb000000000000000000000000000000000000000000000000

This is also the Current_target in the formula above, this time the difficulty difficulty should be,

0x00000000ffff0000000000000000000000000000000000000000000000000000/
0x00000000000404cb000000000000000000000000000000000000000000000000 
= 16307.420938523983 (bdiff, bit currency difficulty)

According to this calculation, a more professional expression of difficulty is that themeaning of difficulty is to compute the difficulty*2^32 hash on average to find a solution. Of course, this is only a bit of the source code defined in the calculation, in the actual mining pool, they will be difficult to 1 defined as 0X00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF. Then the difficulty of their calculation should be,

0X00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF/
0x00000000000404cb000000000000000000000000000000000000000000000000 
= 16307.669773817162 (PDIFF, Ore pool difficulty)

About the difficulty more detailed introduction please refer to: https://en.bitcoin.it/wiki/Difficulty, the current difficulty can pass https://blockexplorer.com/api/status?q= Getdifficulty obtained, the next difficulty can be obtained through https://blockexplorer.com/api/status?q=estimate, difficulty changes can be viewed through http://bitcoin.sipa.be/. Calculate Force

Because of the way the bitcoin is defined in the hash form, the first 32 bits of the difficulty are always 0, which is equivalent to wasting 32 digits, so the final difficulty is multiplied by 2^32 to indicate the average number of hashes for a block. And the speed that the block produces is average every 10 minutes 1, that is 600 seconds, mean the network average hash rate, namely calculate force is difficulty*2^32/600, this is also commonly we use to calculate the approximate expression of the whole network calculate force. According to https://blockexplorer.com/api/status?q=getDifficulty Web site data, the current difficulty is 1347001430558.57, then the total network calculation Force is approximately 9.642*10^18 hash/s. At present, a S9 ant mining machine is the 13t/s, alone to dig a bitcoin need 1347001430558.57*2^32/(13*10^12) = 445,025,160 seconds, that is, 5,150 days. This shows that, now for individual miners, the daily income is very small, so this also led to the formation of the mine pool. Mine Pool

The aim of the mine pool is to stabilize miners ' earnings and reduce the variance of miners ' earnings. In a mine pool, the miners contribute their own calculations, then distribute the proceeds in proportion, and the miners contribute by submitting share, each share has a certain probability is the ultimate effective solution, so this share is the miners themselves work proof, And a share can be found in a short period of time.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.