Getting Started with blockchain

Source: Internet
Author: User
Tags constant hash

Blockchain (blockchain) is a big hit right now, with news media reporting that it will create the future.

However, there are few easy-to-understand introductory articles. What the blockchain is, what is special and seldom explained.

Below, I'll try to write a best-understood blockchain tutorial. After all, it is not a difficult thing, the core concept is very simple, a few words can be said clearly. I hope that after reading this article, you can not only understand the blockchain, but also understand what is mining, why mining more and more difficult problems.

I am not an expert in this area, I have to explain. Although very early attention, but carefully understand the blockchain, or from the beginning of this year. The errors and inaccuracies in the text are welcome to correct me. first, the nature of the block chain

What the blockchain is. In a word, it is a special distributed database.

First, the main role of blockchain is to store information. Any information that needs to be saved can be written to the blockchain or read from it, so it's a database.

Second, anyone can set up a server, join a blockchain network, and become a node. In the blockchain world, there is no central node, and each node is equal, preserving the entire database. You can write/read data to any node, because all nodes will eventually be synchronized to ensure that the blockchain is consistent. second, the largest characteristics of the blockchain

Distributed database is not a new invention, the market has early such products. However, Blockchain has a revolutionary feature.

Blockchain does not have an administrator, it is completely non-centralized. Other databases have administrators, but the blockchain is not. If someone wants to add an audit to a blockchain, it is not possible, because it is designed to prevent the emergence of a central authority.

It is because of the inability to manage that the blockchain can not be controlled. Otherwise, once the big companies control the management, they will control the whole platform, and the other users will have to obey them.

However, without the administrator, everyone can write data inside, how to ensure that the data is trustworthy. What to do if the bad guys change. Read on, and this is where the blockchain is wonderful. third, block

The blockchain is made up of blocks (block). Chunks are like records of a database, and each time the data is written, a chunk is created.

Each chunk consists of two sections. Chunk Header (head): Log the meta-Information block body of the current chunk (body): Actual data

The block size contains the multi-element information for the current chunk. Generate time Actual data (that is, chunk) hash on a chunk of hash ...

Here, you need to understand what Hash is called, which is necessary to understand the blockchain.

The so-called Hash is the computer can be arbitrary content, calculate a length of the same characteristic value. The Hash length of the blockchain is 256 bits, which means that, regardless of the original content, a 256-bit binary number is calculated at the end. and can guarantee, as long as the original content is different, the corresponding Hash must be different.

For example, the hash of string 123 is a8fdc205a9f19cc1c7507a60c4f01b13d11d7fd0 (hex), and the binary is 256 bits, and only 123 can get the hash.

Therefore, there are two important inferences. Inference 1: Each chunk of the hash is not the same, you can identify the block by the hash. Inference 2: If the contents of a chunk change, its Hash will change. Four, the non-modification of the Hash

Chunks and hashes correspond to one by one, and each chunk's hash is calculated for the "Chunk Header" (head).

Hash = SHA256 (block size)

The above is the block hash calculation formula, hash by the district size only decision, SHA256 is the blockchain hash algorithm.

As I said earlier, the block size contains a lot of content, including the hash of the current chunk body (note that the "chunk" hash, not the entire chunk), and the hash of the previous block. This means that if the contents of the current chunk change, or the hash of the previous chunk changes, it will cause the hash of the current chunk to change.

This has significant implications for blockchain. If someone modifies a chunk, the chunk's Hash is changed. In order for the latter block to be connected to it, the person must modify all the blocks at the same time, or the changed chunks will be out of the blockchain. Because of the reasons behind it, Hash calculations are time-consuming, and it is almost impossible to modify multiple chunks, unless someone has mastered the computing power of over 51% of the entire network.

It is through this linkage mechanism, the blockchain guarantees its own reliability, once the data is written, it can not be tampered with. It's like history, it's happening, it's never going to change.

Each chunk is attached to a block, which is the origin of the name "blockchain". v. Mining

Because of the need to ensure synchronization between nodes, so the new block can not be added fast. Imagine that you have just synchronized a chunk, ready to generate the next block based on it, but then another node has a new block generation, you have to give up half of the calculation, to synchronize again. Because behind each chunk, you can only follow a chunk, and you can always generate the next chunk after the latest chunk. So you have no choice but to be in sync as soon as you hear the signal.

