Skip to content

Commit d3be53e

Browse files
committed
gh-148 devp2p: wire subprotocol and discv4 specs added
1 parent 4c1e2d1 commit d3be53e

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed

docs/wiki/EL/devp2p.md

+56-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,62 @@ 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-
## ENR: Ethereum Node Records
61+
The PING/PONG game is better known as the wire subprotocol, and it includes the next specifications:
62+
63+
**PING packet structure**
64+
```
65+
version = 4
66+
from = [sender-ip, sender-udp-port, sender-tcp-port]
67+
to = [recipient-ip, recipient-udp-port, 0]
68+
packet-data = [version, from, to, expiration, enr-seq ...]
69+
```
70+
71+
**PONG packet structure**
72+
```
73+
packet-data = [to, ping-hash, expiration, enr-seq, ...]
74+
```
75+
76+
The packet-data is wrapped in 1280 bytes UDP datagram alongside with the header:
77+
```
78+
packet-header = hash || signature || packet-type
79+
hash = keccak256(signature || packet-type || packet-data)
80+
signature = sign(packet-type || packet-data)
81+
packet = packet-header || packet-data
82+
```
83+
84+
**FindNode packet structure** (called FIND-NEIGHBOURS above)
85+
```
86+
packet-data = [target, expiration, ...]
87+
```
88+
Where the target is a 64-byte secp256k1 node's public key.
89+
90+
**Neighbours packet structure**
91+
```
92+
packet-data = [expiration, neighbours, ...]
93+
neighbours = [ip, udp-port, tcp-port, node-id, ...]
94+
```
95+
Where the neighbours are the list of 16 nodes that are able to connect with the new node.
96+
97+
**ENRRequest packet structure**
98+
```
99+
packet-data = [expiration]
100+
```
101+
102+
**ENRResponse packet structure**
103+
```
104+
packet-data = [request-hash, ENR]
105+
```
106+
Where ENR is the Ethereum Node Record, a standard format for connectivity for nodes. Which it is explained below.
107+
108+
---
109+
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+
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.
112+
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.
113+
114+
115+
116+
### ENR: Ethereum Node Records
62117
* Standard format for connectivity for nodes
63118
* Node's identity
64119
* Object

0 commit comments

Comments
 (0)