区块链工作原理

Posted 活在当下_L

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了区块链工作原理相关的知识,希望对你有一定的参考价值。

 
Blockchains are incredibly popular nowadays.
 
区块链技术如今非常的流行
 
But what is a blockchain?
 
但是,区块链到底是什么呢?
 
How do they work, what problems do they solve and how can they be used?
 
区块链是如何工作的,它解决了哪些问题,并且它又有哪些用途呢?
 
Like the name indicates, a blockchain is a chain of blocks that contains information.
 
顾名思义,区块链是由一组包含信息的信息块组成的信息链。
 
This technique was originally described in 1991 by a group of researchers and was originally
 
区块链技术最早是在1991年由一群研究人员研发并用来给数字化文档打时间戳
 
intended to timestamp digital documents so that it’s not possible to backdate them
 
以使得这些文档不能被倒填日期
 
or to tamper with them.
 
或者被篡改。
 
Almost like a notary.
 
看上去区块链技术就像一位公证人一样。
 
However it went by mostly unused until it was adapted by Satoshi Nakamoto in 2009 to
 
然而,这个技术从那之后就基本上没有再发挥其他作用,直到2009年
 
create the digital cryptocurrency Bitcoin.
 
中本聪采用区块链技术创造了数字加密货币-比特币。
 
A blockchain is a distributed ledger that is completely open to anyone.
 
一条区块链,就是一个对所有人完全公开的分布式账本
 
They have an interesting property: once some data has been recorded inside a blockchain,
 
它有一个很有趣的属性:一旦某些数据被记录到一条区块链中后,
 
it becomes very difficult to change it.
 
那么数据就很难再被改变。
 
So how does that work?
 
所以,它到底是如何工作的呢?
 
Well, let’s take a closer look at a block.
 
接下来,让我们来观察一个区块(block)的组成
 
Each block contains some data, the hash of the block and the hash of the previous block.
 
每一个区块包含了一些数据,这个区块的哈希值,以及前一个区块的哈希值。
 
The data that is stored inside a block depends on the type of blockchain.
 
并且,区块中所保存的数据与区块链的类型有关。
 
The Bitcoin blockchain for example stores the details about a transaction in here, such
 
例如,比特币区块链中的区块保存了相关的交易信息,
 
as the sender, receiver and amount of coins.
 
包括卖家,买家,以及交易比特币的数量。
 
A block also has a hash.
 
每个区块包含了一个哈希值。
 
You can compare a hash to a fingerprint.
 
你可以把哈希值理解成指纹。
 
It identifies a block and all of its contents and it’s always unique, just as a fingerprint.
 
哈希值用来标识一个区块和它所包含的所有内容,并且它总是唯一的,就像指纹一样。
 
Once a block is created, it’s hash is being calculated.
 
一旦某个区块被创建,它的哈希值就相对应的被计算出来了。
 
Changing something inside the block will cause the hash to change.
 
改变区块中的某些内容会使得哈希值改变。
 
So in other words: hashes are very useful when you want to detect changes to blocks.
 
所以换句话说:当你想要检测区块中内容的改变时,哈希值对你就很有帮助。
 
If the fingerprint of a block changes, it no longer is the same block.
 
如果一个区块的指纹改变了,那它就再也不是之前的区块了。
 
The third element inside each block is the hash of the previous block.
 
区块中包含的第三个元素是前一个区块的哈希值。
 
This effectively creates a chain of blocks and it’s this technique that makes a blockchain
 
这个元素使得区块之间可以形成链接,并且能够使得区块链
 
so secure.
 
十分的安全。
 
Let’s take an example.
 
举个例子
 
Here we have a chain of 3 blocks.
 
假设我们有一条区块链包含3个区块
 
As you can see, each block has a hash and the hash of the previous block.
 
如图所示,每个区块包含了一个自己的哈希值以及前一个区块的哈希值
 
So block number 3 points to block number 2 and number 2 points to number 1.
 
所以3号区块指向2号区块,2号区块又指向1号区块。
 
Now the first block is a bit special, it cannot point to previous blocks because it’s the
 
但是现在1号区块有点特殊,它不能指向前一个区块,因为
 
first one.
 
它是第一个区块。
 
We call this the genesis block.
 
我们把1号区块叫做创世区块。
 
Now let’s say that you tamper with the second block.
 
那么,现在我们假设你篡改了第二个区块。
 
This causes the hash of the block to change as well.
 
这将导致第二个区块的哈希值改变。
 
In turn that will make block 3 and all following blocks invalid because they no longer store
 
接下来这就会导致3号区块以及3号区块连接的所有的后续区块变得非法,因为现在它们存储的
 
a valid hash of the previous block.
 
前一个区块号的都变得非法。
 
So changing a single block will make all following blocks invalid.
 
所以改变一个区块会使得其后所有连接的区块变得非法
 
But using hashes is not enough to prevent tampering.
 
但是,仅仅使用哈希值的方法不足以防止用户篡改区块。
 
Computers these days are very fast and can calculate hundreds of thousands of hashes per second.
 
