转自:https://cloud.tencent.com/developer/article/1838661
From: https://clud.tencent.com/development/article/1838661
本文主要是对区块链进行概念分析和组成技术解析,从哈希运算、数字签名、共识算法、智能合约、P2P网络等技术在区块链中的应用进行综合分析
This paper focuses on conceptual analysis and technical composition of the block chain, and a comprehensive analysis of applications in the block chain from technologies such as Hasi operations, digital signatures, consensus algorithms, smart contracts, P2P networks, etc.
区块链(blockchain) 是一种数据以 区块(block) 为单位产生和存储,并按照时间顺序首尾相连形成 链式(chain) 结构,同时通过密码学保证不可篡改、不可伪造及数据传输访问安全的去中心化分布式账本。区块链中所谓的账本,其作用和现实生活中的账本基本一致,按照一定的格式记录流水等交易信息。特别是在各种数字货币中,交易内容就是各种转账信息。只是随着区块链的发展,记录的交易内容由各种转账记录扩展至各个领域的数据。比如,在供应链溯源应用中,区块中记录了供应链各个环节中物品所处的责任方、位置等信息。
区块是链式结构的基本数据单元,聚合了所有交易相关信息,主要包含区块头和区块主体两部分。区块头主要由父区块哈希值(Previous Hash)、时间戳(Timestamp)、默克尔树根(Merkle TreeRoot)等信息构成;区块主体一般包含一串交易的列表。每个区块中的区块头所保存的父区块的哈希值,便唯一地指定了该区块的父区块,在区块间构成了连接关系,从而组成了区块链的基本数据结构。
Blocks are the basic data unit of the chain structure, which aggregates all relevant information on transactions, mainly the head of the block and the head of the block. The head of the block consists mainly of the Previous Hash value of the parent block , the time stamp of the block
区块链的基础技术主要包括: 哈希运算、数字签名、P2P网络、共识算法以及智能合约等
The basic technologies of the block chain include: Hashi operation,
哈希实现防篡改
这个就不多说了,技术都应该明白,主要我们看看它是怎么防篡改。在区块链中,每个区块头部包含了上一个区块数据的哈希值,这些哈希层层嵌套,最终将所有区块串联起来,形成区块链。区块链里包含了自该链诞生以来发生的所有交易,因此,要篡改一笔交易,意味着它之后的所有区块的父区块哈希全部要篡改一遍。这需要进行大量的运算。如果想要篡改数据,必须靠伪造交易链实现,即保证在正确的区块产生之前能快速地运算出伪造的区块。同时在以比特币为代表的区块链系统要求连续产生一定数量的区块之后,交易才会得到确认,即需要保证连续伪造多个区块。只要网络中节点足够多,连续伪造的区块运算速度都超过其他节点几乎是不可能实现的。另一种可行的篡改区块链的方式是,某一利益方拥有全网超过 的算力,利用区块链中少数服从多数的特点,篡改历史交易。然而在区块链网络中,只要有足够多的节点参与,控制网络中 的算力也是不可能做到的。即使某一利益方拥有了全网超过 的算力,那已经是既得利益者,肯定会更坚定地维护区块链网络的稳定性。
In the block chain, each block has its head that contains the Hash value of the previous block data, and these Hashi layers are embedded, and eventually all the blocks are bound together to form a block chain. The chain contains all the transactions that have taken place since the chain was born, so that it is necessary to tamper with a transaction that means that all of its subsequent sections have to be tampered with. This requires a lot of calculations. If the data are to be tampered with, it must be done quickly before the right block is created. At the same time, the chain system of blocks, represented by bitcoins, requires a number of blocks to be created.
通过哈希构建默克尔树,实现内容改变的快速检测
在区块链中默克尔树就是当前区块所有交易信息的一个哈希值。但是这个哈希值并不是直接将所有交易内容计算得到的哈希,而是一个 哈希二叉树。首先对每笔交易计算哈希值;然后进行两两分组,对这两个哈希值再计算得到一个新的哈希值,两个旧的哈希值就作为新哈希值的叶子节点,如果哈希值数量为单数,则对最后一哈希值再次计算哈希值即可;然后重复上述计算,直至最后只剩一个哈希值,作为默克尔树的根,最终形成一个二叉树的结构。
In the chain of blocks, the Merkel tree is a Hashi value for all transactions in the current block. But this Hashi value is not a Hashi that directly calculates all transactions, but a
在区块链中,我们只需要保留对自己有用的交易信息,删除或者在其他设备备份其余交易信息。如果需要验证交易内容,只需验证默克尔树即可。若根哈希验证不通过,则验证两个叶子节点,再验证其中哈希验证不通过的节点的叶子节点,最终可以准确识别被篡改的交易。
In the block chain, we just need to keep the transaction information that is useful to ourselves, delete it or back up the rest of the transaction information with other devices. If you need to verify the transaction, you just need to verify the Merkel Tree. If Genhashi does not pass, we need to verify the two leaf nodes, then we need to verify the node in which Hashi authenticates the node that is not passed, so that the altered transaction can eventually be accurately identified.
默克尔树在生活中其他领域应用也非常广泛。例如 ,数据一般会分成很多个小块,以保证快速下载。在下载前,先下载该文件的一个默克尔树,下载完成后,重新生成默克尔树进行对比校验。若校验不通过,可根据默克尔树快速定位损坏的数据块,重新下载即可。
Merkel trees are also very widely used in other areas of life. For example, data are usually divided into many small blocks to ensure quick downloads. Before downloading, a Merkel tree downloads the file and, after downloading it, regenerates the Merkel tree for a comparative check. If the check is not passed, re-downloading can be done on the Merkel tree as quickly as possible.
在密码学领域,一套数字签名算法一般包含签名和验签两种运算,数据经过签名后,非常容易验证完整性,并且不可抵赖。只需要使用配套的验签方法验证即可,不必像传统物理签名一样需要专业手段鉴别。数字签名通常采用非对称加密算法,即每个节点需要一对私钥、公钥密钥对。所谓私钥即只有本人可以拥有的密钥,签名时需要使用私钥。不同的私钥对同一段数据的签名是完全不同的,类似物理签名的字迹。数字签名一般作为额外信息附加在原消息中,以此证明消息发送者的身份。公钥即所有人都可以获取的密钥,验签时需要使用公钥。因为公钥人人可以获取,所以所有节点均可以校验身份的合法性。
In the cryptography field, a digital signature algorithm typically contains both signatures and signatures, and the data are easy to verify integrity and irreconcilable once they have been signed. It only needs to be validated by an accompanying signature method, without the need for professional identification like traditional physical signatures. Digital signatures usually use asymmetric encryption algorithms, i.e., each node requires a pair of private keys and a public key pair. The so-called private key is only the key that the person can own, and the private key is required to be used when signing. The signature of the same paragraph of the data is completely different, similar to a physical signature. The digital signature is usually attached to the original message as additional information to prove the identity of the sender. The public key is the key that all people can access, and the public key is required to be used when signing. Because the public key is available, all the public key is valid for checking the legitimacy of the identity.
流程如下:
The process is as follows:
在区块链网络中,每个节点都拥有一份公私钥对。节点发送交易时,先利用自己的私钥对交易内容进行签名,并将签名附加在交易中。其他节点收到广播消息后,首先对交易中附加的数字签名进行验证,完成消息完整性校验及消息发送者身份合法性校验后,该交易才会触发后续处理流程。这对应到前文 比特币的通俗故事 一节中村民验证喊出交易者的声音,确保是张三自己发出的交易。
In the block chain network, each node has a public-private key pair. When a transaction is sent, the transaction is signed using its own private key and the signature is attached to the transaction. After the other node has received the broadcast message, the digital signature attached to the transaction is verified and the integrity of the message is verified and the sender's identity is authenticated before the transaction triggers the follow-up process. This will go to the popular story in the previous section of the < strong > bitcoin > to verify the sound of the caller and ensure that the transaction is made by Zhang San himself.
为什么要共识?
区块链通过全民记账来解决信任问题,但是所有节点都参与记录数据,那么最终以谁的记录为准?或者说,怎么保证所有节点最终都记录一份相同的正确数据,即达成共识?在传统的中心化系统中,因为有权威的中心节点背书,因此可以以中心节点记录的数据为准,其他节点仅简单复制中心节点的数据即可,很容易达成共识。然而在区块链这样的去中心化系统中,并不存在中心权威节点,所有节点对等地参与到共识过程之中。由于参与的各个节点的自身状态和所处网络环境不尽相同,而交易信息的传递又需要时间,并且消息传递本身不可靠,因此,每个节点接收到的需要记录的交易内容和顺序也难以保持一致。更不用说,由于区块链中参与的节点的身份难以控制,还可能会出现恶意节点故意阻碍消息传递或者发送不一致的信息给不同节点,以干扰整个区块链系统的记账一致性,从而从中获利的情况。因此,区块链系统的记账一致性问题,或者说共识问题,是一个十分关键的问题,它关系着整个区块链系统的正确性和安全性。
In traditional central systems, where there is an authoritative endorsement of central nodes, it is easy to reach a consensus. However, in a decentralized system such as a block chain, there is no central authority node, where all nodes are involved in the consensus process. Or, how is it possible to ensure that all nodes are eventually recorded with the same correct data, i.e., consensus? In traditional central systems, where there is an authoritative central node endorsement, other nodes can simply reproduce central node data. Not to mention the fact that the identity of the nodes involved in the node chain is difficult to control, and there may be malicious nodes deliberately obstructing the transmission of information or sending inconsistent information to different nodes in order to disrupt the consistency of the entire system in order to benefit from it, given that the transmission of information is unreliable?
有哪些共识算法?
当前区块链系统的共识算法有许多种,主要可以归类为如下四大类:
There are many kinds of consensus algorithms for the current block chain system, which can be grouped mainly into the following four main categories:
- 工作量证明(Proof of Work, PoW)类的共识算法;
- Po*的凭证类共识算法;
- 拜占庭容错(Byzantine Fault Tolerance, BFT)类算法;
- 结合可信执行环境的共识算法。
POW共识算法
类的共识算法主要包括区块链鼻祖比特币所采用的 共识及一些类似项目(如莱特币等)的变种 ,即为大家所熟知的 挖矿 类算法。这类共识算法的核心思想实际是所有节点竞争记账权,而对于每一批次的记账(或者说,挖出一个区块)都赋予一个 难题,要求只有能够解出这个难题的节点挖出的区块才是有效的。同时,所有节点都不断地通过试图解决难题来产生自己的区块并将自己的区块追加在现有的区块链之后,但全网络中只有最长的链才被认为是合法且正确的。
The consensus algorithm of the class consists mainly of the consensus adopted in the block chain and some variants of similar projects (e.g., Letco) known as the mining algorithm. The core idea of such consensus algorithms is that all nodes actually compete for the right to account, while for each batch (or, for example, to excavate a block) a difficulty requires that only the blocks that can be dug out of the node that solves the problem is valid. At the same time, all nodes constantly try to create their own blocks by resolving them and add their own blocks after the existing chain of blocks, but only the longest of the entire network is considered legitimate and correct.
比特币类区块链系统采取这种共识算法的巧妙之处在于两点:首先,它采用的 难题 具有难以解答,但很容易验证答案的正确性的特点,同时这些难题的 难度,或者说全网节点平均解出一个难题所消耗时间,是可以很方便地通过调整难题中的部分参数来进行控制的,因此它可以很好地控制链增长的速度。同时,通过控制区块链的增长速度,它还保证了若有一个节点成功解决难题完成了出块,该区块能够以(与其他节点解决难题速度相比)更快的速度在全部节点之间传播,并且得到其他节点的验证的特性;这个特性再结合它所采取的 最长链有效 的评判机制,就能够在大多数节点都是诚实(正常记账出块,认同最长链有效)的情况下,避免恶意节点对区块链的控制。这是因为,在诚实节点占据了全网 以上的算力比例时,从期望上讲,当前最长链的下一个区块很大概率也是诚实节点生成的,并且该诚实节点一旦解决了 难题 并生成了区块,就会在很快的时间内告知全网其他节点,而全网的其他节点在验证完毕该区块后,便会基于该区块继续解下一个难题以生成后续的区块,这样以来,恶意节点很难完全掌控区块的后续生成。
The trick of adopting this consensus algorithm for the Bitcoin block chain system is two: first, it uses the difficulty , which is difficult to answer, but which can easily verify the correctness of the answer, while the difficulty of /strung >, or the average amount of time it takes to solve a problem, can easily be controlled by adjusting some of the parameters in the puzzle. At the same time, the growth of the chain can be well controlled. At the same time, if one node succeeds in resolving the problem , the node can spread faster than the node , and the node can spread faster than the other node >, which, in conjunction with the assessment mechanism, will continue to generate the node at most of the node.
类的共识算法所设计的 难题 一般都是需要节点通过进行大量的计算才能够解答的,为了保证节点愿意进行如此多的计算从而延续区块链的生长,这类系统都会给每个有效区块的生成者以一定的奖励。比特币中解决的难题即寻找一个符合要求的随机数。然而不得不承认的是, 类算法给参与节点带来的计算开销,除了延续区块链生长外无任何其他意义,却需要耗费巨大的能源,并且该开销会随着参与的节点数目的上升而上升,是对能源的巨大浪费。
In order to ensure that nodes are willing to make so many calculations to continue the growth of the block chain, such systems offer a certain incentive to the generator of each effective block. The solution in Bitcoin is to find a random number that meets the requirements. It must be acknowledged, however, that the calculation cost of the node of the node of the node of the node of the node of the node of the node of the node of participation, which has no other meaning than to continue the node of the node, is costly of energy, and that it increases as the number of nodes in the node of the node of participation rises and is a great waste of energy.
Po*的凭证类共识算法
鉴于的缺陷,人们提出了一些的替代者—— 。这类算法引入了 凭证 的概念(即 中的 ,代表各种算法所引入的凭证类型):根据每个节点的某些属性(拥有的币数、持币时间、可贡献的计算资源、声誉等),定义每个节点进行出块的难度或优先级,并且取凭证排序最优的节点,或是取凭证最高的小部分节点进行加权随机抽取某一节点,进行下一段时间的记账出块。这种类型的共识算法在一定程度上降低了整体的出块开销,同时能够有选择地分配出块资源,即可根据应用场景选择 凭证 的获取来源,是一个较大的改进。然而,凭证的引入提高了算法的中心化程度,一定程度上有悖于区块链 去中心化 的思想,且多数该类型的算法都未经过大规模的正确性验证实验,部分该类算法的矿工激励不够明确,节点缺乏参与该类共识的动力。
Given the shortcomings, a number of alternatives have been proposed. Such algorithms have introduced the concept of
BFT类算法
无论是 类算法还是 类算法,其中心思想都是将所有节点视作竞争对手,每个节点都需要进行一些计算或提供一些凭证来竞争出块的权利(以获取相应的出块好处)。 类算法则采取了不同的思路,它希望所有节点协同工作,通过协商的方式来产生能被所有(诚实)节点认可的区块
Whether algorithms or algorithms, the central idea is to treat all nodes as competitors and each node requires some calculation or some proof of the right to compete for blocks (in order to obtain the corresponding yield). The algorithm takes a different approach, and it wants all nodes to work together to produce, through consultation, blocks that are acceptable to all (honestly) nodes.
具体地, 类共识算法一般都会定期选出一个领导者,由领导者来接收并排序区块链系统中的交易,领导者产生区块并递交给所有其他节点对区块进行验证,进而其他节点“举手”表决时接受或拒绝该领导者的提议。如果大部分节点认为当前领导者存在问题,这些节点也可以通过多轮的投票协商过程将现有领导者推翻,再以某种预先定好的协议协商产生出新的领导者节点。
Specifically, consensus algorithms typically select, on a regular basis, a leader to receive and sort transactions in the block chain system, who generates blocks and transmits them to all other nodes for validation, and then accepts or rejects the leader's proposal when the other nodes “rise their hands” vote. If most nodes believe that there is a problem with the current leader, these nodes can also overturn the existing leader through a multi-round process of voting consultations, and produce a new leader node with some sort of predetermined agreement.
类算法一般都有完备的安全性证明,能在算法流程上保证在群体中恶意节点数量不超过三分之一时,诚实节点的账本保持一致。然而,这类算法的协商轮次也很多,协商的通信开销也比较大,导致这类算法普遍不适用于节点数目较大的系统。业界普遍认为, 算法所能承受的最大节点数目不超过100
Arithmeticals generally have adequate proof of security to ensure consistency in the books of honest nodes when the number of malicious nodes in the group does not exceed one third in the algorithmic process. However, there are many rounds of consultation for such algorithms, and the cost of the negotiated communications is larger, resulting in the fact that such algorithms are generally not suitable for systems with larger nodes.
结合可信执行环境的共识算法
上述三类共识算法均为纯软件的共识算法。除此之外,还有一些共识算法对硬件进行了利用,如一些利用可信执行环境(Trusted Execution Environment, TEE)的软硬件结合的共识算法。
All three types of consensus algorithms are purely software consensus algorithms. In addition, there are consensus algorithms that use hardware, such as some that combines software and hardware using the credible implementation environment (Trusted Exchange Environment, TEE)
可信执行环境是一类能够保证在该类环境中执行的操作绝对安全可信、无法被外界干预修改的运行环境,它与设备上的普通操作系统(Rich OS)并存,并且能给提供安全服务。 A credible enforcement environment is one in which operations performed in that environment are absolutely safe and credible and cannot be modified by outside intervention, coexisting with the general operating system on equipment (Rich OS) and providing security services. 可信执行环境所能够访问的软硬件资源是与完全分离的,从而保证了可信执行环境的安全性。利用可信执行环境,可以对区块链系统中参与共识的节点进行限制,很大程度上可以消除恶意节点的不规范或恶意操作,从而能够减少共识算法在设计时需要考虑的异常场景,一般来说能够大幅提升共识算法的性能。 The hardware and software resources that can be accessed by a credible enforcement environment are completely isolated, thus ensuring the security of a credible enforcement environment. Using a credible enforcement environment, the consensual nodes involved in block chain systems can be restricted to a large extent to eliminate irregularities or malpractices in malicious nodes, thus reducing the anomalies that consensus algorithms need to consider when they are designed, and can generally significantly enhance the performance of consensus algorithms. 简单来说,智能合约是一种在满足一定条件时,就自动执行的计算机程序。例如自动售货机,就可以视为一个智能合约系统。客户需要选择商品,并完成支付,这两个条件都满足后售货机就会自动吐出货物。合约在生活中处处可见:租赁合同、借条等。传统合约依靠法律进行背书,当产生违约及纠纷时,往往需要借助法院等政府机构的力量进行裁决。智能合约,不仅仅是将传统的合约电子化,它的真正意义在革命性地将传统合约的背书执行由法律替换成了代码。俗话说,规则是死的,人是活的 ,程序作为一种运行在计算机上的规则,同样是死的。但是死的也不总是贬义词,因为它意味着会严格执行。 In short, smart contracts are computer programs that are automatically executed when certain conditions are met. Automatic sales machines, for example, can be regarded as an intelligent contract system. Clients need to select commodities and complete payments, and both conditions are met, and the goods will be thrown out automatically. Contracts can be found in life: lease contracts , debits and so forth. Traditional contracts rely on law for endorsement, and when defaults and disputes arise, they often require decisions by government agencies, such as courts. Smart contracts, more than merely electronicizing traditional contracts, the real meaning of which is revolutionaryly replacing the backs execution of traditional contracts with legal codes. 比如,球赛期间的打赌即可以通过智能合约实现。首先在球赛前发布智能合约,规定:今天凌晨2:45,欧冠皇马VS拜仁慕尼黑,如果皇马赢,则小明给我1000元;如果拜仁赢,我给小明1000元。我和小明都将1000元存入智能合约账户,比赛结果发布,皇马4:2胜拜仁,触发智能合约响应条件,钱直接打入我的账户,完成履约。整个过程非常高效、简单,不需要第三方的中间人进行裁决,也完全不会有赖账等问题。 For example, the bets during the game can be made by a smart contract. The first is to issue a smart contract before the game, which provides that: today at 2.45 a.m., the crown horse V.S. Bainmunich, if the horse wins, will give me $1,000; and if Bayon wins, I will give $1,000 to M. Me and M. will deposit $1,000 into the smart contract account, the results will be released, the horse 4:2 Bailin triggers the smart contract response, the money goes directly into my account, and the performance will be done. The process is very efficient and simple, without the need for a third-party intermediary to adjudicate, and there will be no problems of default. 尽管智能合约这个如此前卫的理念早在1995年就被提出,但是一直没有引起广泛的关注。虽然这个理念很美好,但是缺少一个良好的运行智能合约的平台,确保智能合约一定会被执行,执行的逻辑没有被中途修改。区块链这种去中心化、防篡改的平台,完美地解决了这些问题。智能合约一旦在区块链上部署,所有参与节点都会严格按照既定逻辑执行。基于区块链上大部分节点都是诚实的基本原则,如果某个节点修改了智能合约逻辑,那么执行结果就无法通过其他节点的校验而不会被承认,即修改无效。 The idea of a smart contract, which was so advanced, was introduced in 1995 but did not attract widespread attention. Although it was a good idea, the lack of a platform for a good operating smart contract ensured that the smart contract would be enforced, and the logic of its implementation was not modified in the middle. The decentralized and anti-false platform of the block chain was a perfect solution to these problems. Once the smart contract was deployed on the block chain, all participating nodes would be executed in strict accordance with the established logic. Based on the basic principle of honesty, most nodes on the block chain, if one node changed the smart contract logic, the result of implementation would not be verified without recognition of the other nodes, i.e., the modification would be null and void. 一个基于区块链的智能合约需要包括事务处理机制、数据存储机制以及完备的状态机,用于接收和处理各种条件。并且事务的触发、处理及数据保存都必须在链上进行。当满足触发条件后,智能合约即会根据预设逻辑,读取相应数据并进行计算,最后将计算结果永久保存在链式结构中。智能合约在区块链中的运行逻辑如图所示: An intelligent contract based on the block chain would need to include 对应前面打赌的例子,智能合约即为通过代码实现的打赌内容。该智能合约预置的触发条件即为规定球赛场次、时间等相关信息,同时需要规定获取结果途径(例如直接从官网获取结果)。预置响应条件即为触发事件后,智能合约具体执行内容。 As an example of a previous bet, a smart contract is a bet that is made by a code. The smart contract presets the trigger to specify the relevant information such as the number of games, the timing, and the means to obtain the results (e.g., directly from the official network). The pre-reaction condition is the implementation of the smart contract after the triggering event. 该智能合约一经部署,其内容就会永久地保存在链上,并严格执行。球赛结束后,区块链网络中的节点均会验证响应条件,并将执行结果永久记录在链上。 Once deployed, the smart contract will be permanently kept on the chain and strictly enforced. 因为合约是严肃的事情,传统的合约往往需要专业的律师团队来撰写。古语有云:"术业有专攻。" 当前智能合约的开发工作主要由软件从业者来完成,其所编写的智能合约在完备性上可能有所欠缺,因此相比传统合约,更容易产生逻辑上的漏洞。另外,由于现有的部分支持智能合约的区块链平台提供了利用如Go语言、Java语言等高级语言编写智能合约的功能,而这类高级语言不乏一些具有 不确定性 的指令,可能会造成执行智能合约节点的某些内部状态发生分歧,从而影响整体系统的一致性。因此,智能合约的编写者需要极为谨慎,避免编写出有逻辑漏洞或是执行动作本身有不确定性的智能合约。不过,一些区块链平台引入了不少改进机制,对执行动作上的不确定性进行了消除,如超级账本项目的 子项目,即引入了先执行、背书、验证,再排序写入账本的机制;以太坊项目也通过限制用户只能通过其提供的确定性的语言()进行智能合约的编写,确保了其上运行的智能合约在执行动作上的确定性。 Because contracts are serious, traditional contracts often require professional teams of lawyers to write. Antiquated words: "The arts have an exclusive agenda." The development of current smart contracts is largely done by software practitioners, who may be less advanced in their preparation, making it easier to create a logical gap than traditional ones. Moreover, because existing sector-link platforms that support smart contracts provide the function of using advanced languages such as Go, Java, etc., to write smart contracts, and some of these high-level language instructions with uncertainties may lead to differences in the internal status of the implementation of smart contracts nodes, thus affecting the consistency of the overall system. 2016年著名的 事件,就是因为智能合约漏洞导致大约几千万美元的直接损失。是当时以太坊平台最大的众筹项目,上线不到一个月就筹集了超过1000万个以太币,当时价值一亿多美元。但是该智能合约的转账函数存在漏洞,攻击者利用该漏洞,盗取了360万个以太币。由于此事件影响过大,以太坊最后选择进行回滚硬分叉挽回损失。 The famous event of 2016 was a direct loss of about tens of millions of dollars as a result of an intelligent contract gap. It was the largest crowd-breeding project at the time, with more than 10 million Ethers raised online in less than a month, worth more than $100 million at the time. 对等计算机网络(Peer-to-Peer Networking,P2P网络),是一种消除了中心化的服务节点,将所有的网络参与者视为对等者(Peer),并在他们之间进行任务和工作负载分配。 结构打破了传统的 C/S模式 ,去除了中心服务器,是一种依靠用户群共同维护的网络结构。由于节点间的数据传输不再依赖中心服务节点, 网络具有极强的可靠性,任何单一或者少量节点故障都不会影响整个网络正常运转。同时, 网络的网络容量没有上限,因为随着节点数量的增加,整个网络的资源也在同步增加。由于每个节点可以从任意(有能力的)节点处得到服务,同时由于 网络中暗含的激励机制也会尽力向其他节点提供服务,因此,实际上 网络中节点数目越多, 网络提供的服务质量就越高。 The structure breaks the traditional 在区块链系统中,要求所有节点共同维护账本数据,即每笔交易都需要发送给网络中的所有节点。如果按照传统的C/S这种依赖中心服务节点的模式,中心节点需要大量交易信息转发给所有节点,这几乎是不可能完成的任务。网络的这些设计思想则同区块链的理念完美契合。在区块链中,所有交易及区块的传播并不要求发送者将消息发送给所有节点。节点只需要将消息发送给一定数量的相邻节点即可,其他节点收到消息后,会按照一定的规则转发给自己的相邻节点。最终通过一传十、十传百的方式,最终将消息发送给所有节点。 In block chain systems, all nodes are required to jointly maintain book data, i.e., each transaction needs to be sent to all nodes in the network. If, according to the traditional model of C/S, which relies on the central service node, the central node requires a large amount of transaction information to be transmitted to all nodes, this is almost impossible. These ideas of the network fit perfectly with the concept of the block chain. In the node chain, all transactions and the dissemination of blocks do not require the sender to send the message to all nodes. Node only needs to send the message to a certain number of adjacent nodes, and when the other node receives the message, it is transmitted to its node in accordance with certain rules. 以传统的银行系统为例。传统银行系统均采用C/S网络架构,即以银行服务器为中心节点,各个网点、ATM为客户端。当我们需要发起转账时,首先提供银行卡、密码等信息证明身份,然后生成一笔转账交易,发送到中心服务器后,由中心服务器校验余额是否充足等信息,然后记录到中心服务器,即可完成一笔转账交易。 Take the traditional banking system as an example. The traditional banking system uses the C/S network structure, which uses a bank server as its central node, and the ATM as its client. When we need to initiate a transfer, we first provide information such as a bank card, password, and then generate a transfer transaction, and when sent to the central server, the central server verifies the sufficiency of the balance, and then records it to the central server, so that a transfer transaction can be completed. 而在区块链网络中,并不存在一个中心节点来校验并记录交易信息,校验和记录工作有网络中的所有节点共同完成。当一个节点需要发起转账时,需要指明转账目的地址、转账金额等信息,同时还需要对该笔交易进行签名。由于不存在中心服务器,该交易会随机发送到网络中的邻近节点,邻近节点收到交易消息后,对交易进行签名,确认身份合法性后,再校验余额是否充足等信息。均校验完成后,它则会将该消息转发至自己的邻近节点。以此重复,直至网络中所有节点均收到该交易。最后,矿工获得记账权后,则会将该交易打包至区块,然后再广播至整个网络。区块广播过程同交易的广播过程,仍然使用一传十、十传百的方式完成。收到区块的节点完成区块内容验证后,即会将该区块永久地保存在本地,即交易生效。 In the block chain network, there is no central node to verify and record the transaction information. Once checked, it transmits the message to its immediate node. This is repeated until all nodees in the network receive the transaction. Finally, when the miner has the right to account, the transaction is packaged to a block and then broadcast to the entire network.
为什么区块链的出现使智能合约受到了广泛的关注
智能合约的原理
智能合约的安全性需要关注
注册有任何问题请添加 微信:MVIP619 拉你进入群
打开微信扫一扫
添加客服
进入交流群
发表评论