Kim De Mey d2ba753792
Add rlpx metrics and avoid immediate peer reconnections (#585)
* Add metrics related to devp2p peer connections

* Avoid reconnecting to peers that just failed connection

- Add SeenTable to avoid reconnecting to peers immediately after
a failed connect. Depending on the failure, the amount of time is
different. This is similar to what is done in nimbus-eth2.
- Attempt to rework rlpxConnect at the same time, in order to
make sure that errors are properly handled. The current structure
is far from ideal, but it is hopefully a small step in the right
direction. To many oddities in there right now to really rework
rlpxConnect properply.

* Fix rlpx thunk fuzzer
2023-03-16 16:45:12 +01:00

35 lines
1.0 KiB
Nim

import
testutils/fuzzing, chronos,
../../../eth/p2p, ../../../eth/p2p/rlpx, ../../../eth/p2p/private/p2p_types,
../../p2p/eth_protocol,
../../p2p/p2p_test_helper
var
node1: EthereumNode
node2: EthereumNode
peer: Peer
let rng = newRng()
# This is not a good example of a fuzzing test and it would be much better
# to mock more to get rid of anything sockets, async, etc.
# However, it can and has provided reasonably quick results anyhow.
init:
node1 = setupTestNode(rng, eth)
node2 = setupTestNode(rng, eth)
node2.startListening()
let res = waitFor node1.rlpxConnect(newNode(node2.toENode()))
if res.isErr():
quit 1
else:
peer = res.get()
test:
aflLoop: # This appears to have unstable results with afl-clang-fast, probably
# because of undeterministic behaviour due to usage of network/async.
try:
var (msgId, msgData) = recvMsgMock(payload)
waitFor peer.invokeThunk(msgId.int, msgData)
except CatchableError as e:
debug "Test caused CatchableError", exception=e.name, trace=e.repr, msg=e.msg