EIPs Explained

EIP-7642 · Final(最终) · Networking · 2024-02-29

EIP-7642: eth/69 - history expiry and simpler receipts

以太坊 eth 点对点协议的第 69 版:对等节点会公告自己仍提供的区块范围(丢弃合并前历史之后就需要这一点),握手去掉了已经过时的总难度,收据发送时不再附带 256 字节的 bloom 过滤器。

它解决什么问题?

eth 线路协议中有三处遗留问题,已经变得代价高昂或具有误导性:

  1. 历史过期(history expiry)。 历史过期工作组决定,客户端可以丢弃合并前的区块历史(自 2025 年 5 月 1 日起)。这样,通过 p2p 同步历史的节点就需要知道哪些对等节点仍然拥有它。否则,它只能通过询问并失败来发现。此前一个类似的提案 EIP-7542,在历史过期达成一致之前就被撤回了。
  2. 总难度(total difficulty)。 Status 握手携带了 td,而自合并以来它已毫无意义(合并后的区块难度为 0)。
  3. 收据 bloom。 没有客户端存储收据的 bloom 过滤器,因为可以根据日志重新计算。但协议仍然让提供数据的节点重新生成并发送它们。规范估计,每次全量同步因此多出约 530 GB(snappy 压缩后约 95 GiB)。

它如何运作

eth/69 修改了三条消息:

Status (0x00):去掉 td,加入所提供的范围。

eth/68: [version, networkid, td, blockhash, genesis, forkid]
eth/69: [version, networkid, genesis, forkid, earliestBlock, latestBlock, latestBlockHash]

Receipts (0x10):扁平列表,没有 bloom,对带类型的收据也不再做特殊包装。

eth/68: legacy = [status, cumulative-gas, bloom, logs]; typed = tx-type || rlp(legacy)
eth/69: receipt = [tx-type, post-state-or-status, cumulative-gas, logs]

接收方根据日志重新计算每个 bloom,以检查区块的收据根,这个代价很低。

BlockRangeUpdate (0x11),新增:[earliestBlock, latestBlock, latestBlockHash],在所提供的范围发生变化时发送,但最多大约每个 epoch(32 个区块)一次,以降低流量。

示例代码

根据 eth/69 的收据重建共识收据(含 bloom),TypeScript 伪代码:

import { encodeRlp, concat, toBeHex } from "ethers";

type Log = [address: string, topics: string[], data: string];
type Eth69Receipt = [txType: number, status: string, cumulativeGas: string, logs: Log[]];

function toConsensusEncoding([txType, status, gas, logs]: Eth69Receipt): string {
  const bloom = logsBloom(logs);                     // 256-byte bloom over addresses + topics
  const body = encodeRlp([status, gas, bloom, logs]);
  return txType === 0 ? body : concat([toBeHex(txType, 1), body]);  // typed: type || rlp(...)
}

logsBloom 是标准的以太坊日志 bloom(在 2048 位的过滤器中,每个地址和每个 topic 置位 3 个比特)。

需要注意

  • 状态为 Final。这只是网络层的变更:没有硬分叉,也没有共识变更。客户端与支持 eth/69 的对等节点协商使用它,与较旧的对等节点则可以继续使用 eth/68。
  • 它建立在 eth/68(EIP-5793)之上,后者为公告增加了交易类型。
  • earliestBlock 也为未来的滚动历史窗口(EIP-4444)做好了准备,并让爬虫可以统计有多少节点仍提供完整历史。
  • 下一个协议版本正在另行推进:EIP-7975 提出了带有部分区块收据列表的 eth/70(撰写时处于 Last Call)。

#networking #p2p #devp2p #history-expiry #receipts

详细信息

作者
Marius van der Wijden (@MariusVanDerWijden), Felix Lange <[email protected]>, Ahmad Bitar (@smartprogrammer93) <[email protected]>
状态
Final(最终)
类型
Standards Track / Networking
创建日期
2024-02-29
依赖的提案
被以下提案依赖

机器可读数据: Markdown · JSON