简体   繁体   English

区块链共识如何验证交易?

[英]How blockchain consensus verify the transaction?

So many blockchain documentation tell that the blockchain uses the consensus to verify transactions.很多区块链文档都说区块链使用共识来验证交易。 But what I understand the consensus only generate the hash to create the new block.但据我所知,共识只生成 hash 来创建新块。 I don't know why the documentation says that the consensus verifies the transaction while the transaction has been created (made) before the consensus run for creating the new hash for new block.我不知道为什么文档说在为新块创建新的 hash 的共识运行之前创建(制作)交易时共识验证交易。 The consensus flow does not care about the input (group of transactions), it doesn't know the transactions group are valid or not.共识流不关心输入(交易组),它不知道交易组是否有效。 Why the blockchain documentation say that?为什么区块链文档这么说?

Before getting into details, I'd like to set some context.在进入细节之前,我想设置一些上下文。

First, what is blockchain - blockchain is a set of blocks where every next block depends on a pervious one.首先,什么是区块链——区块链是一组块,其中每个下一个块都依赖于前一个块。 And we can extend the chain as long as every new block is correct from system's point of view.只要从系统的角度来看每个新块都是正确的,我们就可以扩展链。

An example of a block chain (starting from a special, genesis, block): A->B->C->D一个区块链的例子(从一个特殊的创世区块开始):A->B->C->D

Every block, other than A, depends on previous one - usually this is based on hashes and some other rules;除了 A 之外的每个区块都依赖于前一个区块——通常这是基于哈希和一些其他规则; but a blockchain creator may pick any set of rules.但是区块链创建者可以选择任何一组规则。

Second, we need to agree on what is a consensus.其次,我们需要就什么是共识达成一致。 In a blockchain world, the consensus is a process to agree on the chain of block.在区块链世界中,共识是对区块链达成共识的过程。 It could be several chains, but the system will get to a consensus on which one is the right one.它可能是几条链,但系统将就哪一条是正确的达成共识。

Here is why this is important: let's say we have the chain from above with last block being D. In a distributed environment it is totally possible that more than one VALID block will be generated at the same time;这就是为什么这很重要:假设我们有上面的链,最后一个块是 D。在分布式环境中,完全有可能同时生成多个 VALID 块; and since the system is distributed, several new chains may emerge:由于系统是分布式的,因此可能会出现几个新的链:

  • A->B->C->D->E1 A->B->C->D->E1
  • A->B->C->D->E2 A->B->C->D->E2

The consensus in blockchains allows the.network as a whole to agree which of this chains is a valid one.区块链中的共识允许整个网络同意这条链中的哪一条是有效的。 Two important properties of a consensus:共识的两个重要属性:

  • it is eventual, it will take a while before every node gets to the same page;最终,每个节点都需要一段时间才能到达同一页面; which is the same as: if you will ask at the same time different nodes about which chain is the correct one - you may get different answers;这与:如果您同时询问不同的节点关于哪条链是正确的 - 您可能会得到不同的答案; but eventually, the.network will agree on the same one但最终,.network 将就同一个问题达成一致
  • there are many different ways how one can pick the right chain, eg in bitcoin, the system eventually agrees on a longest valid chain.有许多不同的方法可以如何选择正确的链,例如在比特币中,系统最终会就最长的有效链达成一致。

Now we can address the original question: "blockchain uses the consensus to verify transactions".现在我们可以解决最初的问题:“区块链使用共识来验证交易”。 Blockchain (distributed one) uses consensus to agree on a chain and it uses a set of rules to validate that every block is correct.区块链(分布式区块链)使用共识来就链条达成一致,并使用一组规则来验证每个块是否正确。 Since every node runs a software with the same set of rules, nodes will make same decision on every block correctness.由于每个节点都运行具有相同规则集的软件,因此节点将对每个块的正确性做出相同的决定。 But in distributed blockchain case, more than one chain may emerge...as described above.但是在分布式区块链的情况下,可能会出现不止一条链……如上所述。

To verify transactions blockchain is using set of rules applied locally to either accept or reject new blocks.为了验证交易,区块链正在使用本地应用的一组规则来接受或拒绝新块。

The documentation you mentioned does not sound right to me.您提到的文档对我来说听起来不正确。 Here is an example of a doc: https://www.investopedia.com/terms/c/consensus-mechanism-cryptocurrency.asp - I really like their first take away point: "A consensus mechanism refers to any number of methodologies used to achieve agreement, trust, and security across a decentralized computer.network."这是一个文档示例: https://www.investopedia.com/terms/c/consensus-mechanism-cryptocurrency.asp - 我真的很喜欢他们的第一个要点:“共识机制指的是使用的任何数量的方法在分散的计算机网络中实现协议、信任和安全。” - and, as I mentioned about - it is always worth asking - what is consensus about - in distributed blockchains, the consensus is about the chain itself. - 而且,正如我提到的 - 总是值得一问 - 什么是共识 - 在分布式区块链中,共识是关于链本身的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM