From 053ae318967c266ddc6f6efac800e759c6c943c1 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Mon, 25 Nov 2024 14:54:06 +0100 Subject: [PATCH 1/5] fix: outstanding session module non-status (gRPC) errors --- x/session/keeper/msg_update_params.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/x/session/keeper/msg_update_params.go b/x/session/keeper/msg_update_params.go index 84a5debfa..57564b921 100644 --- a/x/session/keeper/msg_update_params.go +++ b/x/session/keeper/msg_update_params.go @@ -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 From efac01893d62bad0490b21d844c40453f9637693 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Wed, 27 Nov 2024 11:09:09 +0100 Subject: [PATCH 2/5] fix: session hydration query --- x/session/keeper/query_get_session.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/x/session/keeper/query_get_session.go b/x/session/keeper/query_get_session.go index bc25fff0e..1b8c31082 100644 --- a/x/session/keeper/query_get_session.go +++ b/x/session/keeper/query_get_session.go @@ -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") } @@ -36,12 +38,14 @@ 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 + err = types.ErrSessionHydration.Wrapf("QueryGetSessionRequest: %+v: %s", req, err) + logger.Error(err.Error()) + return nil, status.Error(codes.Internal, err.Error()) } res := &types.QueryGetSessionResponse{ From 4b3fe020bdbfb8534737372f18e32d3be99eb06a Mon Sep 17 00:00:00 2001 From: Bryan White Date: Wed, 27 Nov 2024 13:59:37 +0100 Subject: [PATCH 3/5] Revert "fix: session hydration query" This reverts commit efac01893d62bad0490b21d844c40453f9637693. --- x/session/keeper/query_get_session.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/x/session/keeper/query_get_session.go b/x/session/keeper/query_get_session.go index 1b8c31082..bc25fff0e 100644 --- a/x/session/keeper/query_get_session.go +++ b/x/session/keeper/query_get_session.go @@ -14,8 +14,6 @@ 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") } @@ -38,14 +36,12 @@ func (k Keeper) GetSession(ctx context.Context, req *types.QueryGetSessionReques blockHeight = req.BlockHeight } - logger.Debug(fmt.Sprintf("Getting session for height: %d", blockHeight)) + k.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 { - err = types.ErrSessionHydration.Wrapf("QueryGetSessionRequest: %+v: %s", req, err) - logger.Error(err.Error()) - return nil, status.Error(codes.Internal, err.Error()) + return nil, err } res := &types.QueryGetSessionResponse{ From 79ae0c714100019440ba5964c4278b99f403cd55 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Wed, 27 Nov 2024 14:04:11 +0100 Subject: [PATCH 4/5] Reapply "fix: session hydration query" This reverts commit 4b3fe020bdbfb8534737372f18e32d3be99eb06a. --- x/session/keeper/query_get_session.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/x/session/keeper/query_get_session.go b/x/session/keeper/query_get_session.go index bc25fff0e..1b8c31082 100644 --- a/x/session/keeper/query_get_session.go +++ b/x/session/keeper/query_get_session.go @@ -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") } @@ -36,12 +38,14 @@ 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 + err = types.ErrSessionHydration.Wrapf("QueryGetSessionRequest: %+v: %s", req, err) + logger.Error(err.Error()) + return nil, status.Error(codes.Internal, err.Error()) } res := &types.QueryGetSessionResponse{ From 438b8624b0d9d098d697d844ac49a67857da741b Mon Sep 17 00:00:00 2001 From: Bryan White Date: Wed, 27 Nov 2024 14:30:43 +0100 Subject: [PATCH 5/5] fix: session query error & test --- x/proof/keeper/session.go | 4 ++++ x/session/keeper/query_get_session.go | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/x/proof/keeper/session.go b/x/proof/keeper/session.go index 9d33d76c6..68a72cf10 100644 --- a/x/proof/keeper/session.go +++ b/x/proof/keeper/session.go @@ -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" @@ -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()) return nil, err } onChainSession := sessionRes.GetSession() diff --git a/x/session/keeper/query_get_session.go b/x/session/keeper/query_get_session.go index 1b8c31082..412d77c45 100644 --- a/x/session/keeper/query_get_session.go +++ b/x/session/keeper/query_get_session.go @@ -43,7 +43,6 @@ func (k Keeper) GetSession(ctx context.Context, req *types.QueryGetSessionReques sessionHydrator := NewSessionHydrator(req.ApplicationAddress, req.ServiceId, blockHeight) session, err := k.HydrateSession(ctx, sessionHydrator) if err != nil { - err = types.ErrSessionHydration.Wrapf("QueryGetSessionRequest: %+v: %s", req, err) logger.Error(err.Error()) return nil, status.Error(codes.Internal, err.Error()) }