Commit cc96111
authored
rotation of outbound peers (#3037)
To make the p2p network uniformly random, nodes need to be able to
change their peers periodically (otherwise network would be centralized
at bootstrap peers). This PR implements an algorithm based on stable
hashing, which makes nodes assign random priority to every node ID, and
connect to peers with higher priority.
This pr also separates inbound and outbound connection pools to simplify
logic. In particular it is possible that there will be 2 concurrent
connections between 2 peers (inbound + outbound). Avoiding duplicate
connections is best effort - nodes try not to dial peers that they are
connected to, but in case 2 peers dial each other at the same time they
let those 2 connections be.
Basic requirements:
* peermanager maintains a pex table: addresses of peers of our peers.
This bounds the network view size (even though it is an unauthenticated
network) that our node needs to maintain and provides enough exposure to
select new peers. Peers are periodically reporting their connections,
therefore peermanager keeps only fresh addresses
* on startup a spike of dials is expected - node will try to connect to
peers that it was connected to before restart
* during stable operation node will dial peers at a low rate like 1/s or
0.1/s, and the node should be selected from a fresh set of addresses -
i.e. we cannot snapshot a list of currently available addresses and try
to dial them all (it will take hours)
* despite low dial rate, node should attempt to round robin over the
ever changing peer candidates set - i.e. it should not get stuck dialing
the same bad address over and over
* in the stable-hash-based approach, each peer ID obtains a priority for
dialing - it should be taken into account
* implementation should support replacing low priority peers with higher
priority peers (to support convergence to a random graph). The churn of
the connections should be low though, so that connection efficiency is
not affected. My initial guesstimate would be that we should allow
replacing a connection every ~1min.
* We need to support a pex table with ~100 * 100 = 10k addresses total
(100 connections per peer is a safe estimate with the current
implementation). Whether we can affort just rank all the addresses on
every dial attempt is a borderline IMO.
* the addresses inserted to pex table should be made available for
dialing ASAP, without any active polling, if possible.1 parent 79b7899 commit cc96111
29 files changed
Lines changed: 1547 additions & 1441 deletions
File tree
- sei-tendermint
- config
- internal
- p2p
- pex
- rpc/core
- statesync
- libs/utils
- node
- types
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
652 | 652 | | |
653 | 653 | | |
654 | 654 | | |
655 | | - | |
| 655 | + | |
656 | 656 | | |
657 | 657 | | |
658 | 658 | | |
| |||
703 | 703 | | |
704 | 704 | | |
705 | 705 | | |
706 | | - | |
707 | | - | |
708 | | - | |
709 | | - | |
710 | | - | |
711 | | - | |
712 | | - | |
713 | | - | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
714 | 710 | | |
715 | 711 | | |
716 | 712 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | 38 | | |
54 | 39 | | |
55 | 40 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | 8 | | |
10 | 9 | | |
11 | 10 | | |
| |||
278 | 277 | | |
279 | 278 | | |
280 | 279 | | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | 280 | | |
297 | 281 | | |
298 | 282 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
| 82 | + | |
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
87 | | - | |
| 87 | + | |
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
101 | | - | |
| 101 | + | |
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
| |||
0 commit comments