Skip to content

Commit 2d6fc10

Browse files
author
Zak Cole
authored
Merge pull request whiteblock#44 from atoulme/patch-2
Add more documentation to rpc messages
2 parents b88e732 + de111c2 commit 2d6fc10

File tree

2 files changed

+82
-40
lines changed

2 files changed

+82
-40
lines changed

gossip.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ The message must contain the following headers:
1616

1717
Example (showing the bson snappy data as json):
1818

19-
```python
19+
```java
2020
EWP 0.2 GOSSIP 24 0
2121
{
2222
"method_id": 3,

rpc-messages.md

+81-39
Original file line numberDiff line numberDiff line change
@@ -32,50 +32,65 @@ EWP 0.2 RPC snappy bson 0 12
3232

3333
## `0x00` HELLO
3434

35-
```python
35+
Nodes can send `HELLO` messages to each other to exchange information on their status.
36+
37+
38+
```java
3639
{
37-
'network_id': 'uint8'
38-
'chain_id': 'uint8'
39-
'latest_finalized_root': 'bytes32'
40-
'latest_finalized_epoch': 'uint64'
41-
'best_root': 'bytes32'
42-
'best_slot': 'uint64'
40+
'network_id': 'uint8' // the ID of the network (1 for mainnet, and some predefined number for a testnet)
41+
'chain_id': 'uint8' // the ID of the chain (1 for ETH)
42+
'latest_finalized_root': 'bytes32' // the hash of the latest finalized root
43+
'latest_finalized_epoch': 'uint64' // the number of the latest finalized epoch
44+
'best_root': 'bytes32' // the hash of the best root this node can offer
45+
'best_slot': 'uint64' // the number of the best slot this node can offer
4346
}
4447
```
4548

4649
## `0x01` GOODBYE
4750

48-
```python
51+
Nodes may signal to other nodes that they are going away by sending a `GOODBYE` message.
52+
The reason given is optional. Reason codes are up to each client and should not be trusted.
53+
54+
```java
4955
{
50-
'reason': 'uint64'
56+
'reason': 'uint64' // an optional reason code up to the client
5157
}
5258

5359
```
5460

5561
## `0x02` GET_STATUS
56-
```python
62+
63+
Nodes may exchange metadata information using a `GET_STATUS` message.
64+
65+
This information is useful to identify other nodes and clients and report that information to statistics services.
66+
67+
```java
5768
{
58-
'sha': 'bytes32'
59-
'user_agent': 'bytes'
60-
'timestamp': 'uint64'
69+
'sha': 'bytes32' // the commit hash of the node
70+
'user_agent': 'bytes' // the human readable name of the client, optionally with its version and other metadata
71+
'timestamp': 'uint64' // the current time of the node in milliseconds since epoch
6172
}
6273
```
6374

6475
## `0x0A` GET_BLOCK_ROOTS
6576

66-
```python
77+
Nodes may request block roots from other nodes using the `GET_BLOCK_ROOTS` message.
78+
79+
```java
6780
{
68-
'start_root': 'bytes32'
69-
'start_slot': 'uint64'
70-
'max': 'uint64'
71-
'skip': 'uint64'
72-
'direction': 'uint8' # 0x01 is forward, 0x00 is backwards
81+
'start_root': 'bytes32' // the root hash to start querying from
82+
'start_slot': 'uint64' // the slot number to start querying from
83+
'max': 'uint64' // the max number of elements to return
84+
'skip': 'uint64' // the number of elements apart to pick from
85+
'direction': 'uint8' // 0x01 is ascending, 0x00 is descending direction to query elements
7386
}
7487
```
7588

7689
## `0x0B` BLOCK_ROOTS
7790

78-
```python
91+
Nodes may provide block roots to other nodes using the `BLOCK_ROOTS` message, usually in response to a `GET_BLOCK_ROOTS` message.
92+
93+
```java
7994
[
8095
{
8196
'block_root': 'bytes32',
@@ -88,40 +103,45 @@ EWP 0.2 RPC snappy bson 0 12
88103

89104
## `0x0C` GET_BLOCK_HEADERS
90105

91-
```python
106+
Nodes may request block headers from other nodes using the `GET_BLOCK_HEADERS` message.
107+
108+
```java
92109
{
93-
'start_root': 'bytes32'
94-
'start_slot': 'uint64'
95-
'max': 'uint64'
96-
'skip': 'uint64'
97-
'direction': 'uint8' # 0x01 is forward, 0x00 is backwards
110+
'start_root': 'bytes32' // the root hash to start querying from
111+
'start_slot': 'uint64' // the slot number to start querying from
112+
'max': 'uint64' // the max number of elements to return
113+
'skip': 'uint64' // the number of elements apart to pick from
114+
'direction': 'uint8' // 0x01 is ascending, 0x00 is descending direction to query elements
98115
}
99116
```
100117

101118
## `0x0D` BLOCK_HEADERS
102119

103-
```python
120+
Nodes may provide block roots to other nodes using the `BLOCK_HEADERS` message, usually in response to a `GET_BLOCK_HEADERS` message.
121+
122+
```java
104123
'headers': '[]BeaconBlockHeader'
105124
```
106125

107-
108126
## `0x0E` GET_BLOCK_BODIES
109127

110-
```python
111-
[
112-
{
113-
'start_root': 'bytes32'
114-
'start_slot': 'uint64'
115-
'max': 'uint64'
116-
'skip': 'uint64'
117-
'direction': 'uint8' # 0x01 is forward, 0x00 is backwards
118-
}
119-
]
128+
Nodes may request block bodies from other nodes using the `GET_BLOCK_BODIES` message.
129+
130+
```java
131+
{
132+
'start_root': 'bytes32' // the root hash to start querying from
133+
'start_slot': 'uint64' // the slot number to start querying from
134+
'max': 'uint64' // the max number of elements to return
135+
'skip': 'uint64' // the number of elements apart to pick from
136+
'direction': 'uint8' // 0x01 is ascending, 0x00 is descending direction to query elements
137+
}
120138
```
121139

122140
## `0x0F` BLOCK_BODIES
123141

124-
```python
142+
Nodes may provide block roots to other nodes using the `BLOCK_BODIES` message, usually in response to a `GET_BLOCK_BODIES` message.
143+
144+
```java
125145
[
126146
{
127147
'randao_reveal': 'bytes96',
@@ -137,6 +157,28 @@ EWP 0.2 RPC snappy bson 0 12
137157
]
138158
```
139159

160+
# Lifecycle and message exchanges
161+
162+
## Initial hello
163+
164+
Upon discovering each other, nodes may exchange `HELLO` messages.
165+
166+
Nodes may send `HELLO` to other peers when they exchange messages for the first time or when their state changes to let them know new blocks are available.
167+
168+
Upon receiving a `HELLO` message, the node may reply with a `HELLO` message.
169+
170+
## Status messages
171+
172+
Any peer may provide information about their status and metadata to any other peer. Other peers may respond on a best effort basis, if at all.
173+
174+
## Block and header messages
175+
176+
Peers may request blocks and headers from other peers.
177+
178+
Other peers may respond on a best effort basis with header and block data.
179+
180+
There is no SLA for responding. Peers may request blocks repeatidly from the same peers.
181+
140182
#### The following definitions are aligned to v0.5.0 of the Beacon Chain Spec:
141183

142184
- [ProposerSlashing](https://github.com/ethereum/eth2.0-specs/blob/v0.5.0/specs/core/0_beacon-chain.md#proposerslashing)

0 commit comments

Comments
 (0)