go-ethereum/p2p
Felix Lange 6a9158bb1b
p2p/discover: improved node revalidation (#29572)
Node discovery periodically revalidates the nodes in its table by sending PING, checking
if they are still alive. I recently noticed some issues with the implementation of this
process, which can cause strange results such as nodes dropping unexpectedly, certain
nodes not getting revalidated often enough, and bad results being returned to incoming
FINDNODE queries.

In this change, the revalidation process is improved with the following logic:

- We maintain two 'revalidation lists' containing the table nodes, named 'fast' and 'slow'.
- The process chooses random nodes from each list on a randomized interval, the interval being
  faster for the 'fast' list, and performs revalidation for the chosen node.
- Whenever a node is newly inserted into the table, it goes into the 'fast' list.
  Once validation passes, it transfers to the 'slow' list. If a request fails, or the
  node changes endpoint, it transfers back into 'fast'.
- livenessChecks is incremented by one for successful checks. Unlike the old implementation,
  we will not drop the node on the first failing check. We instead quickly decay the
  livenessChecks give it another chance.
- Order of nodes in bucket doesn't matter anymore.

I am also adding a debug API endpoint to dump the node table content.

Co-authored-by: Martin HS <martin@swende.se>
2024-05-23 14:26:09 +02:00
..
discover p2p/discover: improved node revalidation (#29572) 2024-05-23 14:26:09 +02:00
dnsdisc p2p/dnsdisc: using clear builtin func (#29418) 2024-04-04 12:19:48 +02:00
enode all: replace fmt.Errorf() with errors.New() if no param required (#29126) 2024-02-29 11:56:46 +02:00
enr all: fix mismatched names in comments (#29348) 2024-03-26 21:01:28 +01:00
msgrate log: remove lazy, remove unused interfaces, unexport methods (#28622) 2023-12-05 11:54:44 +01:00
nat p2p/nat: fix typos in comments (#29536) 2024-04-15 14:58:17 +02:00
netutil p2p: initialize maps with known size (#27229) 2023-05-10 10:52:26 +02:00
nodestate all: fix mismatched names in comments (#29348) 2024-03-26 21:01:28 +01:00
rlpx all: update to go version 1.22.1 (#28946) 2024-03-18 17:36:50 +01:00
simulations p2p/simulations/adapters: use maps.Clone (#29626) 2024-04-29 19:44:41 +02:00
tracker all: fix some typos (#25551) 2022-08-19 09:00:21 +03:00
dial_test.go p2p: initialize maps with known size (#27229) 2023-05-10 10:52:26 +02:00
dial.go p2p: fix race in dialScheduler (#29235) 2024-03-12 19:23:24 +01:00
message_test.go p2p: move rlpx into separate package (#21464) 2020-09-22 10:17:39 +02:00
message.go p2p: use atomic types (#27764) 2023-08-01 23:20:52 +02:00
metrics.go p2p: add inbound and outbound peers metric (#29424) 2024-04-02 21:18:28 +02:00
peer_error.go p2p: use errors.Is for error comparison (#24882) 2022-06-07 17:27:21 +02:00
peer_test.go p2p: move rlpx into separate package (#21464) 2020-09-22 10:17:39 +02:00
peer.go all: remove dependency on golang.org/exp (#29314) 2024-03-25 07:50:18 +01:00
protocol.go all: update golang/x/ext and fix slice sorting fallout (#27909) 2023-08-12 00:04:12 +02:00
server_nat_test.go cmd/bootnode, p2p: support for alternate mapped ports (#26359) 2023-07-14 14:58:27 +02:00
server_nat.go p2p: fix accidental termination of portMappingLoop (#28911) 2024-02-05 22:00:46 +01:00
server_test.go cmd/bootnode, p2p: support for alternate mapped ports (#26359) 2023-07-14 14:58:27 +02:00
server.go p2p/discover: improved node revalidation (#29572) 2024-05-23 14:26:09 +02:00
transport_test.go all: update license headers and AUTHORS from git history (#24947) 2022-05-24 20:39:40 +02:00
transport.go p2p, log, rpc: use errors.New to replace fmt.Errorf with no parameters (#29074) 2024-02-26 11:25:35 +02:00
util_test.go p2p: new dial scheduler (#20592) 2020-02-13 11:10:03 +01:00
util.go all: assign zero after resize in implementations of heap.Interface (#26296) 2022-12-05 13:49:54 +01:00