Avalanche共识

1. 引言

Avalanche共识白皮书 中介绍了Avalanche区块链平台采用的Avalanche共识。

直观举例为:
房间里有很多人,大家一起决策中午是吃披萨还是烧烤。某些人初始可能选择披萨,另一些人初始选择烧烤。最终,大家的目的是达成共识。

每个人询问房间内的a random subset of people其希望午餐吃什么。若有多于一半选择披萨,则其也选择披萨——即采用其所询问的大多数人的选择。

每个人都重复以上过程,每轮,会有越来越多的人具有相同的选择。This is because the more people that prefer an option, the more likely someone is to receive a majority reply and adopt that option as their preference. 足够轮数之后,可达成共识,每个人都选择同一选项。

2. Snowball

Snowball算法是Avalanche共识的基础。
Snowball算法关键参数有:

  • n n n:参与者数量
  • k k k(sample size):取值范围为1到 n n n
  • α \alpha α(法定人数):取值范围为1到 k k k
  • β \beta β(decision threshold): > = 1 >=1 >=1

Snowball算法伪代码示例为:

preference := pizza
consecutiveSuccesses := 0
while not decided:
  ask k random people their preference
  if >= α give the same response:
    preference := response with >= α
    if preference == old preference:
      consecutiveSuccesses++
    else:
      consecutiveSuccesses = 1
  else:
    consecutiveSuccesses = 0
  if consecutiveSuccesses > β:
    decide(preference)

具体示例可参看Snowball BFT demo示例
在这里插入图片描述
Snowball可用于对多个possible choices达成共识。

随着网络中节点数 n n n增加,Snowball具有可扩展性,其每次sample的size可仍然为 k k k

3. DAG(有向无环图)

在这里插入图片描述
DAG可实现partial ordering of decisions。
如上图,可只a在b之前,b在d之前,c在e之前。根据传递性可知a在e之前。但是,所谓partial ordering,是指:某些元素之间的顺序是不确定的,如——无法确定b和c之间的顺序关系。

DAG中相关的概念有:

  • ancestors:为DAG中可用线连上的节点,如上图中, d d d的ancestors为 a , b , c a,b,c a,b,c e e e的ancestors为 a , c a,c a,c
  • descendants:与ancestors相反,如上图中, a a a的descendants为 b , c , d , e b,c,d,e b,c,d,e b b b的descendants为 d d d

以太坊和比特币采用linear chain方式,每个block仅有一个parent和一个child。
但是,Avalanche采用DAG来存储数据,DAG中每个元素可能有多个parents。DAG中的parent-child relationship不代表application-level dependency。

为了避免在DAG中包含conflicting transactions,在Avalanche中定义了conflict set,Avalanche中的每笔交易都属于一个conflict set,conflict set中只能有1笔交易可包含在DAG中,每个节点需prefer one transaction in a conflict set。

详细的可参看 Working Example

4. Vertices

Ava Labs在对白皮书中共识进行实现时,做了一定的优化来降低延迟和提高吞吐量。最大的优化是引入了vertices。
vertex类似于linear blockchain中的区块,vertex中包含了the hashes of its parents 以及 a list of transactions。Vertices支持将多笔交易打包并被voted on in groups rather than one by one。

DAG由vertices组成。

若节点收到a vote for a vertex,则可认为是a vote for all the transactions in a vertex。votes具有可向上传递性。
A vertex is accepted when all the transactions which are in it are accepted. If a vertex contains a rejected transaction then it is rejected and all of its descendants are rejected. If a vertex is rejected, any valid transactions are re-issued into a new vertex which is not the child of a rejected vertex. New vertices are appended to preferred vertices.

5. Finality

Avalanche共识在一定的safety threshold具有probabilistically safe。即,the probability that a correct node accepts a transaction that another correct rejects can be made arbitrarily low by adjusting system parameters。
不同于以太坊和比特币需很长时间来等待区块固化,Avalanche中acceptance/rejection是final and irreversible的,仅需几秒钟。

6. 优化

节点query new transaction的同时,也会不断query知道没有不善良的vertices。善良的vertex中没有conflicts。

节点也无需等待 k k k个query responses才register the outcome of a poll,因为若交易未获得 α \alpha α majority,则无需在等待剩余的response了。

7. Validator

要称为Validator,节点需质押AVAX,质押量越多,越容易被其他节点query,对网络的影响力会越大。
节点query时并不是uniformly random的,而是weighted by stake amount。

Avalanche没有slash,Validator作恶或者不响应并不会惩罚,其质押金到期仍将全额返还,只是没有reward。As long as a sufficient portion of the bonded AVAX is held by correct nodes,则网络是安全的,且is live for virtuous transactions。

8. 两大创新

Avalanche中的2大创新分别是:

  • subsampling:具有low message overhead。不随20个节点还是2000个节点影响,the number of consensus messages a node sends during a query remains constant。
  • transitive voting:即a vote for a vertex is a vote for all its ancestors,这样有助于提升交易吞吐量。each note is actually many votes in one。

在这里插入图片描述
如上图,a vote for vertex D,也是a vote for A,B,C。

9. Loose Ends

用户可调用AvalancheGo全节点 API或者直接使用avalanchejs库 的方式来发起交易。

基于以下2种情况,vertex将被创建并添加到DAG:

  • when nodes batch incoming transactions together。
  • when accepted transactions from a rejected vertex get reissued。

10. Snowman

可将以上Avalanche consensus protocol改为linear chain,即要求each vertex has only one parent,这样可确定vertices的全局排序,适用于如智能合约——one needs to know if a transaction came before another transaction。

Avalanche consensus protocol for linear chains的实现,称为Snowman,即对应的为C-Chain 和P-Chain采用的为Snowman共识。

Avalanche中没有leader,任意节点都可提交交易,任意质押AVAX的节点都可对每一笔交易进行投票,可make the network more robust and decentralized。

参考资料

[1] Avalanche Consensus

猜你喜欢

转载自blog.csdn.net/mutourend/article/details/120349037