区块链到底是啥? 区块链是什么玩意

区块链是什么?一句话,它是一种特殊的分布式数据库。


首先,区块链的主要作用是储存信息。任何需要保存的信息,都可以写入区块链,也可以从里面读取,所以它是数据库。

其次,任何人都可以架设服务器,加入区块链网络,成为一个节点。区块链的世界里面,没有中心节点,每个节点都是平等的,都保存着整个数据库。你可以向任何一个节点,写入/读取数据,因为所有节点最后都会同步,保证区块链一致。

二、区块链的最大特点

分布式数据库并非新发明,市场上早有此类产品。但是,区块链有一个革命性特点。

区块链没有管理员,它是彻底无中心的。其他的数据库都有管理员,但是区块链没有。如果有人想对区块链添加审核,也实现不了,因为它的设计目标就是防止出现居于中心地位的管理当局。

正是因为无法管理,区块链才能做到无法被控制。否则一旦大公司大集团控制了管理权,他们就会控制整个平台,其他使用者就都必须听命于他们了。

但是,没有了管理员,人人都可以往里面写入数据,怎么才能保证数据是可信的呢?被坏人改了怎么办?请接着往下看,这就是区块链奇妙的地方。

三、区块

区块链由一个个区块(block)组成。区块很像数据库的记录,每次写入数据,就是创建一个区块。


每个区块包含两个部分。

区块头(Head):记录当前区块的元信息

区块体(Body):实际数据

区块头包含了当前区块的多项元信息。

生成时间

实际数据(即区块体)的 Hash

上一个区块的 Hash

这里,你需要理解什么叫Hash,这是理解区块链必需的。


所谓 Hash 就是计算机可以对任意内容,计算出一个长度相同的特征值。区块链的 Hash 长度是256位,这就是说,不管原始内容是什么,最后都会计算出一个256位的二进制数字。而且可以保证,只要原始内容不同,对应的 Hash 一定是不同的。

举例来说,字符串123的 Hash 是a8fdc205a9f19cc1c7507a60c4f01b13d11d7fd0(十六进制),转成二进制就是256位,而且只有123能得到这个 Hash。因此,就有两个重要的推论。

推论1:每个区块的 Hash 都是不一样的,可以通过 Hash 标识区块。

推论2:如果区块的内容变了,它的 Hash 一定会改变。

四、 Hash 的不可修改性

区块与 Hash 是一一对应的,每个区块的 Hash 都是针对”区块头”(Head)计算的。

Hash = SHA256(区块头)

上面就是区块 Hash 的计算公式,Hash 由区块头唯一决定,SHA256是区块链的 Hash 算法。

前面说过,区块头包含很多内容,其中有当前区块体的 Hash(注意是”区块体”的 Hash,而不是整个区块),还有上一个区块的 Hash。这意味着,如果当前区块的内容变了,或者上一个区块的 Hash 变了,一定会引起当前区块的 Hash 改变。

这一点对区块链有重大意义。如果有人修改了一个区块,该区块的 Hash 就变了。为了让后面的区块还能连到它,该人必须同时修改后面所有的区块,否则被改掉的区块就脱离区块链了。由于后面要提到的原因,Hash 的计算很耗时,同时修改多个区块几乎不可能发生,除非有人掌握了全网51%以上的计算能力。

正是通过这种联动机制,区块链保证了自身的可靠性,数据一旦写入,就无法被篡改。这就像历史一样,发生了就是发生了,从此再无法改变。


每个区块都连着上一个区块,这也是”区块链”这个名字的由来。

五、挖矿

由于必须保证节点之间的同步,所以新区块的添加速度不能太快。试想一下,你刚刚同步了一个区块,准备基于它生成下一个区块,但这时别的节点又有新区块生成,你不得不放弃做了一半的计算,再次去同步。因为每个区块的后面,只能跟着一个区块,你永远只能在最新区块的后面,生成下一个区块。所以,你别无选择,一听到信号,就必须立刻同步。

所以,区块链的发明者中本聪(这是假名,真实身份至今未知)故意让添加新区块,变得很困难。他的设计是,平均每10分钟,全网才能生成一个新区块,一小时也就六个。

这种产出速度不是通过命令达成的,而是故意设置了海量的计算。也就是说,只有通过极其大量的计算,才能得到当前区块的有效 Hash,从而把新区块添加到区块链。由于计算量太大,所以快不起来。

这个过程就叫做挖矿(mining),因为计算有效 Hash 的难度,好比在全世界的沙子里面,找到一粒符合条件的沙子。计算 Hash 的机器就叫做矿机,操作矿机的人就叫做矿工。

六、难度系数

你可能会有一个疑问,人们都说挖矿很难,可是挖矿不就是用计算机算出一个 Hash 吗,这正是计算机的强项啊,怎么会变得很难,迟迟算不出来呢?

原来不是任意一个 Hash 都可以,只有满足条件的 Hash 才会被区块链接受。这个条件特别苛刻,使得绝大部分 Hash 都不满足要求,必须重算。

原来,区块头包含一个难度系数(difficulty),这个值决定了计算 Hash 的难度。举例来说,第100000个区块的难度系数是 14484.16236122。


区块链协议规定,使用一个常量除以难度系数,可以得到目标值(target)。显然,难度系数越大,目标值就越小。


Hash 的有效性跟目标值密切相关,只有小于目标值的 Hash 才是有效的,否则 Hash 无效,必须重算。由于目标值非常小,Hash 小于该值的机会极其渺茫,可能计算10亿次,才算中一次。这就是挖矿如此之慢的根本原因。

区块头里面还有一个 Nonce 值,记录了 Hash 重算的次数。第 100000 个区块的 Nonce 值是274148111,即计算了 2.74 亿次,才得到了一个有效的 Hash,该区块才能加入区块链。

七、难度系数的动态调节

就算采矿很难,但也没法保证,正好十分钟产出一个区块,有时一分钟就算出来了,有时几个小时可能也没结果。总体来看,随着硬件设备的提升,以及矿机的数量增长,计算速度一定会越来越快。

为了将产出速率恒定在十分钟,中本聪还设计了难度系数的动态调节机制。他规定,难度系数每两周(2016个区块)调整一次。如果这两周里面,区块的平均生成速度是9分钟,就意味着比法定速度快了10%,因此难度系数就要调高10%;如果平均生成速度是11分钟,就意味着比法定速度慢了10%,因此难度系数就要调低10%。

难度系数越调越高(目标值越来越小),导致了挖矿越来越难。

八、区块链的分叉

即使区块链是可靠的,现在还有一个问题没有解决:如果两个人同时向区块链写入数据,也就是说,同时有两个区块加入,因为它们都连着前一个区块,就形成了分叉。这时应该采纳哪一个区块呢?


现在的规则是,新节点总是采用最长的那条区块链。如果区块链有分叉,将看哪个分支在分叉点后面,先达到6个新区块(称为”六次确认”)。按照10分钟一个区块计算,一小时就可以确认。


由于新区块的生成速度由计算能力决定,所以这条规则就是说,拥有大多数计算能力的那条分支,就是正宗的比特链。

区块链作为无人管理的分布式数据库,从2009年开始已经运行了9年,没有出现大的问题。这证明它是可行的。

但是,为了保证数据的可靠性,区块链也有自己的代价。一是效率,数据写入区块链,最少要等待十分钟,所有节点都同步数据,则需要更多的时间;二是能耗,区块的生成需要矿工进行无数无意义的计算,这是非常耗费能源的。

九、区块链的10大应用场景

☞金融服务:在一些私募与众筹项目上,利用区块链交易流程可以缩短周期。

☞医疗健康:应用于医院挂号、数字病例。将这些数据记录在链上,可以保证我们的健康数据不被侵犯。

☞IP版权:有利于维权。利用区块链技术,把数字资产记录在链上,第三方继续使用IP版权的时候,就可以通过技术追溯到谁在用,什么时候发生的。

☞教育:学籍证明、档案管理、学生征信、成绩证明、产学合作等。利用区块链都可以把教育上的数据通过一种资产的方式存储在分布式的数据库当中,可以永久保留。

☞物联网:物品的溯源、防伪、认证,还有网络效率提升,可以把每个物品当成一个节点进行存储流转。

☞共享经济:租车租房、智能硬件租赁、知识技能租赁。它可以把这些资产本身放在区块链的链条当中,对于使用权,进行流转,享受一些使用权的费用。

