Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SoV networking support #2951

Merged
merged 86 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 83 commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
17a8ae8
Add validator manager callbacks
StephenButtolph Apr 18, 2024
01aaf16
Add tests
StephenButtolph Apr 18, 2024
542ac26
Expose all validator sets to IP tracking
StephenButtolph Apr 18, 2024
4344233
merged
StephenButtolph Apr 18, 2024
ef31c90
Merge branch 'add-manager-validator-set-callbacks' into sov-networkin…
StephenButtolph Apr 18, 2024
16a245f
merged
StephenButtolph Apr 18, 2024
6d2c138
wip
StephenButtolph Apr 24, 2024
496426d
wip
StephenButtolph Apr 24, 2024
a849393
nit
StephenButtolph Apr 24, 2024
b9a10cd
wip
StephenButtolph Apr 26, 2024
0bb9d82
Remove subnet filter from Peer.TrackedSubnets()
StephenButtolph Apr 29, 2024
7c3b228
refactor test peer creation
StephenButtolph Apr 29, 2024
4a5cfaa
Add tracked subnets test
StephenButtolph Apr 29, 2024
824ea10
merged
StephenButtolph Apr 29, 2024
255a2c7
Update p2p messages
StephenButtolph Apr 29, 2024
9a3ee34
use network bool
StephenButtolph Apr 29, 2024
2ad3f0e
cleanup tests
StephenButtolph Apr 29, 2024
7512258
fix merge
StephenButtolph Apr 29, 2024
d6bdaa8
cleanup
StephenButtolph Apr 30, 2024
25b3c26
not obviously broken
StephenButtolph Apr 30, 2024
8a15984
nit
StephenButtolph May 13, 2024
4c9fc81
Standardize peer logging
StephenButtolph May 13, 2024
5a25bd1
nit
StephenButtolph May 13, 2024
66cae7a
nit
StephenButtolph May 13, 2024
ec069b7
nit
StephenButtolph May 13, 2024
f44b492
nit
StephenButtolph May 13, 2024
d6e99b5
nit
StephenButtolph May 13, 2024
4620366
merged
StephenButtolph May 13, 2024
40bb983
merged
StephenButtolph May 13, 2024
63a3e67
Merge branch 'track-peer-subnets' into sov-networking-support
StephenButtolph May 13, 2024
6f0b6f7
merged
StephenButtolph May 13, 2024
56aa31e
Merge branch 'standardize-peer-logs' into track-peer-subnets
StephenButtolph May 13, 2024
83cab97
Merge branch 'track-peer-subnets' into sov-networking-support
StephenButtolph May 13, 2024
85edf06
require both sides to think they are validators
StephenButtolph May 13, 2024
f668ea3
merged
StephenButtolph May 14, 2024
1a08def
nit
StephenButtolph May 14, 2024
f05b7b7
Merge branch 'track-peer-subnets' into sov-networking-support
StephenButtolph May 14, 2024
e740fe9
Delete empty subnets
StephenButtolph May 14, 2024
c6e4e4d
cleanup
StephenButtolph May 14, 2024
4fe32d7
add primary network to tracked subnets
StephenButtolph May 14, 2024
167f5d8
merged
StephenButtolph May 14, 2024
24cff08
nit
StephenButtolph May 14, 2024
4fe584b
nit
StephenButtolph May 14, 2024
f5d57e8
metrics
StephenButtolph May 14, 2024
9f2f84d
metrics
StephenButtolph May 14, 2024
5384f37
Add comments
StephenButtolph May 15, 2024
2b0d0d5
Fix tests + fix bugs
StephenButtolph May 16, 2024
5b47b11
lint
StephenButtolph May 16, 2024
80ca753
comment
StephenButtolph May 16, 2024
a783f03
nit
StephenButtolph May 16, 2024
9e1ad1a
nit
StephenButtolph May 16, 2024
20338ab
update readme
StephenButtolph May 16, 2024
ce6c08a
Merge branch 'master' into track-peer-subnets
StephenButtolph May 16, 2024
b8e2763
Merge branch 'track-peer-subnets' into sov-networking-support
StephenButtolph May 16, 2024
f7bb7e9
Merge branch 'master' into track-peer-subnets
StephenButtolph May 17, 2024
0cf01c8
merged
StephenButtolph May 17, 2024
0546523
1 less call
StephenButtolph May 17, 2024
a6e3bb9
Remove testing duplication
StephenButtolph May 20, 2024
c754543
nits
StephenButtolph May 20, 2024
2bf771f
nit
StephenButtolph May 20, 2024
934a64b
nit
StephenButtolph May 20, 2024
8d2a2cc
nit
StephenButtolph May 20, 2024
20e999d
Enable gossiping of newer IPs when connected to an older IP (#3035)
StephenButtolph May 21, 2024
a1ac017
Merge branch 'master' into sov-networking-support
StephenButtolph May 24, 2024
da4f9bd
merged
StephenButtolph May 24, 2024
564723e
merged
StephenButtolph Jun 3, 2024
f40337a
add comment
StephenButtolph Jun 3, 2024
7cb89fb
nit
StephenButtolph Jun 3, 2024
04bd5fd
Merge branch 'master' into sov-networking-support
StephenButtolph Jun 7, 2024
86e06cc
merged
StephenButtolph Jun 17, 2024
895376d
nit
StephenButtolph Jun 17, 2024
2b00ee7
nits
StephenButtolph Jun 17, 2024
cf3d60d
standardize name
StephenButtolph Jun 18, 2024
3ed23a8
nit
StephenButtolph Jun 18, 2024
a13ddf2
nit
StephenButtolph Jun 18, 2024
5df54eb
nit
StephenButtolph Jun 25, 2024
612e21c
nit
StephenButtolph Jun 25, 2024
053cb00
nit
StephenButtolph Jun 25, 2024
dbe32f6
nit
StephenButtolph Jun 25, 2024
8238d60
nit
StephenButtolph Jun 25, 2024
8e59560
nit
StephenButtolph Jun 25, 2024
be86c97
remove redundent graph
StephenButtolph Jun 25, 2024
009e445
nit
StephenButtolph Jun 25, 2024
3b13ca4
merged
StephenButtolph Jul 30, 2024
c572ea0
merged
StephenButtolph Aug 5, 2024
369a224
Merge branch 'master' into sov-networking-support
StephenButtolph Aug 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions message/mock_outbound_message_builder.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion message/outbound_msg_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ type OutboundMsgBuilder interface {
objectedACPs []uint32,
knownPeersFilter []byte,
knownPeersSalt []byte,
requestAllSubnetIPs bool,
) (OutboundMessage, error)

GetPeerList(
knownPeersFilter []byte,
knownPeersSalt []byte,
requestAllSubnetIPs bool,
) (OutboundMessage, error)

PeerList(
Expand Down Expand Up @@ -242,6 +244,7 @@ func (b *outMsgBuilder) Handshake(
objectedACPs []uint32,
knownPeersFilter []byte,
knownPeersSalt []byte,
requestAllSubnetIPs bool,
) (OutboundMessage, error) {
subnetIDBytes := make([][]byte, len(trackedSubnets))
encodeIDs(trackedSubnets, subnetIDBytes)
Expand Down Expand Up @@ -270,7 +273,8 @@ func (b *outMsgBuilder) Handshake(
Filter: knownPeersFilter,
Salt: knownPeersSalt,
},
IpBlsSig: ipBLSSig,
IpBlsSig: ipBLSSig,
AllSubnets: requestAllSubnetIPs,
},
},
},
Expand All @@ -282,6 +286,7 @@ func (b *outMsgBuilder) Handshake(
func (b *outMsgBuilder) GetPeerList(
knownPeersFilter []byte,
knownPeersSalt []byte,
requestAllSubnetIPs bool,
) (OutboundMessage, error) {
return b.builder.createOutbound(
&p2p.Message{
Expand All @@ -291,6 +296,7 @@ func (b *outMsgBuilder) GetPeerList(
Filter: knownPeersFilter,
Salt: knownPeersSalt,
},
AllSubnets: requestAllSubnetIPs,
},
},
},
Expand Down
144 changes: 83 additions & 61 deletions network/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- [Bloom Filter](#bloom-filter)
- [GetPeerList](#getpeerlist)
- [PeerList](#peerlist)
- [Avoiding Persistent Network Traffic](#avoiding-persistent-network-traffic)

## Overview

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

```mermaid
sequenceDiagram
actor Alice
actor Bob
actor Morty
actor Rick
loop
Alice->>Bob: Write outbound messages
Bob->>Alice: Read incoming messages
Morty->>Rick: Write outbound messages
Rick->>Morty: Read incoming messages
end
loop
Bob->>Alice: Write outbound messages
Alice->>Bob: Read incoming messages
Rick->>Morty: Write outbound messages
Morty->>Rick: Read incoming messages
end
```

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

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.

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).
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).

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

```mermaid
sequenceDiagram
actor Alice
actor Bob
Note over Alice,Bob: Connection Created
actor Morty
actor Rick
Note over Morty,Rick: Connection Created
par
Alice->>Bob: AvalancheGo v1.0.0
Morty->>Rick: AvalancheGo v1.0.0
and
Bob->>Alice: AvalancheGo v1.11.4
Rick->>Morty: AvalancheGo v1.11.4
end
Note right of Bob: v1.0.0 is incompatible with v1.11.4.
Note left of Alice: v1.11.4 could be compatible with v1.0.0!
Note right of Rick: v1.0.0 is incompatible with v1.11.4.
Note left of Morty: v1.11.4 could be compatible with v1.0.0!
par
Bob-->>Alice: Disconnect
Rick-->>Morty: Disconnect
and
Alice-XBob: Peerlist
Morty-XRick: Peerlist
end
Note over Alice,Bob: Handshake Failed
Note over Morty,Rick: Handshake Failed
```

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

```mermaid
sequenceDiagram
actor Alice
actor Bob
Note over Alice,Bob: Connection Created
actor Morty
actor Rick
Note over Morty,Rick: Connection Created
par
Alice->>Bob: AvalancheGo v1.11.0
Morty->>Rick: AvalancheGo v1.11.0
and
Bob->>Alice: AvalancheGo v1.11.4
Rick->>Morty: AvalancheGo v1.11.4
end
Note right of Bob: v1.11.0 is compatible with v1.11.4!
Note left of Alice: v1.11.4 could be compatible with v1.11.0!
Note right of Rick: v1.11.0 is compatible with v1.11.4!
Note left of Morty: v1.11.4 could be compatible with v1.11.0!
par
Bob->>Alice: Peerlist
Rick->>Morty: Peerlist
and
Alice->>Bob: Peerlist
Morty->>Rick: Peerlist
end
Note over Alice,Bob: Handshake Complete
Note over Morty,Rick: Handshake Complete
```

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

```mermaid
sequenceDiagram
actor Alice
actor Bob
Note left of Alice: Send Ping
Alice->>Bob: I think your uptime is 95%
Note right of Bob: Send Pong
Bob->>Alice: ACK
actor Morty
actor Rick
Note left of Morty: Send Ping
Morty->>Rick: I think your uptime is 95%
Note right of Rick: Send Pong
Rick->>Morty: ACK
```

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

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).

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:
- The node is in the initial bootstrapper set.
- The node is in the default bootstrapper set.
- The node in the current Primary Network validator set.
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:
- The peer is in the initial bootstrapper set.
- The peer is in the default bootstrapper set.
- The peer is a Primary Network validator.
- The peer is a validator of a tracked Subnet.
- The peer is a validator of a Subnet and the local node is a Primary Network validator.

#### IP Authentication

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

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.

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`.
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`.

#### Gossipable Peers

The peers that a node may include into a [`GetPeerList`](#getpeerlist) message are considered `gossipable`.


#### Trackable Peers

The peers that a node would attempt to connect to if included in a [`PeerList`](#peerlist) message are considered `trackable`.

#### Bloom Filter

Expand All @@ -171,32 +183,42 @@ A `GetPeerList` message contains the Bloom Filter of the currently known peers a
`PeerList` messages are expected to contain `IP:Port` pairs that satisfy all of the following constraints:
- The Bloom Filter sent when requesting the `PeerList` message does not contain the node claiming the `IP:Port` pair.
- The node claiming the `IP:Port` pair is currently connected.
- The `IP:Port` pair the node shared during the `Handshake` message is the node's most recently known `IP:Port` pair.
- The node claiming the `IP:Port` pair is either in the default bootstrapper set or is a current Primary Network validator.
- 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.

#### Example PeerList Gossip
#### Avoiding Persistent Network Traffic

The following diagram shows an example of `Alice` repeatedly learning about new peers from `Bob`.
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.

For example, say there are 3 nodes: `Rick`, `Morty`, and `Summer`.

First we consider the case that `Rick` and `Morty` consider `Summer` [`gossipable`](#gossipable-peers) and [`trackable`](#trackable-peers), respectively.
```mermaid
sequenceDiagram
actor Morty
actor Rick
Note left of Morty: Not currently tracking Summer
Morty->>Rick: GetPeerList
Note right of Rick: Summer isn't in the bloom filter
Rick->>Morty: PeerList - Contains Summer
Note left of Morty: Track Summer and add to bloom filter
Morty->>Rick: GetPeerList
Note right of Rick: Summer is in the bloom filter
Rick->>Morty: PeerList - Empty
```
This case is ideal, as `Rick` only notifies `Morty` about `Summer` once, and never uses bandwidth for their connection again.

Now we consider the case that `Rick` considers `Summer` [`gossipable`](#gossipable-peers), but `Morty` does not consider `Summer` [`trackable`](#trackable-peers).
```mermaid
sequenceDiagram
actor Alice
actor Bob
Note left of Alice: Initialize Bloom Filter
Note left of Alice: Bloom: [0, 0, 0]
Alice->>Bob: GetPeerList [0, 0, 0]
Note right of Bob: Any peers can be sent.
Bob->>Alice: PeerList - Peer-1
Note left of Alice: Bloom: [1, 0, 0]
Alice->>Bob: GetPeerList [1, 0, 0]
Note right of Bob: Either Peer-2 or Peer-3 can be sent.
Bob->>Alice: PeerList - Peer-3
Note left of Alice: Bloom: [1, 0, 1]
Alice->>Bob: GetPeerList [1, 0, 1]
Note right of Bob: Only Peer-2 can be sent.
Bob->>Alice: PeerList - Peer-2
Note left of Alice: Bloom: [1, 1, 1]
Alice->>Bob: GetPeerList [1, 1, 1]
Note right of Bob: There are no more peers left to send!
Bob->>Alice: PeerList - Empty
actor Morty
actor Rick
Note left of Morty: Not currently tracking Summer
Morty->>Rick: GetPeerList
Note right of Rick: Summer isn't in the bloom filter
Rick->>Morty: PeerList - Contains Summer
Note left of Morty: Ignore Summer
Morty->>Rick: GetPeerList
Note right of Rick: Summer isn't in the bloom filter
Rick->>Morty: PeerList - Contains Summer
```
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`.
Loading
Loading