So, the blockchain inventor Satoshi (this is the pseudonym, the real identity is unknown) deliberately let add new blocks, become very difficult. His design is that on average every 10 minutes, the whole network can generate a new chunk, an hour will be six.

This rate of output is not achieved by order, but by deliberately setting a huge amount of computation. In other words, only by a very large number of calculations, the current chunk of the effective Hash, so that the new blocks added to the blockchain. The calculation is too large to get up.

This process is called mining (mining), because the difficulty of calculating a valid Hash is like finding a grain of sand in the sand around the world. The machine that calculates the Hash is called the mine machine, and the person who operates the miner is called the miners.

six, the difficulty coefficient

Read here, you may have a question, people say mining is very difficult, but mining is not to use a computer to calculate a Hash, this is the computer's strengths Ah, how can become difficult, slow to calculate it.

The original is not any hash can be, only the hash to meet the conditions will be accepted by the blockchain. This condition is particularly harsh, so that most of the Hash does not meet the requirements, must be re-calculated.

Originally, the block size contains a difficulty factor (difficulty), which determines the difficulty of calculating the Hash. For example, the 100,000th block has a difficulty factor of 14484.16236122.

The blockchain protocol stipulates that the target value can be obtained by dividing a constant by the difficulty factor. Obviously, the greater the difficulty factor, the smaller the target value.

The validity of the hash is closely related to the target value, only the hash that is less than the target value is valid, otherwise the hash is invalid and must be re-calculated. Because the target value is very small, the chance of a Hash less than this value is extremely slim, and may be calculated 1 billion times before it is counted. This is the root cause of such slow mining.

There is also a Nonce value in the block size, which records the number of Hash re-counts. The Nonce value of the 100,000th chunk is 274148111, that is, it is calculated 274 million times before a valid Hash is obtained and the block can be added to the block chain. Seven, the dynamic adjustment of the difficulty coefficient

Even if mining is difficult, there is no guarantee that a chunk is produced in just 10 minutes, sometimes a minute, and sometimes a few hours may not result. Overall, with the upgrading of hardware equipment, as well as the increase in the number of mining machines, the speed of calculation will be more and more fast.

In order to keep the output rate constant at 10 minutes, the dynamic regulation mechanism of the difficulty coefficient is also designed in Nakamoto. He stipulated that the difficulty factor was adjusted once every two weeks (2016 blocks). If within two weeks, the average generation speed of the block is 9 minutes, which means 10% faster than the legal speed, so the difficulty factor will be increased by 10%, if the average generation speed is 11 minutes, it means that the legal speed is 10%, so the difficulty factor will be lowered by 10%.

The higher the difficulty coefficient (the smaller the target value), the more difficult the mining becomes. Viii. bifurcation of blockchain

Even if the blockchain is reliable, there is still a problem: If two people write data to the blockchain at the same time, that is, two chunks are added, because they are all attached to the previous block, forming a fork. Which chunk should be adopted at this time?

The rule now is that the new node always takes the longest chunk chain. If the blockchain has a fork, it will see which branch is behind the fork point, reaching 6 new chunks (called "six Confirmations"). In a block of 10 minutes, you can confirm it in an hour.

Since the speed at which the blocks are generated is determined by the computational power, this rule means that the branch that has most of the computational power is the authentic bit chain. ix. Summary

The blockchain, as a distributed, unmanaged database, has been running for 8 years since 2009, with no major problems. This proves that it is feasible.

However, in order to ensure the reliability of data, Blockchain also has its own cost. One is efficiency, the data is written to the blockchain, at least 10 minutes to wait, all the nodes are synchronized data, it takes more time, and the second is the energy consumption, the generation of blocks requires the miners to make countless meaningless calculations, which is very energy-consuming.

Therefore, the application scenario of blockchain is actually very limited. Does not exist the data written by the administration that all members trust is not realistic when using mining proceeds to compensate for their own costs

If the above conditions are not met, then the traditional database is a better solution.

Currently, the largest blockchain scenario (and probably the only scenario) is the crypto currency represented by Bitcoin. In the next article, I will introduce you to the basics of Bitcoin. 10, reference links How does blockchain really work?, by Sean Han Bitcoin Mining the hard way:the

Related Article

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.