From 991e7cafbcd73ac52b06dc4918f5ecb29964e46a Mon Sep 17 00:00:00 2001 From: Etan Kissling Date: Sun, 24 Mar 2024 05:37:47 +0100 Subject: [PATCH] descore when opening connection fails, same as when reading fails (#6130) `eth2_network` forgets to descore peers when opening connection times out. It only descores when opening the connection succeeds and then there is a subsequent error. The caller cannot distinguish the cases, so ensure that the descore is also applied if the request fails during its initial portion. --- beacon_chain/networking/eth2_network.nim | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/beacon_chain/networking/eth2_network.nim b/beacon_chain/networking/eth2_network.nim index 0797336de..64728e571 100644 --- a/beacon_chain/networking/eth2_network.nim +++ b/beacon_chain/networking/eth2_network.nim @@ -971,8 +971,14 @@ proc makeEth2Request(peer: Peer, protocolId: string, requestBytes: seq[byte], deadline = sleepAsync timeout streamRes = awaitWithTimeout(peer.network.openStream(peer, protocolId), deadline): + peer.updateScore(PeerScorePoorRequest) return neterr StreamOpenTimeout - stream = ?streamRes + stream = streamRes.valueOr: + if streamRes.error().kind in ProtocolViolations: + peer.updateScore(PeerScoreInvalidRequest) + else: + peer.updateScore(PeerScorePoorRequest) + return err streamRes.error() try: # Send the request