因为现在的计算机运算速度已经足够强大,并且能够每秒计算成千上万的哈希值。
 
You could effectively tamper with a block and recalculate all the hashes of other blocks
 
你完全可以篡改一个区块并且重新计算其他的区块的哈希值,
 
to make your blockchain valid again.
 
这样就使得你的区块再次变得合法。
 
So to mitigate this, blockchains have something called proof-of-work.
 
所以为了减少这种风险,区块链还采用了一种技术叫做工作量证明。
 
It’s a mechanism that slows down the creation of new blocks.
 
这是一种减缓新区块创建过程的机制。
 
In Bitcoins case: it takes about 10 minutes to calculate the required proof-of-work and
 
在比特币区块链中,大概需要花费10分钟来完成所要求的工作量证明,
 
add a new block to the chain.
 
并且添加一个新的区块到区块链中。
 
This mechanism makes it very hard to tamper with the blocks, because if you tamper with
 
这个机制使得区块链的篡改更加困难,因为一旦
 
1 block, you’ll need to recalculate the proof-of-work for all the following blocks.
 
你篡改了一个区块,你需要重新计算所有后续的区块的工作量证明。
 
So the security of a blockchain comes from its creative use of hashing and the proof-of-work mechanism.
 
所以区块链技术的安全性主要来自于哈希值以及工作量证明机制。
 
But there is one more way that blockchains secure themselves and that’s by being distributed.
 
但是,区块链还有一种机制来保护自身的安全性,那就是分布式。
 Instead of using a central entity to manage the chain, blockchains use a peer-to-peer
 
相对于用一个中心化的实体来管理区块链网络,区块链采用的是一种peer-to-peer
 
network and anyone is allowed to join.
 
网络,并且所有人都可以加入。
 
When someone joins this network, he gets the full copy of the blockchain.
 
当有人加入这个网络时,他就会得到整个区块链的复制。
 
The node can use this to verify that everything is still in order.
 
这个人就可以以此来验证是否所有的区块还是合法未篡改的。
 
Now let’s see what happens when someone creates a new block.
 
那么接下来我们就来看看,当某人创建了一个新的区块时,会发生哪些改变
 
That new block is send to everyone on the network.
 
这个新的区块会被发送给网络上的所有人。
 
Each node then verifies the block to make sure that it hasn’t been tampered with.
 
每个人再验证这个区块以确保这个区块没有被篡改过
 
If everything checks out, each node adds this block to their own blockchain.
 
 如果所有的东西都被检验正确之后,那么每个人就都会把这块新的区块加到自己的区块链上。
 
 All the nodes in this network create consensus.
 
我们可以称之为,网络上的所有人达成了“共识”。
 
They agree about what blocks are valid and which aren’t.
 
他们认同网络中那些区块是合法的,哪些是不合法的。
 
Blocks that are tampered with will be rejected by other nodes in the network.
 
那些被篡改过的区块将会被网络上的其他用户拒绝。
 
So to successfully tamper with a blockchain you’ll need to tamper with all blocks on the
 
所以,要成功篡改一个区块链,你需要篡改区块链上的所有区块,
 
chain, redo the proof-of-work for each block and take control of more than 50% of the peer-to-peer network.
 
重新完成每个区块的工作量证明,并且控制区块链网络中超过50%的用户
 
Only then will your tampered block become accepted by everyone else.
 只有这样,你篡改的区块才会被所有人承认。
 
This is almost impossible to do!
 
可以说,这基本上是不可能做得到的!
 
Blockchains are also constantly evolving.
 
区块链技术本身也在不断地发展。
 
One of the more recent developments is the creation of smart contracts.
 
最近的一个技术改进,叫做智能合约。
 
These contracts are simple programs that are stored on the blockchain and can be used to
 
智能合约是一些存放在区块链上的简单的程序,
 
automatically exchange coins based on certain conditions.
 
并且在特定条件下可以实现自动化比特币交易。
 
More on smart contracts in a later video.
 
我们将会在后续的视频中讲解智能合约。
 
The creation of blockchain technology peaked a lot of people’s interest.
 
区块链技术的诞生吸引了很多人的目光,
 
Soon, others realized that the technology could be used for other things like storing
 
在其诞生不久之后,一些人意识到区块链技术可以用来
 
medical records, creating a digital notary or even collecting taxes.
 存放病史档案,创造数字化公证甚至还可以用来收税。
 
So now you know what a blockchain is, how it works on basic level and what problems it solves.
 
那么,到这里,你应该已经明白区块链基本的工作原理,以及它到底解决了哪些问题吧。
 

以上是关于区块链工作原理的主要内容,如果未能解决你的问题,请参考以下文章

区块链启示录:中本聪文集二: 比特币的工作原理(下)

五分钟看明白区块链,工作证明(POW)代码+原理 golang版剖析

[GO]用go语言实现区块链工作原理

区块链启示录:中本聪文集一:前言 | 比特币的工作原理(上)

区块链教程——挖矿原理

区块链原理(结合实际例子较详细的讲述原理)