Skip to content

Commit cbc2430

Browse files
carverfjl
andauthored
caps/wit.md: Ethereum Witness Protocol v0 (#167)
This adds the initial specification of the wit/0 protocol. Also fixes a broken lin in caps/pip.md. Co-authored-by: Felix Lange <[email protected]>
1 parent d3f6d67 commit cbc2430

File tree

3 files changed

+121
-1
lines changed

3 files changed

+121
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Ethereum.
1111
- [Ethereum Snapshot Protocol] (version 1)
1212
- [Light Ethereum Subprotocol] (version 3)
1313
- [Parity Light Protocol] (version 1)
14+
- [Ethereum Witness Protocol] (version 0)
1415

1516
The issue tracker here is for discussions of protocol changes. It's OK to open an issue if
1617
you just have a question. You can also get in touch through our [Gitter channel].
@@ -77,6 +78,7 @@ WireShark dissectors are available here: <https://github.com/ConsenSys/ethereum-
7778
[Ethereum Snapshot Protocol]: ./caps/snap.md
7879
[Gitter channel]: https://gitter.im/ethereum/devp2p
7980
[Light Ethereum Subprotocol]: ./caps/les.md
81+
[Ethereum Witness Protocol]: ./caps/wit.md
8082
[Ethereum Node Records]: ./enr.md
8183
[Node Discovery Protocol v4]: ./discv4.md
8284
[Node Discovery Protocol v5]: ./discv5/discv5.md

caps/pip.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Unlike LES, a PIP CHT is generated once every 2048 blocks. One 32-byte trie root
1212
for every range of 2048 blocks.
1313

1414
The current version is **pip/1**. This specification was derived from the official
15-
specification at <https://wiki.parity.io>. However, the official specification has since
15+
specification at `https://wiki.parity.io`. However, the official specification has since
1616
been deleted.
1717

1818
## Notation

caps/wit.md

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# Ethereum Witness Protocol (wit)
2+
3+
The `wit` protocol runs on top of [RLPx], facilitating the exchange of Ethereum state
4+
witnesses between peers. The protocol is an optional extension for peers supporting (or
5+
caring about) the state witnesses for Ethereum blocks.
6+
7+
The current version is `wit/0`.
8+
9+
### Overview
10+
11+
The `wit` protocol is designed to assist clients in syncing up to the tip of the chain.
12+
Eventually, it also aspires to assist in stateless client operation. The `wit` protocol
13+
does not take part in chain maintenance (block and transaction propagation); and it is
14+
**meant to be run side-by-side with the `eth` protocol**, not standalone (e.g. chain
15+
progression is announced via `eth`). (like the `snap` protocol)
16+
17+
Despite the name, version 0 will not provide actual witnesses. It will provide meta-data
18+
about the witness, which can be used to download the witness over the `eth` protocol.
19+
20+
For now, the known use case is to assist [Beam Syncing] peers. By requesting witness
21+
metadata, these peers will keep up with the tip of the network and become fully-synced
22+
nodes faster.
23+
24+
Using the `wit` protocol, peers ask each other for the list of trie node hashes read
25+
during the execution of a particular block. This includes the following data:
26+
27+
- Storage nodes
28+
- Bytecodes
29+
- Account nodes
30+
- Read during EVM execution
31+
- Read during transaction validation
32+
- Read during block reward calculation
33+
- Nodes read when generating the final state root (i.e. sometimes deleting data requires a
34+
trie refactor that reads nearby trie nodes)
35+
36+
The trie node hashes which are generated at the end of the block from existing data are
37+
*not* included. For example, the final state root hash is not included.
38+
39+
## Relation to `eth`
40+
41+
The `wit` protocol follows the same pattern as `snap`. It is a *dependent satellite* of
42+
`eth` (i.e. to run `wit`, you need to run `eth` too), not a fully standalone protocol.
43+
This is a deliberate design decision:
44+
45+
- `wit` is meant to be a bootstrap aid for newly joining full nodes. By enforcing all
46+
`wit` peers to also speak `eth`, we can avoid non-full nodes from lingering attached to
47+
`wit` indefinitely.
48+
- `eth` already contains well established chain and fork negotiation mechanisms, as well
49+
as remote peer staleness detection during sync. By running both protocols side-by-side,
50+
`wit` can benefit of all these mechanisms without having to duplicate them.
51+
52+
This *satellite* status may be changed later, but it's better to launch with a more
53+
restricted protocol first and then expand if need be vs. trying to withdraw depended-upon
54+
features.
55+
56+
In order to follow the `wit` protocol, clients must generate witness metadata when
57+
executing blocks. For now, its primary purpose is also one specific sync method that might
58+
not be suitable for all clients. Keeping `wit` as a separate protocol permits every client
59+
to decide to pursue it or not, without hindering their capacity to participate in the
60+
`eth` protocol.
61+
62+
## Accelerating Beam Sync
63+
64+
At its most naive, Beam Sync needs to download any missing state one trie node at a time.
65+
According to a recent test, after Beam Syncing for 22 hours, the median block still
66+
required more than 300 new trie nodes. At an optimistic 100ms round-trip time, that means
67+
30 seconds per block of data download. This is where witness metadata can help
68+
tremendously.
69+
70+
If a client can request the trie node hashes used by a block up front, those 300 trie
71+
nodes can likely be accessed in a fraction of a second. That's easily enough to keep
72+
synced with mainnet.
73+
74+
Unfortunately, the list of trie node hashes cannot be verified before the block is
75+
imported. This would be a huge problem for a stateless client, which would be permanently
76+
at risk to a DoS attack where peers feed it a long list of incorrect hashes. But Beam
77+
Syncing clients are only vulnerable until they've finished downloading the full network
78+
state, so the payoff for such an attack is smaller.
79+
80+
## Protocol Messages
81+
82+
### RESERVED (0x00)
83+
84+
This command is undefined, held in place for a possible future Status message.
85+
86+
### GetBlockWitnessHashes (0x01)
87+
88+
`[reqID: P, blockHash: B_32]`
89+
90+
Requests a list of trie node hashes used by a given block.
91+
92+
- `reqID`: Request ID to match up responses with
93+
- `blockHash`: Hash of the header to request the witness hashes for
94+
95+
Notes:
96+
97+
- Nodes **must** always respond to the query.
98+
- If the node does **not** have the trie hashes requested block, it **must** return an
99+
empty reply.
100+
101+
### BlockWitnessHashes (0x02)
102+
103+
`[reqID: P, witnessHashes: [trieNodeHash: B_32, ...]]`
104+
105+
Returns a list of the trie node hashes that were read during execution and validation of
106+
the given block.
107+
108+
- `reqID`: ID of the request this is a response for
109+
- `witnessHashes`: List of trie node hashes
110+
111+
## Change Log
112+
113+
### wit/0 (October 2020)
114+
115+
Version 0 was the introduction of the witness protocol.
116+
117+
[RLPx]: ../rlpx.md
118+
[Beam Syncing]: https://github.com/ethereum/stateless-ethereum-specs/blob/master/beam-sync-phase0.md

0 commit comments

Comments
 (0)