EIP-2481 · Final · Networking · 2020-01-17
EIP-2481: eth/66 request identifier
Introduced the eth/66 wire protocol, which wraps every request and response in the `eth` p2p protocol with a 64-bit request ID so nodes can match replies to requests directly.
What problem does it solve?
Ethereum nodes talk to each other over the devp2p eth sub-protocol. Many messages come in request/response pairs: GetBlockHeaders → BlockHeaders, GetReceipts → Receipts, and so on.
Before eth/66 those messages carried no identifier. A node that sent several GetBlockHeaders requests to the same peer could not be sure which response belonged to which request, because replies may arrive out of order. Clients had to compare each response against all pending requests by its contents, which is complex and ambiguous, especially for empty responses. The light-client protocol les already had request IDs; eth did not.
How it works
eth/66 changes the shape of every request/response message in the same way:
- Create a two-element list.
- The first element is
request_id, a 64-bit integer chosen by the requester. - The second element is the original message body, unchanged.
The responder copies the request_id from the request into its response. Affected messages are GetBlockHeaders/BlockHeaders, GetBlockBodies/BlockBodies, GetPooledTransactions/PooledTransactions, GetNodeData/NodeData and GetReceipts/Receipts.
Request IDs:
- do not have to be sequential (random is fine), which avoids collisions after reconnects;
- may repeat, so a simple client could even use one constant ID;
- are 64-bit to match
les.
Because devp2p can run several versions of a sub-protocol side by side, eth/66 rolled out without a hard fork; peers that had not upgraded kept speaking eth/65 (EIP-2464).
Sample code
A test vector from the spec, decoded by hand:
GetBlockHeaders (eth/66), RequestId 1111, origin block 9999, amount 5, skip 5, reverse false
rlp: 0xca 820457 c6 82270f 05 05 80
│ │ │ │ │ │ └ reverse = false (empty string)
│ │ │ │ │ └── skip = 5
│ │ │ │ └───── maxHeaders = 5
│ │ │ └──────────── block = 9999 (0x270f)
│ │ └─────────────── inner list: the eth/65 message body
│ └────────────────────── request_id = 1111 (0x0457)
└────────────────────────── outer list
Matching responses in a client becomes a map lookup:
const pending = new Map<bigint, (body: unknown) => void>();
function request(send: (msg: unknown[]) => void, body: unknown[]) {
const id = BigInt.asUintN(64, BigInt(Math.floor(Math.random() * 2 ** 53)));
send([id, body]); // [request_id, original message]
return new Promise((resolve) => pending.set(id, resolve));
}
function onResponse([id, body]: [bigint, unknown]) {
pending.get(id)?.(body);
pending.delete(id);
}
Things to know
- Status is Final. This is a networking change only; it does not affect consensus or smart contracts.
- Peers can still throttle or disconnect clients that flood them with parallel requests; request IDs make parallelism easier but do not grant more of it.
- Later
ethprotocol versions keep the request-ID envelope while changing other messages. For example, EIP-2976 defines how typed transactions travel over the same protocol.