什么是 PoW 和 PoS？
Proof of Work (PoW) and Proof of Stake (PoS) have been inaccurately used as short hand to refer to consensus mechanisms of blockchains, but that does not capture the full picture. PoW is the method for agreeing on a block author and part of the fuller Nakamoto consensus that also encompasses a chain selection algorithm (longest chain rule in Bitcoin). Similarly, PoS is a set of rules for selecting the validator set and does not specify a chain selection rule or how a chain might reach finality. PoS algorithms have traditionally been paired with an algorithm for coming to Byzantine agreement between nodes. For example, Tendermint is a practical Byzantine fault tolerant algorithm that uses PoS as its validator set selection method.
Although simple and effective in coming to a decentralized consensus on the next block producer, proof of work with Nakamoto consensus consumes an incredible amount of energy, has no economic or provable finality, and has no effective strategy in resisting cartels.
概率性 vs 可证明的最终性
PoW 中本聪共识只能实现概率最终性并会达到最终共识。概率最终性意味着假设在某些网络和参与者之下，如果我们看到多过区块在某个区块上构建了，则有很大概率估计它是最终了。最终共识意味着在接下来的某个时间，所有节点都将就一组数据的真实性达成共识。最终共识可能需要很长时间，并且无法确定需要多长时间。但是例如 GRANDPA 或以太坊的 Casper FFG 之类的最终性工具旨在为区块提供更强的最终性 - 特别是更快的保证，在经过拜占庭协议的某些处理后，它们永远无法篡改。不可逆的共识概念称为可证明的最终性。
在 GRANDPA 论文中，它的表达方式如下：
如果在没有指定的时间后向所有参与者返回相同的值，oracle A 在协议中是最终一致。
什么是 GRANDPA / BABE?
在讨论 Polkadot 的共识协议时，我们使用两个首字母缩写词：GRANDPA 和 BABE。我们讨论这两个的原因是因为 Polkadot 使用的是混合共识。混合共识从区块生产机制中拆分了最终性工具。
这是在 Polkadot 中获得概率最终性（拥有产生新区块的能力）和可证明的最终性（在规范链上具有通用协议，没有任何逆转机会）的好处。它还避免了每种机制的相应缺点（在概率最终性中不知不觉地遵循了错误的分叉的机会，以及在可证明的最终性中存在"过时"的可能性- 无法产生新的区块）。通过结合这两种机制，Polkadot 可以快速生成区块，而较慢的最终机制可以在单独的流程中运行以确定区块，而不会使交易速度变慢或停顿的风险。
BABE (Blind Assignment for Blockchain Extension) 是在验证人节点与决定谁是产生新区块之间的产生区块机制。 BABE 与 Ouroboros Praos 相比，在链选择规则和时段调整方面存在一些关键差异。 BABE 根据抵押和使用 Polkadot 随机性周期分配区块生产插槽给验证人。
当没有任何验证人在随机抽奖中达到足够低的资格进行生产区块时，时隙便会没有区块。我们在后台通过运行辅助轮循样式验证人选择算法来避免这种情况。通过选择该算法生成区块的验证人始终生成区块，但是如果同一时隙也从 VRF 选择验证人生成主块，则这些次要区块将被忽略。因此时隙可以具有_ 主要 或 次要 _区块，并且不会跳过任何时隙。
有关更多 BABE 的详细信息，请参见正在研究的草案。
Difference of BABE secondary blocks between Kusama and Polkadot
Both Kusama and Polkadot uses the BABE block production mechanism outlined above. However, there is a slight difference in the secondary blocks that are produced between the two networks. Polkadot attaches the VRF output to secondary blocks (and therefore every block contributes to the Era randomness), while Kusama keeps the VRF output off the secondary blocks (meaning only the primary blocks contribute to Era randomness). The Polkadot method should give stronger randomness as more inputs are collected during every Era. Eventually, this change should make its way into Kusama too.
GRANDPA (GHOST-based Recursive ANcestor Deriving Prefix Agreement) is the finality gadget that is implemented for the Polkadot Relay Chain.
It works in a partially synchronous network model as long as 2/3 of nodes are honest and can cope with 1/5 Byzantine nodes in an asynchronous setting.
A notable distinction is that GRANDPA reaches agreements on chains rather than blocks, greatly speeding up the finalization process, even after long-term network partitioning or other networking failures.
In other words, as soon as more than 2/3 of validators attest to a chain containing a certain block, all blocks leading up to that one are finalized at once.
Please refer to heading 3 in the paper for a full description of the protocol.
The Rust implementation is part of Substrate Frame.
For even more detail, see the GRANDPA research page on the W3F Research pages.
Bringing BABE and GRANDPA together, the fork choice of Polkadot becomes clear. BABE must always build on the chain that has been finalized by GRANDPA. When there are forks after the finalized head, BABE provides probabilistic finality by building on the chain with the most primary blocks.
In the above image, the black blocks are finalized. Ones are primary, twos are secondary blocks. Even though the topmost chain is the longest chain on the latest finalized block, it does not qualify because it has fewer primaries at the time of evaluation than the one below it.
Nakamoto consensus consists of the longest chain rule using proof of work as its sybil resistance mechanism and leader election.
Nakamoto consensus only gives us probabilistic finality. Probabilistic finality states that a block in the past is only as safe as the number of confirmations it has, or the number of blocks that have been built on top of it. As more blocks are built on top of a specific block in a Proof of Work chain, more computational work has been expended behind this particular chain. However, it does not guarantee that the chain containing the block will always remain the agreed-upon chain, since an actor with unlimited resources could potentially build a competing chain and expend enough computational resources to create a chain that did not contain a specific block. In such a situation, the longest chain rule employed in Bitcoin and other proof of work chains would move to this new chain as the canonical one.
PBFT / Tendermint
Please see the relevant section in the Cosmos comparison article.
The two main differences between GRANDPA and Casper FFG (Friendly Finality Gadget) are:
- GRANDPA 依靠最终的区块来影响底层区块生产机制的分叉选择规则