☞通信:区块链技术可以让每个人的社交ID进行确权,比如在运营商的社交数据,它可以变成一种资产进行管理。

☞社会管理:身份认证、档案管理、公证遗产继承、个人及社会信用等。以区块链技术进行记录,放在分布式数据库当中,永久保存。

☞慈善公益:可以实现整个捐助流程的阳光化。

☞文化娱乐:视频版权、音乐版权、软件防伪数字等。它们本身属于数字资产,容易被追诉,容易被记录,容易被进行透明化改造。

我国在2017年上半年已经发布国内首个区块链标准,这为我国抢占国际先机奠定坚实基础。在已纳入《“十三五”国家信息化规划》的基础上,专家建议着力细化区块链技术发展路径,明确具体的发力点、攻坚领域、对标方向。

十、区块链的分类

信息上网,价值上链,互联网传递信息,区块链传递价值。目前区块链的项目可以大致分为三类:

1)公有区块链:世界上任何个体或者团体都可以发送交易,且交易能够获得该区块链的有效确认,任何人都可以参与其共识过程。公有区块链是最早的区块链,也是目前应用最广泛的区块链,各大bitcoins系列的虚拟数字货币均基于公有区块链,世界上有且仅有一条该币种对应的区块链。

2)行业区块链:由某个群体内部指定多个预选的节点为记账人,每个块的生成由所有的预选节点共同决定(预选节点参与共识过程),其他接入节点可以参与交易,但不过问记账过程(本质上还是托管记账,只是变成分布式记账,预选节点的多少,如何决定每个块的记账者成为该区块链的主要风险点),其他任何人可以通过该区块链开放的API进行限定查询。

3)私有区块链:仅仅使用区块链的总账技术进行记账,可以是一个公司,也可以是个人,独享该区块链的写入权限,本链与其他的分布式存储方案没有太大区别。保守的巨头(传统金融)都是想实验尝试私有区块链,而公链的应用例如bitcoin已经工业化,私链的应用产品还在摸索当中。

现在关于区块链的项目成千上万,尽管没几个是成熟的,但人们更愿意相信,这就是1995-1996年的重现,那时候谁能想到互联网给人类带来的巨大改变呢?


What is blockchain? In a word, it is a special kind of distributed database.


First of all, the main function of blockchain is to store information. Any information that needs to be saved can be written to the blockchain and read from it, so it is a database.

Secondly, anyone can set up a server, join the blockchain network, and become a node. In the world of blockchain, there is no central node. Every node is equal and stores 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.

2. The biggest feature of blockchain

Distributed databases are not a new invention, and there have been such products on the market for a long time. However, blockchain has a revolutionary feature.

The blockchain has no administrator and is completely centerless. Other databases have administrators, but blockchain does not. If one wanted to add auditing to the blockchain, it would not be possible because it is designed to prevent the emergence of a central authority.

It is precisely because it cannot be managed that the blockchain cannot be controlled. Otherwise, once big companies and large groups control the management, they will control the entire platform, and other users will have to take orders from them.

However, without an administrator, everyone can write data into it. How can we ensure that the data is trustworthy? What should I do if I am changed by a bad person? Please read on, this is the wonderful place of blockchain.

3. Block

The blockchain is composed of blocks. Blocks are much like database records. Every time data is written, a block is created.


Each block contains two parts.

Block header (Head): records meta information of the current block

Block body (Body): actual data

The block header contains the current block multiple meta-information.

Generation time

Hash of actual data (i.e. block body)

Hash of the previous block

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


The so-called Hash means that the computer can calculate a feature 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. 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 string 123 is a8fdc205a9f19cc1c7507a60c4f01b13d11d7fd0 (hexadecimal), which is 256 bits when converted to binary, and only 123 can get this Hash. Therefore, there are two importantinference.

Corollary 1: The Hash of each block is different, and the block can be identified by Hash.

Corollary 2: If the content of the block changes, its Hash will definitely change.

4. The non-modifiable nature of Hash

Blocks and Hash are in one-to-one correspondence, and the Hash of each block is calculated against the "block header" (Head).

Hash = SHA256 (block header)

The above is the calculation formula of block Hash. Hash is uniquely determined by the block header. SHA256 is the Hash algorithm of the blockchain.

