---
eip: 3436
label: EIP-3436
title: Expanded Clique Block Choice Rule
status: Stagnant
type: Standards Track
category: Core
created: 2021-03-25
requires: 225
official: https://eips.ethereum.org/EIPS/eip-3436
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-3436.md
canonical: https://eips.huatuo.xyz/zh/eip-3436/
lang: zh
tldr: 为 Clique 权威证明网络设计的确定性四步分叉选择平局决胜规则，旨在避免验证者分裂成权重相同的分叉时在 Goerli 上出现的链停摆。
tags: [clique, consensus, proof-of-authority, fork-choice, testnet]
---

# EIP-3436: Expanded Clique Block Choice Rule

> Add a four step block rule to Clique that should reduce block production deadlocks

**TL;DR:** 为 Clique 权威证明网络设计的确定性四步分叉选择平局决胜规则，旨在避免验证者分裂成权重相同的分叉时在 Goerli 上出现的链停摆。

## 它解决什么问题？

[Clique](/eip-225/) 是几个以太坊测试网和私有网络使用的权威证明共识引擎。签名者轮流出块；**轮到自己（in-turn）** 的区块难度为 2，非轮次（out-of-turn）的区块难度为 1，节点跟随总难度最高的链。

当两个互相竞争的链头总难度相同时，原始规范没有再说明什么，因此客户端退而采用"保留我先看到的那个"。在多客户端的 Goerli 测试网上，这导致了真实的**死锁**：诚实的验证者分处两个同样重的分叉，各自拒绝切换，即使超过一半的验证者在线，链也停摆了。其中一次事件直到一个离线的验证者重新上线才得以解决。

Geth 已经加入了"优先选择较短的链"的规则，但该 EIP 展示了一种连这条规则也无法打破平局的配置。

## 它如何运作

在两个链头之间做选择时，Clique 验证者依次应用以下规则：

1. **总难度最大。**
2. **区块号最小**（较短的链，隐含着更多 in-turn 区块）。
3. **in-turn 时隙最不近的验证者。** 计算下面的值，并优先选择其**最大**者：

   ```
   (header_number - validator_index) % validator_count
   ```

   其中 `validator_index` 是签名者在排序后的验证者列表中的位置。in-turn 区块算作最近的。其思路是拒绝即将轮到的那个验证者的分叉，让他能够产出 in-turn 区块。
4. **区块哈希最小**，按无符号 256 位整数解释，作为最后的兜底。

由于每一步都是确定性的，看到同样两个链头的验证者总会选出同一个。该规则可以平滑降级：如果只有部分客户端实现了它，或者只实现了较高优先级的规则，行为也不会比以前更差。

## 示例代码

把选择规则表示为比较键（Python）：

```python
def clique_choice_key(head, validators):
    """Higher key wins. validators = signer addresses sorted as in epoch checkpoints."""
    n = len(validators)
    idx = validators.index(head.signer)
    recency = (head.number - idx) % n      # rule 3: larger = less recent in-turn
    return (
        head.total_difficulty,             # rule 1: more is better
        -head.number,                      # rule 2: lower number is better
        recency,                           # rule 3
        -int.from_bytes(head.hash, "big"), # rule 4: lower hash is better
    )

def choose(a, b, validators):
    return a if clique_choice_key(a, validators) >= clique_choice_key(b, validators) else b
```

## 需要注意

- **状态：Stagnant（停滞）。** 它没有被最终确定为对 Clique 规范的修改。
- 确定性的最低哈希平局决胜规则，使恶意验证者更容易产出一个替换区块；作者判断这一影响较小。
- Clique 只对权威证明网络有意义。以太坊主网已经通过 [EIP-3675](/eip-3675/) 转向权益证明，而催生该 EIP 的 Goerli 网络此后也已被弃用。


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-3436
