An article takes you to understand the working principle and process of blockchain

The blockchain is quite popular these days, and there are a lot of reports in the news media, claiming that it will create the future, but what is the blockchain? How does it work, what’s special about it, what problems does it solve, and how is it used? Today we will try it and make a blockchain tutorial that you can understand best. I hope that after reading this article, you can not only understand the blockchain, but also understand what mining is and why mining will become more and more difficult. .

What is a blockchain, as its name suggests, a blockchain is a series of data blocks containing information, it is a special distributed database, this technology was first proposed by a group of researchers in 1991, using Come time stamping digital documents to ensure that people cannot go back or tamper with time, like a notary public. First of all, the blockchain is mainly used to store information, just like storing your chat records. Any information that needs to be saved can be written into the blockchain or read from it, so it is a database. Secondly, anyone can You can set up a server, join the blockchain network, and become a node. There is no central node in the blockchain world. Each node is equal and saves the entire database. You can write or read to any node. Take data, because all nodes will eventually be synchronized to ensure the consistency of the blockchain.

For example, a certain letter that we commonly use is a centralized server, and the host of a certain news is the central node. All the chat content of everyone is sent to the person you want to send through their node, and then the chat record will be saved in the On their server, if you use the blockchain, your information may be sent to any node, and then the entire network node will be synchronized, so that all the machines are a database, and secondly, your computer can also install programs to become a node, After encryption, everyone’s chat records are saved, and they have the same authority and level as the server of a news.

An article takes you to understand the working principle and process of blockchain

In fact, the distributed database is not a new invention, there are such products on the market, but the blockchain has a revolutionary feature. The blockchain has no administrator, it is completely centerless, and other databases are managed However, the blockchain does not. If someone wants to add audit to the blockchain, it cannot be achieved, because its design goal is to prevent the emergence of a central management authority. It is precisely because it cannot be managed that the blockchain can do Otherwise, once the management rights are controlled by the big companies and groups, they will control the entire platform, and other users must obey them. However, without the administrator, everyone can write data into it. , how can we ensure that the data is credible, and what should we do if it is changed by the bad guys? The blockchain has a block group, and the blocks are very similar to the records of the database. Every time data is written, a block is created. The block contains two parts, the block header and the block body. The block header records the eigenvalues ​​of the current block, and the block extract records the current actual data. The block header contains a number of eigenvalues ​​of the current block, generation time, actual The hash of the data, the hash of the previous block, etc.

You need to understand what a hash is, which is necessary to understand the blockchain. The so-called hash is that a computer can calculate a characteristic value of the same length for any content. The hash length of the blockchain is 256 bits, which means that no matter what the original content is, a 256-bit binary number will be calculated in the end, which can be a smiley face, a voice, a paragraph or a video. And it can be guaranteed that as long as the original content is different, the corresponding hash must be different. For example, the hash of the string 123 is this, and the conversion to binary is 256 bits, and only 123 can get this hash. In theory, other It is also possible for character creation to get this hash, but the probability is extremely low, and it can be approximated as impossible, so there are two important inferences: 1. The hash of each block is different, which can be obtained by The hash identifies the block. 2. If the content of the block changes, its hash will definitely change. The block is corresponding to the hash one-to-one. The hash of each block is calculated for the block header. That is to say, the feature values ​​of the block header are connected together in order to form a very long string, and then the hash of this string is calculated, Hash=SHA256 (block header) This is the calculation of the block hash formula. The hash algorithm of the SHA256 blockchain, note that this formula only contains the block header, not the block body, that is to say, the hash is uniquely determined by the block header.

As mentioned earlier, the block header contains a lot of content, including the hash of the current block and the hash of the previous block. This means that if the content of the current block body changes, or the hash of the previous block If it changes, it will definitely cause the hash of the current block to change, which is of great significance to the blockchain. If someone modifies a block, the hash of the block will change. If you can still connect to it, you must modify all the following blocks in turn, otherwise the changed blocks will be separated from the blockchain. Modifying multiple blocks is almost impossible, unless someone masters more than 51% of the computing power of the entire network, and the blockchain officially ensures its own reliability through this linkage mechanism. Once data is written, it cannot be tampered with. Just like history, what happened is what happened, and it can never be changed again. Every blockchain is connected to the previous block. This is the origin of the name of the blockchain. Since synchronization between nodes must be guaranteed, new blocks cannot be added too quickly.

An article takes you to understand the working principle and process of blockchain

Imagine that you have just synchronized a block and are going to generate the next block based on it, but at this time other nodes generate new blocks, you have to give up half of the calculations to synchronize again, because every A block can only be followed by a block, you can only generate the next block after the latest block, so you have no choice, you have to synchronize as soon as you hear the signal, so the inventor of the blockchain Satoshi Nakamoto deliberately made it difficult to add new blocks. Its design is that on average, the entire network can generate one new block every ten minutes, and only six per hour. This output speed is not achieved through commands. , but deliberately set up massive calculations. That is to say, only through these large amounts of calculations can the effective hash of the current block be obtained, so that the new block can be added to the blockchain quickly. Due to the large amount of calculation, it cannot be done quickly. This process is called mining, also known as mining. .

