Skip to content

p2p: fix dial metrics not picking up the right error #31621

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
p2p: wrap internal error in new error type
Signed-off-by: Csaba Kiraly <[email protected]>
  • Loading branch information
cskiraly committed Apr 14, 2025
commit f2020470f26b09c3d022b88e75fe6a97519c3a5e
3 changes: 2 additions & 1 deletion p2p/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func markDialError(err error) {
return
}

var e *protoHandshakeError
switch {
case errors.Is(err, DiscTooManyPeers):
dialTooManyPeers.Mark(1)
Expand All @@ -81,7 +82,7 @@ func markDialError(err error) {
dialUnexpectedIdentity.Mark(1)
case errors.Is(err, errEncHandshakeError):
dialEncHandshakeError.Mark(1)
case errors.Is(err, errProtoHandshakeError):
case errors.As(err, &e):
dialProtoHandshakeError.Mark(1)
}
}
Expand Down
12 changes: 8 additions & 4 deletions p2p/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,15 @@ const (
)

var (
errServerStopped = errors.New("server stopped")
errEncHandshakeError = errors.New("rlpx enc error")
errProtoHandshakeError = errors.New("rlpx proto error")
errServerStopped = errors.New("server stopped")
errEncHandshakeError = errors.New("rlpx enc error")
)

type protoHandshakeError struct{ err error }

func (e *protoHandshakeError) Error() string { return fmt.Sprintf("rlpx proto error: %s", e.err) }
func (e *protoHandshakeError) Unwrap() error { return e.err }

// Server manages all peer connections.
type Server struct {
// Config fields may not be modified while the server is running.
Expand Down Expand Up @@ -908,7 +912,7 @@ func (srv *Server) setupConn(c *conn, dialDest *enode.Node) error {
if err != nil {
clog.Trace("Failed p2p handshake", "err", err)
//Wrapping both errors for later inspection
return fmt.Errorf("%w: %w", errProtoHandshakeError, err)
return &protoHandshakeError{err: err}
}
if id := c.node.ID(); !bytes.Equal(crypto.Keccak256(phs.ID), id[:]) {
clog.Trace("Wrong devp2p handshake identity", "phsid", hex.EncodeToString(phs.ID))
Expand Down
Loading