Skip to content
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

[Code Health] fix: session module gRPC status return errors #960

Merged
merged 5 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions x/proof/keeper/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package keeper

import (
"context"
"fmt"

cosmostypes "github.com/cosmos/cosmos-sdk/types"
"google.golang.org/grpc/status"

"github.com/pokt-network/poktroll/x/proof/types"
sessiontypes "github.com/pokt-network/poktroll/x/session/types"
Expand All @@ -30,6 +32,8 @@ func (k Keeper) queryAndValidateSessionHeader(
// session header is to be validated.
sessionRes, err := k.sessionKeeper.GetSession(ctx, sessionReq)
if err != nil {
// NB: Strip internal error status from error. An appropriate status will be associated by the caller.
err = fmt.Errorf("%s", status.Convert(err).Message())
bryanchriswhite marked this conversation as resolved.
Show resolved Hide resolved
return nil, err
}
onChainSession := sessionRes.GetSession()
Expand Down
19 changes: 16 additions & 3 deletions x/session/keeper/msg_update_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,34 @@ package keeper

import (
"context"
"fmt"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/pokt-network/poktroll/x/session/types"
)

func (k msgServer) UpdateParams(ctx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) {
logger := k.Logger().With("method", "UpdateParams")

if err := req.ValidateBasic(); err != nil {
return nil, err
return nil, status.Error(codes.InvalidArgument, err.Error())
}

if k.GetAuthority() != req.Authority {
return nil, types.ErrSessionInvalidSigner.Wrapf("invalid authority; expected %s, got %s", k.GetAuthority(), req.Authority)
return nil, status.Error(
codes.PermissionDenied,
types.ErrSessionInvalidSigner.Wrapf(
"invalid authority; expected %s, got %s", k.GetAuthority(), req.Authority,
).Error(),
)
}

if err := k.SetParams(ctx, req.Params); err != nil {
return nil, err
err = fmt.Errorf("unable to set params: %w", err)
logger.Error(err.Error())
return nil, status.Error(codes.Internal, err.Error())
}

return &types.MsgUpdateParamsResponse{}, nil
Expand Down
7 changes: 5 additions & 2 deletions x/session/keeper/query_get_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
// GetSession should be deterministic and always return the same session for
// the same block height.
func (k Keeper) GetSession(ctx context.Context, req *types.QueryGetSessionRequest) (*types.QueryGetSessionResponse, error) {
logger := k.Logger().With("method", "GetSession")

if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
Expand All @@ -36,12 +38,13 @@ func (k Keeper) GetSession(ctx context.Context, req *types.QueryGetSessionReques
blockHeight = req.BlockHeight
}

k.Logger().Debug(fmt.Sprintf("Getting session for height: %d", blockHeight))
logger.Debug(fmt.Sprintf("Getting session for height: %d", blockHeight))

sessionHydrator := NewSessionHydrator(req.ApplicationAddress, req.ServiceId, blockHeight)
session, err := k.HydrateSession(ctx, sessionHydrator)
if err != nil {
return nil, err
logger.Error(err.Error())
return nil, status.Error(codes.Internal, err.Error())
}

res := &types.QueryGetSessionResponse{
Expand Down