The article easily understands the working principle of blockchain.
Author’s Note: This article is a popular science article for friends who are not computer majors, and tries to avoid more professional details. If you are a computer-related major, or have a certain knowledge of data structures, algorithms and cryptography, it is recommended to read three blog posts in the resources at the end of the article, or more professional materials.
Blockchain: Decentralized Distributed Database
As we all know, Bitcoin is a kind of digital currency. The "blockchain" is the bookkeeping system of Bitcoin. You can think of the blockchain as an account book that records all the bitcoin transaction information in the world. So, what is the difference between blockchain and traditional bank bookkeeping?
This involves the essence of blockchain: blockchain is a decentralized distributed database. I will explain these three keywords one by one.
Database:
The so-called "database" is a set of tables on the computer, which can store a lot of structured information (comparable to Excel, but far more complicated than Excel). For example, we go to the bank to deposit, withdraw money and remit money, and these transaction information are all uploaded to the bank’s database.
Distributed:
This database can be stored on a supercomputer in a bank or on multiple computers. For example, ICBC may have a server in North China, Central China, East China, South China and other regions, and the transaction information in each region is sent to the server in the region, and the servers are connected through the internal network of the bank. This is called a distributed database.
Decentralization:
Traditional servers, whether distributed or not, have administrators. In other words, there is a "super user" inside the bank who can view all the transaction information and can add and modify it at will. This is called“centralization".
The blockchain is "Decentralization". In other words, there is no administrator in the blockchain database, and everyone is equal and has the right to view and add information. Decentralization is the essential feature of blockchain.
Since everyone has the right to add information to the blockchain, isn’t this "account book" messy? To understand this, we need to know what a "block" is and what a "chain" is.
What is a "block" and a "chain"?"Blocks" are the basic components of blockchain. A block is a data block. Analogously, a block is equivalent to a page on the ledger, which records a number of transaction information. And by stringing these "pages" scattered throughout the Internet into a chain, a complete "account book" can be formed. So, how is the "block" strung into a "blockchain"?
Bookkeeping principle of blockchain account book
Hash value and tamper resistance:
In addition to the bitcoin transaction information, the block also contains some characteristic information of the block itself. It can be compared with the "page number" on a page, but this "page number" is more complicated. The most important thing in "page number" is "hash value", which is to understand blockchain.reliabilityThe key.
The so-called "Hash value"can be understood as a" fingerprint "of data. When we sign a contract, we sometimes press our fingerprints. In the future, we can prove that we signed the contract by comparing our fingerprints with those on the contract. Similarly, when we download a software on the Internet, some websites will give the hash value of the installation package (which may be called CRC or SHA). After we download the installation package, we only need to use a special tool to calculate the SHA value, and then compare it with the SHA value given by official website, so that we can know whether our download is 100% consistent with that provided by the website, and whether the download process has been tampered with.
Different data, the calculated hash value is generally different. If the hash value of data A is known as H, it is extremely difficult to forge another data B so that its hash value is also H. That is, the hash value hasUnforgettability, played the role of "fingerprint".
A block contains two kinds of hash values: "the hash value of the previous block" and "the hash value of this block". Because each block contains the hash value of the previous block, all blocks are connected into a (logical) chain in turn. "Hash value of the previous block" plays the role of "page number"-ranking pages.
▲ Content contained in the block
▲ Blocks are connected into a blockchain.
If the transaction information on a block is maliciously tampered with, the "hash value of this block" will change. Since the next block in the blockchain contains the "hash value of the previous block", in order to make the next block still connected to this block, the next block needs to be modified. This in turn leads to the next, next next ….. block must also be modified.
▲ If you tamper with a block, you must modify all the blocks behind.
Due to some mechanisms of the blockchain itself (this mechanism is more detailed and we will not discuss it here), it is extremely difficult to calculate the hash value of one block, and it is even more difficult to modify the hash values of multiple blocks. In this way, it is almost impossible to tamper with the transaction information in the blockchain. This ensures the reliability of the blockchain.
Mining: a way to write information to blockchain
Mining: The way to write information to the blockchain "mining" is to calculate the hash value of a potential block and make this block formally join the whole blockchain. After a block joins the blockchain, the transaction information contained in it can become a fact. Due to some considerations of bitcoin designers, the mining process needs to consume a lot of time and resources. As mentioned earlier, it is extremely difficult to calculate the hash value of a block. How difficult is it? If all the computers in the bitcoin network participate in the calculation of hash value, a hash value can only be calculated every ten minutes on average.
People engaged in mining activities are called "miners". Anyone on the Internet can join the Bitcoin network and become a miner. Since mining consumes a lot of time and resources, why do miners join voluntarily? This is because the bitcoin agreement stipulates that miners who dig new blocks will receive bitcoin rewards. This is the driving force for miners to mine; It is also because miners continue to dig mines that bitcoin transaction information can be confirmed and bitcoin transactions can be carried out normally. At the same time, this is the only way to increase the total amount of bitcoin. Unlike traditional currency, bitcoin’s total amount cannot be increased artificially by the state or institutions, but can only be "naturally" increased by mining incentives.
How to avoid bifurcation of main chain?
Since there will be bitcoin rewards for mining, bitcoin traders will also give miners some handling fees as a reward, which will inevitably lead to a lot of competition among miners. If two miners dig into the next block of a block at the same time, who is qualified to join the blockchain? If everyone can join the blockchain, the blockchain has a fork, so how to ensure the blockchain’s "uniqueness"and?
The blockchain agreement stipulates that if there are six new blocks on a fork, it will become the "orthodoxy" of the blockchain; At the same time, others who do not reach the bifurcation of six blocks will be unfortunately eliminated, and the trading information on these blocks will not be recognized. This avoids the bifurcation of the blockchain. Since a block must be followed by six new blocks after being dug up, and a new block can only be dug up every ten minutes on average, it takes at least one hour for a transaction to be confirmed (written into the blockchain).
▲ Miner B: I have a saying that I don’t know when to say it properly.
To sum up the above, what is the process of bitcoin trading?
The transaction is nothing more than a message: "buyer -1$, seller +1$." (This involves some knowledge of asymmetric cryptography, which is not unique to Bitcoin and will not be discussed. When you initiate a bitcoin transaction, the transaction information will be gradually sent from your device to the entire bitcoin network.
In order to reward mining, many miners will collect your trading information and dig new blocks desperately. If a miner digs out a new block, he will write your trading information into the block. After that, he needs to dig out six new blocks to ensure that the whole blockchain adopts this block. At this time, your transaction information can be officially written into the blockchain and confirmed. The results of miners who have not dug six blocks will be eliminated.
In this way, although many miners are competing to write your trading information, only one miner can successfully write it in the end. This ensures that your money will not be deducted twice in the same transaction.
Once a new block officially joins the blockchain, this block will be synchronized to all miners’ machines, and the new block can only follow this block. Miners who dig into this block will get some bitcoins as rewards, which is also the process of issuing new bitcoins.
Summarize the above points:
Blockchain is a reliable and unique account book for bitcoin transactions.Blockchain is a distributed database without center. It has no administrator, and all users in the network can write new blocks into the blockchain equally.Blocks are connected into a chain according to the "hash value of the last block".The difficulty of calculating hash value makes the block and blockchain unable to be tampered with and ensures the reliability of the block and blockchain.Only by adding six blocks behind a block can it formally join the blockchain, which makes the blockchain not bifurcate and ensures the uniqueness of the blockchain.But at the same time, it also leads to bitcoin transactions taking at least one hour to confirm, which is not immediate.Mining reward is the only distribution mechanism of Bitcoin, and it is also the driving force for miners to mine.
References:
Introduction to Blockchain, by Ruan Yifeng (the same below)
Introduction to Bitcoin
The essence of cryptocurrency
Want to see more of this content? Go to the APP store to searchithomeThere is a little joy every day.
Reporting/feedback