As mentioned before, the block header contains a lot of content, including the hash of the current block body (note that it is the hash of the "block body", not the entire block), and the hash of the previous block. Hash. This means that if the content of the current block changes, or the Hash of the previous block changes, it will definitely cause the Hash of the current block to change.

This is of great significance to the blockchain. If someone modifies a block, the hash of the block changes. In order for subsequent blocks to still be connected to it, the person must modify all subsequent blocks at the same time, otherwise the modified blocks will be out of the blockchain. Due to the reasons mentioned later, Hash calculation is very time-consuming, and it is almost impossible to modify multiple blocks at the same time, unless someone controls more than 51% of the computing power of the entire network.

It is through this linkage mechanism that the blockchain ensures its own reliability. Once the data is written, it cannot be tampered with. This is just like history, what happened happened, and it can’t be changed from now on.


Each block is connected to the previous block, which is also the origin of the name "blockchain".

5. Mining

Since synchronization between nodes must be ensured, new blocks cannot be added too fast. Just imagine, you have just synchronized a block and are preparing to generate the next block based on it, but at this time, another node generates a new block, and you have to give up half of the calculations and synchronize again. Because each block can only be followed by one block, you can only generate the next block after the latest block. So, you have no choice but to sync as soon as you hear the signal.

So, the inventor of the blockchain, Satoshi Nakamoto (this is a pseudonym, his true identity is still unknown), deliberately made it difficult to add new blocks. His design is that on average, the entire network can generate a new block every 10 minutes, which is only six per hour.

This output speed is not achieved through commands, but by deliberately setting up massive calculations. In other words, only through an extremely large amount of calculations can the effective hash of the current block be obtained and the new block added to the blockchain. Due to the amount of calculationIt's too big, so I can't get up quickly.

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

6. Difficulty coefficient

You may have a question. People say that mining is difficult, but isn’t mining just about using a computer to calculate a Hash? This is the strength of computers. How could it become It’s very difficult. Why can’t I figure it out?

It turns out that not any Hash can be used. Only Hash that meets the conditions will be accepted by the blockchain. This condition is particularly harsh, causing most hashes to fail to meet the requirements and must be recalculated.

It turns out that the block header contains a difficulty coefficient (difficulty), which determines the difficulty of calculating the Hash. For example, the difficulty coefficient of the 100,000th block is 14484.16236122.


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


The effectiveness of Hash is closely related to the target value. Only 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 that the Hash is smaller than this value is extremely slim. It may be calculated 1 billion times before it is considered a hit. This is the fundamental reason why mining is so slow.

There is also a Nonce value in the block header, which records the number of Hash recalculations. The Nonce value of the 100,000th block is 274148111, which means that after 274 million calculations, a valid Hash is obtained and the block can be added to the blockchain.

7. Dynamic adjustment of difficulty coefficient

Even if mining is difficult, there is no guarantee that a block will be produced in exactly ten minutes. Sometimes it is calculated in one minute, and sometimes there may be no results in a few hours. Overall, with the improvement of hardware equipment and the increase in the number of mining machines, the computing speed will definitely become faster and faster.

In order to keep the output rate constant at ten minutes, Satoshi Nakamoto also designed a dynamic adjustment mechanism for the difficulty coefficient. He stipulated that the difficulty coefficient should be adjusted every two weeks (2016 blocks). If the average block generation speed in these two weeks is 9 minutes, it means that it is 10% faster than the legal speed, so the difficulty factor needs to be increased by 10%; if the average block generation speed is 11 minutes, it means that it is 10% faster than the legal speed. The speed is 10% slower, so the difficulty coefficient needs to be lowered by 10%.

The difficulty coefficient is adjusted higher and higher (the target value is getting smaller and smaller), making mining more and more difficult.

8. Forks of the blockchain

Even if the blockchain is reliable, there is still an unresolved problem: if two people simultaneouslyWriting data to the blockchain, that is, two blocks are added at the same time, because they are both connected to the previous block, forming a fork. Which block should be adopted at this time?


The current rule is that new nodes always use the longest blockchain. If there is a fork in the blockchain, it will look at which branch is behind the fork and reaches 6 new blocks first (called "six confirmations"). Based on a block calculation of 10 minutes, it can be confirmed in one hour.


