eth/protocols/eth: fix handshake timeout metrics classification (#33539)

Previously, handshake timeouts were recorded as generic peer errors
instead of timeout errors. waitForHandshake passed a raw
p2p.DiscReadTimeout into markError, but markError classified errors only
via errors.Unwrap(err), which returns nil for non-wrapped errors. As a
result, the timeoutError meter was never incremented and all such
failures fell into the peerError bucket.

This change makes markError switch on the base error, using
errors.Unwrap(err) when available and falling back to the original error
otherwise. With this adjustment, p2p.DiscReadTimeout is correctly mapped
to timeoutError, while existing behaviour for the other wrapped sentinel
errors remains unchanged

---------

Co-authored-by: lightclient <lightclient@protonmail.com>
This commit is contained in:
ANtutov 2026-02-25 06:50:26 +02:00 committed by GitHub
parent 8450e40798
commit 2a45272408
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -191,16 +191,16 @@ func markError(p *Peer, err error) {
return return
} }
m := meters.get(p.Inbound()) m := meters.get(p.Inbound())
switch errors.Unwrap(err) { switch {
case errNetworkIDMismatch: case errors.Is(err, errNetworkIDMismatch):
m.networkIDMismatch.Mark(1) m.networkIDMismatch.Mark(1)
case errProtocolVersionMismatch: case errors.Is(err, errProtocolVersionMismatch):
m.protocolVersionMismatch.Mark(1) m.protocolVersionMismatch.Mark(1)
case errGenesisMismatch: case errors.Is(err, errGenesisMismatch):
m.genesisMismatch.Mark(1) m.genesisMismatch.Mark(1)
case errForkIDRejected: case errors.Is(err, errForkIDRejected):
m.forkidRejected.Mark(1) m.forkidRejected.Mark(1)
case p2p.DiscReadTimeout: case errors.Is(err, p2p.DiscReadTimeout):
m.timeoutError.Mark(1) m.timeoutError.Mark(1)
default: default:
m.peerError.Mark(1) m.peerError.Mark(1)