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.
This commit is contained in:
Etan Kissling 2024-03-24 05:37:47 +01:00 committed by GitHub
parent 3765e8ac06
commit 991e7cafbc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 1 deletions

View File

@ -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