Skip to content

Commit 1af9e89

Browse files
committed
Add payload threshold to use uTP, and show work
1 parent 3508500 commit 1af9e89

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

portal-wire-protocol.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,39 @@ The transmission of data that is too large to fit a single packet is done using
6868

6969
> The Portal wire protocol currently implements uTP over the `TALKREQ/TALKRESP` messages. Future plans are to move to the [sub-protocol data transmission](https://github.com/ethereum/devp2p/issues/229) in order to use a protocol native mechanism for establishing packet streams between clients.
7070
71+
Currently, the standard is to switch to uTP when the payload exceeds 1165 bytes. This may change over time, because it depends on a number of other variables. See an example derivation in rust:
72+
```rs
73+
/// The maximum size of a Discv5 packet.
74+
const MAX_DISCV5_PACKET_SIZE: usize = 1280;
75+
76+
/// The maximum size of a Discv5 talk request payload.
77+
///
78+
/// Discv5 talk request overhead:
79+
/// * masking IV length: 16
80+
/// * static header (protocol ID || version || flag || nonce || authdata-size) length: 23
81+
/// * authdata length: 32
82+
/// * HMAC length: 16
83+
/// * (max) talk request ID length: 8
84+
/// * (max assumed) talk request protocol length: 8
85+
/// * RLP byte array overhead: 6
86+
const MAX_DISCV5_TALK_REQ_PAYLOAD_SIZE: usize =
87+
MAX_DISCV5_PACKET_SIZE - 16 - 23 - 32 - 16 - 8 - 8 - 6;
88+
89+
// NOTE: The wire constant below relies on the following SSZ constants:
90+
// * `ssz::BYTES_PER_UNION_SELECTOR`: 1
91+
// * `ssz::BYTES_PER_LENGTH_OFFSET`: 4
92+
93+
/// The maximum size of a portal CONTENT payload. At the time of writing, this payload either
94+
/// corresponds to a `connection_id`, `enrs`, or `content` payload.
95+
///
96+
/// Portal wire overhead:
97+
/// * portal message SSZ union selector
98+
/// * CONTENT SSZ union selector
99+
/// * CONTENT SSZ length offset for List `enrs` or `content`
100+
const MAX_PORTAL_CONTENT_PAYLOAD_SIZE: usize = MAX_DISCV5_TALK_REQ_PAYLOAD_SIZE
101+
- (ssz::BYTES_PER_UNION_SELECTOR * 2)
102+
- ssz::BYTES_PER_LENGTH_OFFSET;
103+
```
71104

72105
## Request - Response Messages
73106

0 commit comments

Comments
 (0)