Skip to content

Commit a76f7b7

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

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

portal-wire-protocol.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,36 @@ 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 calculation in [rust](https://github.com/ethereum/trin/blob/0ff1b8310f70327da61b3e8ac6e2163977cf2511/ethportal-api/src/types/portal_wire.rs#L34-L71):
72+
```rs
73+
/// The maximum size of a Discv5 talk request payload.
74+
///
75+
/// Discv5 talk request overhead:
76+
/// * masking IV length: 16
77+
/// * static header (protocol ID || version || flag || nonce || authdata-size) length: 23
78+
/// * authdata length: 32
79+
/// * HMAC length: 16
80+
/// * (max) talk request ID length: 8
81+
/// * (max assumed) talk request protocol length: 8
82+
/// * RLP byte array overhead: 6
83+
pub(crate) const MAX_DISCV5_TALK_REQ_PAYLOAD_SIZE: usize =
84+
MAX_DISCV5_PACKET_SIZE - 16 - 23 - 32 - 16 - 8 - 8 - 6;
85+
86+
// NOTE: The wire constant below relies on the following SSZ constants:
87+
// * `ssz::BYTES_PER_UNION_SELECTOR`: 1
88+
// * `ssz::BYTES_PER_LENGTH_OFFSET`: 4
89+
90+
/// The maximum size of a portal CONTENT payload. At the time of writing, this payload either
91+
/// corresponds to a `connection_id`, `enrs`, or `content` payload.
92+
///
93+
/// Portal wire overhead:
94+
/// * portal message SSZ union selector
95+
/// * CONTENT SSZ union selector
96+
/// * CONTENT SSZ length offset for List `enrs` or `content`
97+
pub const MAX_PORTAL_CONTENT_PAYLOAD_SIZE: usize = MAX_DISCV5_TALK_REQ_PAYLOAD_SIZE
98+
- (ssz::BYTES_PER_UNION_SELECTOR * 2)
99+
- ssz::BYTES_PER_LENGTH_OFFSET;
100+
```
71101

72102
## Request - Response Messages
73103

0 commit comments

Comments
 (0)