fix dial metrics not picking up the right error

The original error was not wrapped, so the caller function had
no chance of picking it up.

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
Csaba Kiraly 2025-04-12 14:46:39 +02:00
parent 80753ba147
commit f5e0eadad2
No known key found for this signature in database
GPG key ID: 0FE274EE8C95166E
2 changed files with 11 additions and 12 deletions

View file

@ -67,23 +67,21 @@ func markDialError(err error) {
if !metrics.Enabled() { if !metrics.Enabled() {
return return
} }
if err2 := errors.Unwrap(err); err2 != nil {
err = err2 switch {
} case errors.Is(err, DiscTooManyPeers):
switch err {
case DiscTooManyPeers:
dialTooManyPeers.Mark(1) dialTooManyPeers.Mark(1)
case DiscAlreadyConnected: case errors.Is(err, DiscAlreadyConnected):
dialAlreadyConnected.Mark(1) dialAlreadyConnected.Mark(1)
case DiscSelf: case errors.Is(err, DiscSelf):
dialSelf.Mark(1) dialSelf.Mark(1)
case DiscUselessPeer: case errors.Is(err, DiscUselessPeer):
dialUselessPeer.Mark(1) dialUselessPeer.Mark(1)
case DiscUnexpectedIdentity: case errors.Is(err, DiscUnexpectedIdentity):
dialUnexpectedIdentity.Mark(1) dialUnexpectedIdentity.Mark(1)
case errEncHandshakeError: case errors.Is(err, errEncHandshakeError):
dialEncHandshakeError.Mark(1) dialEncHandshakeError.Mark(1)
case errProtoHandshakeError: case errors.Is(err, errProtoHandshakeError):
dialProtoHandshakeError.Mark(1) dialProtoHandshakeError.Mark(1)
} }
} }

View file

@ -907,7 +907,8 @@ func (srv *Server) setupConn(c *conn, dialDest *enode.Node) error {
phs, err := c.doProtoHandshake(srv.ourHandshake) phs, err := c.doProtoHandshake(srv.ourHandshake)
if err != nil { if err != nil {
clog.Trace("Failed p2p handshake", "err", err) clog.Trace("Failed p2p handshake", "err", err)
return fmt.Errorf("%w: %v", errProtoHandshakeError, err) //Wrapping both errors for later inspection
return fmt.Errorf("%w: %w", errProtoHandshakeError, err)
} }
if id := c.node.ID(); !bytes.Equal(crypto.Keccak256(phs.ID), id[:]) { if id := c.node.ID(); !bytes.Equal(crypto.Keccak256(phs.ID), id[:]) {
clog.Trace("Wrong devp2p handshake identity", "phsid", hex.EncodeToString(phs.ID)) clog.Trace("Wrong devp2p handshake identity", "phsid", hex.EncodeToString(phs.ID))