Skip to content

Commit eea2b00

Browse files
SoV networking support (#2951)
1 parent ac87871 commit eea2b00

File tree

13 files changed

+1757
-986
lines changed

13 files changed

+1757
-986
lines changed

message/mock_outbound_message_builder.go

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

message/outbound_msg_builder.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@ type OutboundMsgBuilder interface {
3535
objectedACPs []uint32,
3636
knownPeersFilter []byte,
3737
knownPeersSalt []byte,
38+
requestAllSubnetIPs bool,
3839
) (OutboundMessage, error)
3940

4041
GetPeerList(
4142
knownPeersFilter []byte,
4243
knownPeersSalt []byte,
44+
requestAllSubnetIPs bool,
4345
) (OutboundMessage, error)
4446

4547
PeerList(
@@ -242,6 +244,7 @@ func (b *outMsgBuilder) Handshake(
242244
objectedACPs []uint32,
243245
knownPeersFilter []byte,
244246
knownPeersSalt []byte,
247+
requestAllSubnetIPs bool,
245248
) (OutboundMessage, error) {
246249
subnetIDBytes := make([][]byte, len(trackedSubnets))
247250
encodeIDs(trackedSubnets, subnetIDBytes)
@@ -270,7 +273,8 @@ func (b *outMsgBuilder) Handshake(
270273
Filter: knownPeersFilter,
271274
Salt: knownPeersSalt,
272275
},
273-
IpBlsSig: ipBLSSig,
276+
IpBlsSig: ipBLSSig,
277+
AllSubnets: requestAllSubnetIPs,
274278
},
275279
},
276280
},
@@ -282,6 +286,7 @@ func (b *outMsgBuilder) Handshake(
282286
func (b *outMsgBuilder) GetPeerList(
283287
knownPeersFilter []byte,
284288
knownPeersSalt []byte,
289+
requestAllSubnetIPs bool,
285290
) (OutboundMessage, error) {
286291
return b.builder.createOutbound(
287292
&p2p.Message{
@@ -291,6 +296,7 @@ func (b *outMsgBuilder) GetPeerList(
291296
Filter: knownPeersFilter,
292297
Salt: knownPeersSalt,
293298
},
299+
AllSubnets: requestAllSubnetIPs,
294300
},
295301
},
296302
},

network/README.md

Lines changed: 83 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
- [Bloom Filter](#bloom-filter)
1717
- [GetPeerList](#getpeerlist)
1818
- [PeerList](#peerlist)
19+
- [Avoiding Persistent Network Traffic](#avoiding-persistent-network-traffic)
1920

2021
## Overview
2122

@@ -33,15 +34,15 @@ Peers communicate by enqueuing messages between one another. Each peer on either
3334

3435
```mermaid
3536
sequenceDiagram
36-
actor Alice
37-
actor Bob
37+
actor Morty
38+
actor Rick
3839
loop
39-
Alice->>Bob: Write outbound messages
40-
Bob->>Alice: Read incoming messages
40+
Morty->>Rick: Write outbound messages
41+
Rick->>Morty: Read incoming messages
4142
end
4243
loop
43-
Bob->>Alice: Write outbound messages
44-
Alice->>Bob: Read incoming messages
44+
Rick->>Morty: Write outbound messages
45+
Morty->>Rick: Read incoming messages
4546
end
4647
```
4748

@@ -55,50 +56,50 @@ A peer will then read the full message and attempt to parse it into either a net
5556

5657
Upon connection to a new peer, a handshake is performed between the node attempting to establish the outbound connection to the peer and the peer receiving the inbound connection.
5758

58-
When attempting to establish the connection, the first message that the node sends is a `Handshake` message describing the compatibility of the nodes. If the `Handshake` message is successfully received and the peer decides that it wants a connection with this node, it replies with a `PeerList` message that contains metadata about other peers that allows a node to connect to them. See [Peerlist Gossip](#peerlist-gossip).
59+
When attempting to establish the connection, the first message that the node sends is a `Handshake` message describing the configuration of the node. If the `Handshake` message is successfully received and the peer decides that it will allow a connection with this node, it replies with a `PeerList` message that contains metadata about other peers that allows a node to connect to them. See [PeerList Gossip](#peerlist-gossip).
5960

6061
As an example, nodes that are attempting to connect with an incompatible version of AvalancheGo or a significantly skewed local clock are rejected.
6162

6263
```mermaid
6364
sequenceDiagram
64-
actor Alice
65-
actor Bob
66-
Note over Alice,Bob: Connection Created
65+
actor Morty
66+
actor Rick
67+
Note over Morty,Rick: Connection Created
6768
par
68-
Alice->>Bob: AvalancheGo v1.0.0
69+
Morty->>Rick: AvalancheGo v1.0.0
6970
and
70-
Bob->>Alice: AvalancheGo v1.11.4
71+
Rick->>Morty: AvalancheGo v1.11.4
7172
end
72-
Note right of Bob: v1.0.0 is incompatible with v1.11.4.
73-
Note left of Alice: v1.11.4 could be compatible with v1.0.0!
73+
Note right of Rick: v1.0.0 is incompatible with v1.11.4.
74+
Note left of Morty: v1.11.4 could be compatible with v1.0.0!
7475
par
75-
Bob-->>Alice: Disconnect
76+
Rick-->>Morty: Disconnect
7677
and
77-
Alice-XBob: Peerlist
78+
Morty-XRick: Peerlist
7879
end
79-
Note over Alice,Bob: Handshake Failed
80+
Note over Morty,Rick: Handshake Failed
8081
```
8182

8283
Nodes that mutually desire the connection will both respond with `PeerList` messages and complete the handshake.
8384

8485
```mermaid
8586
sequenceDiagram
86-
actor Alice
87-
actor Bob
88-
Note over Alice,Bob: Connection Created
87+
actor Morty
88+
actor Rick
89+
Note over Morty,Rick: Connection Created
8990
par
90-
Alice->>Bob: AvalancheGo v1.11.0
91+
Morty->>Rick: AvalancheGo v1.11.0
9192
and
92-
Bob->>Alice: AvalancheGo v1.11.4
93+
Rick->>Morty: AvalancheGo v1.11.4
9394
end
94-
Note right of Bob: v1.11.0 is compatible with v1.11.4!
95-
Note left of Alice: v1.11.4 could be compatible with v1.11.0!
95+
Note right of Rick: v1.11.0 is compatible with v1.11.4!
96+
Note left of Morty: v1.11.4 could be compatible with v1.11.0!
9697
par
97-
Bob->>Alice: Peerlist
98+
Rick->>Morty: Peerlist
9899
and
99-
Alice->>Bob: Peerlist
100+
Morty->>Rick: Peerlist
100101
end
101-
Note over Alice,Bob: Handshake Complete
102+
Note over Morty,Rick: Handshake Complete
102103
```
103104

104105
### Ping-Pong Messages
@@ -107,12 +108,12 @@ Peers periodically send `Ping` messages containing perceived uptime information.
107108

108109
```mermaid
109110
sequenceDiagram
110-
actor Alice
111-
actor Bob
112-
Note left of Alice: Send Ping
113-
Alice->>Bob: I think your uptime is 95%
114-
Note right of Bob: Send Pong
115-
Bob->>Alice: ACK
111+
actor Morty
112+
actor Rick
113+
Note left of Morty: Send Ping
114+
Morty->>Rick: I think your uptime is 95%
115+
Note right of Rick: Send Pong
116+
Rick->>Morty: ACK
116117
```
117118

118119
## Peer Discovery
@@ -127,10 +128,12 @@ It is expected for Avalanche nodes to allow inbound connections. If a validator
127128

128129
Avalanche nodes that have identified the `IP:Port` pair of a node they want to connect to will initiate outbound connections to this `IP:Port` pair. If the connection is not able to complete the [Peer Handshake](#peer-handshake), the connection will be re-attempted with an [Exponential Backoff](https://en.wikipedia.org/wiki/Exponential_backoff).
129130

130-
A node should initiate outbound connections to an `IP:Port` pair that is believed to belong to a node that is not connected and meets at least one of the following conditions:
131-
- The node is in the initial bootstrapper set.
132-
- The node is in the default bootstrapper set.
133-
- The node in the current Primary Network validator set.
131+
A node should initiate outbound connections to an `IP:Port` pair that is believed to belong to another node that is not connected and meets at least one of the following conditions:
132+
- The peer is in the initial bootstrapper set.
133+
- The peer is in the default bootstrapper set.
134+
- The peer is a Primary Network validator.
135+
- The peer is a validator of a tracked Subnet.
136+
- The peer is a validator of a Subnet and the local node is a Primary Network validator.
134137

135138
#### IP Authentication
136139

@@ -148,7 +151,16 @@ Once connected to an initial set of peers, a node can use these connections to d
148151

149152
Peers are discovered by receiving [`PeerList`](#peerlist) messages during the [Peer Handshake](#peer-handshake). These messages quickly provide a node with knowledge of peers in the network. However, they offer no guarantee that the node will connect to and maintain connections with every peer in the network.
150153

151-
To provide an eventual guarantee that all peers learn of one another, nodes periodically send a [`GetPeerList`](#getpeerlist) message to a randomly selected validator with the node's current [Bloom Filter](#bloom-filter) and `Salt`.
154+
To provide an eventual guarantee that all peers learn of one another, nodes periodically send a [`GetPeerList`](#getpeerlist) message to a randomly selected Primary Network validator with the node's current [Bloom Filter](#bloom-filter) and `Salt`.
155+
156+
#### Gossipable Peers
157+
158+
The peers that a node may include into a [`GetPeerList`](#getpeerlist) message are considered `gossipable`.
159+
160+
161+
#### Trackable Peers
162+
163+
The peers that a node would attempt to connect to if included in a [`PeerList`](#peerlist) message are considered `trackable`.
152164

153165
#### Bloom Filter
154166

@@ -171,32 +183,42 @@ A `GetPeerList` message contains the Bloom Filter of the currently known peers a
171183
`PeerList` messages are expected to contain `IP:Port` pairs that satisfy all of the following constraints:
172184
- The Bloom Filter sent when requesting the `PeerList` message does not contain the node claiming the `IP:Port` pair.
173185
- The node claiming the `IP:Port` pair is currently connected.
174-
- The `IP:Port` pair the node shared during the `Handshake` message is the node's most recently known `IP:Port` pair.
175-
- The node claiming the `IP:Port` pair is either in the default bootstrapper set or is a current Primary Network validator.
186+
- The node claiming the `IP:Port` pair is either in the default bootstrapper set, is a current Primary Network validator, is a validator of a tracked Subnet, or is a validator of a Subnet and the peer is a Primary Network validator.
176187

177-
#### Example PeerList Gossip
188+
#### Avoiding Persistent Network Traffic
178189

179-
The following diagram shows an example of `Alice` repeatedly learning about new peers from `Bob`.
190+
To avoid persistent network traffic, it must eventually hold that the set of [`gossipable peers`](#gossipable-peers) is a subset of the [`trackable peers`](#trackable-peers) for all nodes in the network.
191+
192+
For example, say there are 3 nodes: `Rick`, `Morty`, and `Summer`.
193+
194+
First we consider the case that `Rick` and `Morty` consider `Summer` [`gossipable`](#gossipable-peers) and [`trackable`](#trackable-peers), respectively.
195+
```mermaid
196+
sequenceDiagram
197+
actor Morty
198+
actor Rick
199+
Note left of Morty: Not currently tracking Summer
200+
Morty->>Rick: GetPeerList
201+
Note right of Rick: Summer isn't in the bloom filter
202+
Rick->>Morty: PeerList - Contains Summer
203+
Note left of Morty: Track Summer and add to bloom filter
204+
Morty->>Rick: GetPeerList
205+
Note right of Rick: Summer is in the bloom filter
206+
Rick->>Morty: PeerList - Empty
207+
```
208+
This case is ideal, as `Rick` only notifies `Morty` about `Summer` once, and never uses bandwidth for their connection again.
180209

210+
Now we consider the case that `Rick` considers `Summer` [`gossipable`](#gossipable-peers), but `Morty` does not consider `Summer` [`trackable`](#trackable-peers).
181211
```mermaid
182212
sequenceDiagram
183-
actor Alice
184-
actor Bob
185-
Note left of Alice: Initialize Bloom Filter
186-
Note left of Alice: Bloom: [0, 0, 0]
187-
Alice->>Bob: GetPeerList [0, 0, 0]
188-
Note right of Bob: Any peers can be sent.
189-
Bob->>Alice: PeerList - Peer-1
190-
Note left of Alice: Bloom: [1, 0, 0]
191-
Alice->>Bob: GetPeerList [1, 0, 0]
192-
Note right of Bob: Either Peer-2 or Peer-3 can be sent.
193-
Bob->>Alice: PeerList - Peer-3
194-
Note left of Alice: Bloom: [1, 0, 1]
195-
Alice->>Bob: GetPeerList [1, 0, 1]
196-
Note right of Bob: Only Peer-2 can be sent.
197-
Bob->>Alice: PeerList - Peer-2
198-
Note left of Alice: Bloom: [1, 1, 1]
199-
Alice->>Bob: GetPeerList [1, 1, 1]
200-
Note right of Bob: There are no more peers left to send!
201-
Bob->>Alice: PeerList - Empty
213+
actor Morty
214+
actor Rick
215+
Note left of Morty: Not currently tracking Summer
216+
Morty->>Rick: GetPeerList
217+
Note right of Rick: Summer isn't in the bloom filter
218+
Rick->>Morty: PeerList - Contains Summer
219+
Note left of Morty: Ignore Summer
220+
Morty->>Rick: GetPeerList
221+
Note right of Rick: Summer isn't in the bloom filter
222+
Rick->>Morty: PeerList - Contains Summer
202223
```
224+
This case is suboptimal, because `Rick` told `Morty` about `Summer` multiple times. If this case were to happen consistently, `Rick` may waste a significant amount of bandwidth trying to teach `Morty` about `Summer`.

0 commit comments

Comments
 (0)