Since the generation speed of new blocks is determined by computing power, this rule means that the branch with the most computing power is the authentic Bitcoin chain.

Blockchain, as an unmanaged distributed database, has been running for 9 years since 2009 without major problems. This proves it works.

However, in order to ensure the reliability of data, blockchain also has its own price. The first is efficiency. You have to wait at least ten minutes to write data to the blockchain. All nodes need to synchronize the data, which requires more time. The second is energy consumption. The generation of blocks requires miners to perform countless meaningless calculations. This is Very energy consuming.

9. Top 10 application scenarios of blockchain

☞Financial services: In some private equity and crowdfunding projects, the use of blockchain transaction processes can shorten the cycle.

☞Medical health: applied to hospital registration and digital cases. Recording this data on the chain can ensure that our health data is not infringed.

☞IP copyright: conducive to rights protection. Using blockchain technology to record digital assets on the chain, when a third party continues to use IP copyright, it can be traced back to who is using it and when it happened through technology.

☞Education: student status certificate, file management, student credit report, achievement certificate, industry-university cooperation, etc. Using blockchain, educational data can be stored in a distributed database as an asset and can be retained permanently.

☞Internet of Things: Traceability, anti-counterfeiting, authentication of items, and improvement of network efficiency. Each item can be treated as a node for storage and circulation.

☞Sharing economy: car rental, smart hardware rental, knowledge and skill rental. It can put these assets themselves in the blockchain chain, transfer the usage rights, and enjoy some fees for the usage rights.

☞Communication: Blockchain technology can allow everyone’s social ID to be confirmed. For example, in an operator’s social data, it can be turned into an asset for management.

☞Social management: identity authentication, file management, notarized inheritance, personal and social credit, etc. Recorded using blockchain technology, placed in a distributed database, and stored permanently.

☞Philanthropy: The entire donation process can be made transparent.

☞Culture and entertainment: video copyright, music copyright, software anti-counterfeiting numbers, etc. They are digital assets themselves, which are easy to be prosecuted, recorded, and invaded.Carry out transparent transformation.

my country has released its first domestic blockchain standard in the first half of 2017, which has laid a solid foundation for my country to seize international opportunities. On the basis of being included in the "Thirteenth Five-Year Plan for National Informatization", experts suggest focusing on refining the development path of blockchain technology and clarifying specific focus, key areas, and benchmarking directions.

10. Classification of Blockchain

Information goes online, value goes to the chain, the Internet transmits information, and blockchain transmits value. Current blockchain projects can be roughly divided into three categories:

1) Public blockchain: Any individual or group in the world can send transactions, and the transactions can be effectively confirmed by the blockchain, Anyone can participate in its consensus process. The public blockchain is the earliest blockchain and is currently the most widely used blockchain. The virtual digital currencies of all major bitcoins series are based on the public blockchain. There is only one block corresponding to this currency in the world. chain.

2) Industry blockchain: Multiple pre-selected nodes are designated within a certain group as bookkeepers, and the generation of each block is jointly decided by all pre-selected nodes (the pre-selected nodes participate in the consensus process), Other access nodes can participate in transactions, but are not involved in the accounting process (it is essentially still managed accounting, but becomes distributed accounting. How many nodes are pre-selected, and how to determine the bookkeeper of each block to become the blockchain Main risk point), anyone else can conduct limited queries through the API opened by the blockchain.

3) Private blockchain: only uses the general ledger technology of the blockchain for accounting. It can be a company or an individual, with exclusive write permission to the blockchain. This chain is the same as Other distributed storage solutions are not much different. Conservative giants (traditional finance) all want to experiment with private blockchains, while public chain applications such as Bitcoin have been industrialized, and private chain application products are still being explored.

There are thousands of blockchain projects now. Although few are mature, people are more willing to believe that this is a recurrence of 1995-1996. At that time, who could have imagined that the Internet would bring What about the huge changes humans have brought about?

本文来源: 网络 文章作者: 网络投稿
    下一篇

① 股指期货如何计算卖出或买入期货的合约数 要详细的过程和解答期现货价值比等于β,那么现货价值是2.25亿元,期货价值是 合约数量*5700*300(因为沪深300指数合约每点300元),那么就可以得