Because of the difficulty of calculating an effective hash, it is like finding a grain of sand that meets the conditions in the sand all over the world. The machine that calculates the hash is called a mining machine, and the person who operates the mining machine is called a miner. You may still have a question after reading this. , People say that mining is very difficult, but isn’t mining just using computers to calculate hashes one by one? This is the strength of computers, how can it become difficult? It turns out that not any hash can be used. Only the hash that meets the conditions will be accepted by the blockchain. This condition is particularly harsh, so that most of the hashes cannot meet the requirements. Recalculate.

It turns out that the hash header contains a difficulty coefficient, and this value determines the difficulty of calculating the hash. For example, the difficulty coefficient of the 100,000th block is 14,000. The blockchain protocol stipulates that a constant is used to divide the difficulty coefficient, The target value can be obtained. Obviously, the larger the difficulty coefficient, the smaller the target value. The validity of the hash is closely related to the target value. Only the hash smaller than the target value is valid, otherwise the hash is invalid and must be recalculated. Since the target value is very small, The chance of a hash being less than that value is extremely slim, maybe one in a billion calculations, which is why mining is so slow.

An article takes you to understand the working principle and process of blockchain

As I said just now, the hash of the current block is determined only by the block header. If you want to repeatedly calculate the hash for the same block, it means that the block header must keep changing, otherwise it is impossible to calculate different hashes. All eigenvalues ​​in the block header are fixed. In order to make the block header change, Satoshi Nakamoto deliberately added a random item called “Nonce”. Nonce is a random value. The role of miners is to guess the value of Nonce. The hash of the block header can be smaller than the target value, so that it can be written into the blockchain. Nonce is very difficult to guess. At present, only one by one trial and error can be used exhaustively.

According to the agreement, Nonce is a 32-bit binary, the maximum can reach 214.7 billion, and the Nonce of the 100,000th block is 274 million. It can be understood that miners have calculated 27.4 billion times from scratch to get a valid Nonce. value, so that the calculated hash can meet the conditions. If you are lucky, you may find the Nonce in a while. If you are unlucky, you may not be able to find the Nonce after counting 214.7 billion, and it is impossible to calculate the hash that meets the conditions for the current trending topic. , then the protocol allows miners to change the block body and start a new calculation.

As I said earlier, the randomness of mining cannot guarantee that a block will be produced in exactly ten minutes. Sometimes it will be produced in one minute, and sometimes there will be no result in several hours. In general, with the improvement of hardware equipment and the growth of mining machines, the calculation speed will definitely become faster and faster. In order to keep the output rate constant at ten minutes, Satoshi Nakamoto also designed the difficulty coefficient and dynamic adjustment mechanism. It is stipulated that the difficulty coefficient is adjusted every two weeks. If the average generation speed of blocks in these two weeks is nine minutes, it means that this is 10% faster than the predetermined speed. Therefore, the next difficulty coefficient will be increased by 10%. If the average speed is increased to 11 minutes, it means that it is 10% slower than the predetermined speed. Therefore, the next difficulty factor will be reduced by 10%. The higher the difficulty factor is, the smaller the target value is. It’s getting harder, even if the blockchain is reliable.

There is still a problem that has not been solved. If two people write data to the blockchain at the same time, that is to say, two blocks are added at the same time, because they are both connected to the previous block, a fork is formed. At this time, it should be Which block to use? The current rule is that new nodes always use the longest chain. If there is a fork in the blockchain, it will look at which branch and hit six blocks after the fork point. It is called six confirmations, calculated as a block in ten minutes, and it can be completed in one hour.

Since the fast generation speed of the new area is determined by the computing power, this rule means that the branch with the most computing power is the authentic blockchain, and the blockchain acts as an unmanaged distributed database. It has been running for 11 years since 2009, and there are no major problems. This proves that it is feasible. However, in order to ensure the reliability of data, the blockchain also has its own costs. 1. Efficiency problem, data is written into blocks The chain has to wait at least ten minutes, and it takes more time for all nodes to synchronize data. 2. Energy consumption, the generation of blocks requires miners to perform countless meaningless calculations, which is very wasteful of energy. Therefore, blockchain The applicable scenarios are actually limited. There is no authority that all members trust in the management. The written data does not need to be used in real time, and the mining revenue can make up for its own cost. If the above two conditions cannot be met, then the traditional database will be better solution.

At present, the largest application scenario of blockchain is the cryptocurrency represented by Bitcoin, and industries such as decentralized finance and communications are also developing rapidly.

Posted by:CoinYuppie,Reprinted with attribution to:
Coinyuppie is an open information publishing platform, all information provided is not related to the views and positions of coinyuppie, and does not constitute any investment and financial advice. Users are expected to carefully screen and prevent risks.

Like (0)
Donate Buy me a coffee Buy me a coffee
Previous 2022-02-19 21:51
Next 2022-02-19 21:53

Related articles