eth2.0-specs/specs/networking/messaging.md

46 lines
1.8 KiB
Markdown
Raw Normal View History

2019-05-06 15:30:32 +00:00
# Eth 2.0 Networking Spec - Messaging
2019-03-12 20:46:58 +00:00
2019-05-06 15:30:32 +00:00
## Abstract
2019-03-12 20:46:58 +00:00
This specification describes how individual Ethereum 2.0 messages are represented on the wire.
2019-05-06 15:30:32 +00:00
The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL”, NOT", “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in [RFC 2119](https://tools.ietf.org/html/rfc2119).
2019-03-12 20:46:58 +00:00
2019-05-06 15:30:32 +00:00
## Motivation
2019-03-12 20:46:58 +00:00
2019-05-06 15:30:32 +00:00
This specification seeks to define a messaging protocol that is flexible enough to be changed easily as the Eth 2.0 specification evolves.
2019-03-12 20:46:58 +00:00
2019-03-19 22:32:38 +00:00
Note that while `libp2p` is the chosen networking stack for Ethereum 2.0, as of this writing some clients do not have workable `libp2p` implementations. To allow those clients to communicate, we define a message envelope that includes the body's compression, encoding, and body length. Once `libp2p` is available across all implementations, this message envelope will be removed because `libp2p` will negotiate the values defined in the envelope upfront.
2019-05-06 15:30:32 +00:00
## Specification
2019-03-12 20:46:58 +00:00
2019-05-06 15:30:32 +00:00
### Message structure
2019-03-12 20:46:58 +00:00
2019-05-06 15:30:32 +00:00
An Eth 2.0 message consists of an envelope that defines the message's compression, encoding, and length followed by the body itself.
2019-03-12 20:46:58 +00:00
Visually, a message looks like this:
```
+--------------------------+
2019-03-18 23:02:31 +00:00
| compression nibble |
+--------------------------+
| encoding nibble |
+--------------------------+
| body length (uint64) |
2019-03-12 20:46:58 +00:00
+--------------------------+
| |
| body |
| |
+--------------------------+
```
2019-05-06 15:30:32 +00:00
Clients MUST ignore messages with malformed bodies. The compression/encoding nibbles MUST be one of the following values:
2019-03-18 23:02:31 +00:00
2019-05-06 15:30:32 +00:00
### Compression nibble values
2019-03-12 20:46:58 +00:00
2019-03-18 23:02:31 +00:00
- `0x0`: no compression
2019-03-12 20:46:58 +00:00
2019-05-06 15:30:32 +00:00
### Encoding nibble values
2019-03-12 20:46:58 +00:00
2019-03-18 23:02:31 +00:00
- `0x1`: SSZ