---
eip: 5793
label: EIP-5793
title: eth/68 - Add tx type to tx announcement
status: Final
type: Standards Track
category: Networking
created: 2022-10-18
requires: 2464, 2481, 4938
official: https://eips.ethereum.org/EIPS/eip-5793
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-5793.md
canonical: https://eips.huatuo.xyz/zh/eip-5793/
lang: zh
tldr: eth/68 网络协议版本：交易公告现在携带每笔交易的类型和大小，使节点可以在下载庞大的 blob 交易之前决定要获取什么。
tags: [networking, devp2p, mempool, eth68, blobs]
---

# EIP-5793: eth/68 - Add tx type to tx announcement

> Adds the transaction type and transaction size to tx announcement messages in the wire protocol

**TL;DR:** eth/68 网络协议版本：交易公告现在携带每笔交易的类型和大小，使节点可以在下载庞大的 blob 交易之前决定要获取什么。

## 它解决什么问题？

以太坊节点会相互传播待处理的交易。自 [eth/65](/eip-2464/) 起，节点可以只公告自己拥有的交易的哈希（`NewPooledTransactionHashes`），对等节点再请求自己缺少的完整交易体。

随着 [EIP-4844](/eip-4844/) 出现了 blob 交易，它们比普通交易大得多。如果节点只看到一个哈希，那么在下载完成之前，它无法区分一笔 100 字节的转账和一笔携带 blob 的交易。这使带宽难以控制，也为放大攻击留出了空间。

EIP-5793 在公告中增加了刚好足够的元数据，让节点可以提前做出这一决定。

## 它如何运作

它定义了协议版本 **eth/68**，并修改了一条消息 `NewPooledTransactionHashes (0x08)`：

```text
eth/67: [hash_0: B_32, hash_1: B_32, ...]
eth/68: [types: B, [size_0: P, size_1: P, ...], [hash_0: B_32, hash_1: B_32, ...]]
```

- `types` 是一个字节串，其中第 *i* 个字节是交易 *i* 的 [EIP-2718](/eip-2718/) 类型（例如 EIP-1559 为 `0x02`，blob 为 `0x03`）。
- `size_i` 是交易 *i* 编码后的大小。
- 哈希列表保持不变。

请注意，`types` 被打包成单个字节数组，而不是 RLP 列表。早期实现就是这样做的，为避免额外工作而保留了下来。

有了这些信息，节点可以做到例如：永远不接受推送的 blob 交易，只在需要时才获取；限制公告超大交易的对等节点；或者跳过自己不支持的类型。

## 示例代码

三笔交易的 eth/68 公告的 RLP 结构（伪代码）：

```python
import rlp

types  = bytes([0x02, 0x03, 0x00])           # EIP-1559, blob, legacy
sizes  = [180, 131_590, 110]                  # encoded sizes in bytes
hashes = [h0, h1, h2]                         # 32-byte transaction hashes

msg = rlp.encode([types, sizes, hashes])      # payload of message 0x08

# Receiver side
types, sizes, hashes = rlp.decode(msg)
want = [h for t, s, h in zip(types, sizes, hashes)
        if t != 0x03 or wants_blobs()]        # decide what to request
send_get_pooled_transactions(want)
```

## 需要注意

- **状态：Final。** 它只是网络层的变更：没有硬分叉，也没有共识变更。节点会协商协议版本，因此在推广期间 eth/67 和 eth/68 的对等节点可以共存。
- 接收方应检查最终获取的交易是否与公告的类型和大小一致；不一致说明对等节点行为异常。
- 后来的版本 [eth/69](/eip-7642/) 在 eth/68 的基础上，围绕历史过期和收据做了改动。


---

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