Skip to content

Commit

Permalink
chore: Improve errors readability
Browse files Browse the repository at this point in the history
  • Loading branch information
red-0ne committed Nov 9, 2023
1 parent 1646a55 commit b692e4c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
14 changes: 7 additions & 7 deletions pkg/relayer/proxy/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package proxy
import sdkerrors "cosmossdk.io/errors"

var (
codespace = "relayer/proxy"
ErrUnsupportedRPCType = sdkerrors.Register(codespace, 1, "unsupported rpc type")
ErrInvalidRelayRequestSignature = sdkerrors.Register(codespace, 2, "invalid relay request signature")
ErrInvalidSession = sdkerrors.Register(codespace, 3, "invalid session")
ErrInvalidSupplier = sdkerrors.Register(codespace, 4, "invalid supplier")
ErrUndefinedSigningKeyName = sdkerrors.Register(codespace, 5, "undefined signing key name")
ErrUndefinedProxiedServicesEndpoints = sdkerrors.Register(codespace, 6, "undefined proxied services endpoints")
codespace = "relayer_proxy"
ErrRelayerProxyUnsupportedRPCType = sdkerrors.Register(codespace, 1, "unsupported relayer proxy rpc type")
ErrRelayerProxyInvalidRelayRequestSignature = sdkerrors.Register(codespace, 2, "invalid relay request signature")
ErrRelayerProxyInvalidSession = sdkerrors.Register(codespace, 3, "invalid session in relayer request")
ErrRelayerProxyInvalidSupplier = sdkerrors.Register(codespace, 4, "invalid relayer proxy supplier")
ErrRelayerProxyUndefinedSigningKeyName = sdkerrors.Register(codespace, 5, "undefined relayer proxy signing key name")
ErrRelayerProxyUndefinedProxiedServicesEndpoints = sdkerrors.Register(codespace, 6, "undefined proxied services endpoints for relayer proxy")
)
5 changes: 3 additions & 2 deletions pkg/relayer/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,14 @@ func (rp *relayerProxy) ServedRelays() observable.Observable[*types.Relay] {
}

// validateConfig validates the relayer proxy's configuration options and returns an error if it is invalid.
// TODO_TEST: Add tests for validating these configurations.
func (rp *relayerProxy) validateConfig() error {
if rp.signingKeyName == "" {
return ErrUndefinedSigningKeyName
return ErrRelayerProxyUndefinedSigningKeyName
}

if rp.proxiedServicesEndpoints == nil {
return ErrUndefinedProxiedServicesEndpoints
return ErrRelayerProxyUndefinedProxiedServicesEndpoints
}

return nil
Expand Down
6 changes: 3 additions & 3 deletions pkg/relayer/proxy/relay_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (rp *relayerProxy) VerifyRelayRequest(
}

if !account.GetPubKey().VerifySignature(hash, relayRequest.Meta.Signature) {
return ErrInvalidRelayRequestSignature
return ErrRelayerProxyInvalidRelayRequestSignature
}

// Query for the current session to check if relayRequest sessionId matches the current session.
Expand All @@ -62,7 +62,7 @@ func (rp *relayerProxy) VerifyRelayRequest(
// matches the relayRequest sessionId.
// TODO_INVESTIGATE: Revisit the assumptions above at some point in the future, but good enough for now.
if session.SessionId != relayRequest.Meta.SessionHeader.SessionId {
return ErrInvalidSession
return ErrRelayerProxyInvalidSession
}

// Check if the relayRequest is allowed to be served by the relayer proxy.
Expand All @@ -72,5 +72,5 @@ func (rp *relayerProxy) VerifyRelayRequest(
}
}

return ErrInvalidSupplier
return ErrRelayerProxyInvalidSupplier
}
2 changes: 1 addition & 1 deletion pkg/relayer/proxy/server_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (rp *relayerProxy) BuildProvidedServices(ctx context.Context) error {
rp,
)
default:
return ErrUnsupportedRPCType
return ErrRelayerProxyUnsupportedRPCType
}

serviceEndpoints = append(serviceEndpoints, server)
Expand Down

0 comments on commit b692e4c

Please sign in to comment.