Skip to content

Commit 6d761c2

Browse files
committed
gh-148 devp2p: ENR subsection added
1 parent d3be53e commit 6d761c2

File tree

2 files changed

+47
-23
lines changed

2 files changed

+47
-23
lines changed

docs/wiki/EL/devp2p.md

+43-23
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ The reason behind this is that the information exchange requires a reliable conn
4646
so they can be able to both confirm the connection before sending the data and have a way to ensure that the data is delivered in the correct order and without errors (or at least to have a way to detect and correct them),
4747
while the discovery process does not require the reliable connection, since it is enough to let other knows that the node is available to communicate.
4848

49-
### Discovery
49+
### Discv protocol (Discovery)
5050
The process of how the nodes find each other in the network starts with [the hard-coded bootnodes listed in the specification](https://github.com/ethereum/go-ethereum/blob/master/params/bootnodes.go).
5151
The bootnodes are nodes that are known by all the other nodes in the networks (both Mainnet and testnets), and they are used to bootstrap the discovery peers process.
52-
Using the Kademlia DHT (Distributed Hash Table) algorithm, the nodes are able to find each other in the network by referring to a routing table where the bootnodes are listed.
52+
Using the Kademlia-like DHT (Distributed Hash Table) algorithm, the nodes are able to find each other in the network by referring to a routing table where the bootnodes are listed.
5353
The TLDR of the Kademlia is that it is a peer-to-peer protocol that enables nodes to find each other in the network by using a distributed hash table, as Leffew mentioned in his article (2019).
5454

5555
That is to say, the connection process starts with a PING-PONG game where the new node send a PING message to the bootnode, and the bootnode responds with a PONG hashed message.
@@ -58,6 +58,7 @@ so it can repeat the PING-PONG game with them and bond with them as well.
5858

5959
![img.png](../../images/el-architecture/peer-discovery.png)
6060

61+
#### Wire protocol
6162
The PING/PONG game is better known as the wire subprotocol, and it includes the next specifications:
6263

6364
**PING packet structure**
@@ -107,37 +108,56 @@ Where ENR is the Ethereum Node Record, a standard format for connectivity for no
107108

108109
---
109110
Currently, the execution clients are using the [Discv4 protocol](https://github.com/ethereum/devp2p/blob/master/discv4.md) for the discovery process, although it is planned to be migrated to [Discv5](https://github.com/ethereum/devp2p/blob/master/discv5/discv5.md) in the future.
110-
This Kademlia-like discovery protocol includes the routing table, which keeps information about other nodes in the neighbourhood consisting of *k-buckets* (where *k* is the number of nodes in the bucket, currently defined as 16).
111+
This Kademlia-like protocol includes the routing table, which keeps information about other nodes in the neighbourhood consisting of *k-buckets* (where *k* is the number of nodes in the bucket, currently defined as 16).
111112
Worth mentioning that all the table entries are sorted by *last seen/least-recently seen* at the head, and most-recently seen at the tail.
112113
If one of the entities has not been responded to in 12 hours, it is removed from the table, and the next encounter node is added to the tail of the list.
113114

115+
### ENR: Ethereum Node Records
116+
The ENR os a standard format for p2p connectivity, which was originally proposed in the [EIP-778](https://eips.ethereum.org/EIPS/eip-778).
117+
A node record contains the node's network endpoints, such as the IP address and port, as well as the node's public key and the sequence number of the record.
114118

119+
The record content structure is as follows:
115120

116-
### ENR: Ethereum Node Records
117-
* Standard format for connectivity for nodes
118-
* Node's identity
119-
* Object
120-
* signature (hash)
121-
* sequence number
122-
* arbitrary key-value pairs
123-
124-
## DevP2P specs
125-
* RLPx: encrypted and authenticated transport protocol (TCP based transport system for nodes communication)
126-
* Handshake messaging
127-
* Encryption
128-
* Authentication
129-
* RLP: Recursive Length Prefix encoding
130-
* Multiplexing: multiple subprotocols
131-
* Subprotocols
132-
* LES: Light Ethereum Subprotocol
133-
* Witness Subprotocol
134-
* Wire Subprotocol
135-
* SHH: Whisper Subprotocol
121+
| Key | Value |
122+
| --- |---------------------------------------------|
123+
| id | id scheme, e.g "v4" |
124+
| secp256k1 | compressed public key, 33 bytes |
125+
| ip | IPv4 address, 4 bytes |
126+
| tcp | TCP port, big endinan integer |
127+
| udp | UDP port, big endinan integer |
128+
| ip6 | IPv6 address, 16 bytes |
129+
| tcp6 | IPv6-specific TCP port, big endinan integer |
130+
| udp6 | IPv6-specific UDP port, big endinan integer |
131+
132+
All the fields are optional, except for the `id` field, which is required. If no `tcp6`/`udp6` port are provided, the `tcp`/`udp` ports are used for both IPv4 and IPv6.
133+
134+
The node record is composed of a `signature`, which iw the cryptographic signature of record contents, and a `seq` field, which is the sequence number of the record (a 64-bit unsigned integer).
135+
#### Encoding
136+
137+
The record is encoded as an RLP list of `[signature, seq, k, v,...]` with a maximum size of 300 bytes.
138+
Signed records are encoded as follows:
139+
```
140+
content = [seq, k, v, ...]
141+
signature = sign(content)
142+
record = [signature, seq, k, v, ...]
143+
```
144+
In addition to the RLP encoding, there is a textual representation of the record, which is a base64 encoding of the RLP encoding. It is prefixed with `enr:`.
145+
i.e. `enr:-IS4QHCYrYZbAKWCBRlAy5zzaDZXJBGkcnh4MHcBFZntXNFrdvJjX04jRzjzCBOonrkTfj499SZuOh8R33Ls8RRcy5wBgmlkgnY0gmlwhH8AAAGJc2VjcDI1NmsxoQPKY0yuDUmstAHYpMa2_oxVtw0RW_QAdpzBQA8yWM0xOIN1ZHCCdl8` which contains the loopback address `127.0.0.1` and the UDP port 30303. The node ID is `a448f24c6d18e575453db13171562b71999873db5b286df957af199ec94617f7`.
146+
147+
Despite of the fact that the ENR is a standard format for p2p connectivity, it is not mandatory to use it in the Ethereum network. The nodes can use any other format to exchange the information about their connectivity.
148+
There are two additional formats able to be understand by an Ethereum node: multiaddr and enode.
149+
150+
* The muldiaddr was the original one. For example, the multiaddr for a node with a loopback IP listening on TCP port 30303 and node ID `a448f24c6d18e575453db13171562b71999873db5b286df957af199ec94617f7` is `/ip4/127.0.0.1/tcp/30303/a448f24c6d18e575453db13171562b71999873db5b286df957af199ec94617f7`.
151+
* The enode is a more human-readable format. For example, the enode for the same node is `enode://a448f24c6d18e575453db13171562b71999873db5b286df957af199ec94617f7@127.0.0.1:30303?discport=30301`. It is a URL-like format describing the node ID encoded before de @ sign, the IP address, the TCP port and the UDP port specified as "discport".
152+
153+
### RLPx protocol (Transport)
136154

137155

138156
### Further Reading
139157
* [Geth devp2p docs](https://geth.ethereum.org/docs/tools/devp2p)
140158
* [Ethereum devp2p GitHub](https://github.com/ethereum/devp2p)
159+
* [Ethereum networking layer](https://ethereum.org/en/developers/docs/networking-layer/)
160+
* [Ethereum Addresses](https://ethereum.org/en/developers/docs/networking-layer/network-addresses/)
141161
* Andrew S. Tanenbaum, Nick Feamster, David J. Wetherall (2021). *Computer Networks*. 6th edition. Pearson. London.
142162
* Clause E. Shannon (1948). "A Mathematical Theory of Communication". *Bell System Technical Journal*. Vol. 27.
143163
* Jim Kurose and Keith Ross (2020). *Computer Networking: A Top-Down Approach*. 8th edition. Pearson.

wordlist.txt

+4
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ EL's
225225
Encodings
226226
Endian
227227
env
228+
enode
228229
ENR
229230
EOA
230231
EOAs
@@ -403,6 +404,7 @@ locktime
403404
Longrightarrow
404405
lookahead
405406
lookups
407+
loopback
406408
LSB
407409
LSM
408410
LSP
@@ -447,6 +449,7 @@ MSB
447449
MSIZE
448450
mstore
449451
MUL
452+
multiaddr
450453
multiproofs
451454
Murr
452455
MVE
@@ -458,6 +461,7 @@ namespaces
458461
Nand
459462
natively
460463
neighbours
464+
neighbourhood
461465
neq
462466
Nethermind
463467
neuder

0 commit comments

Comments
 (0)