From 36148300b012a69227ddc022027b428b498a4369 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Mon, 25 Nov 2024 16:37:09 +0100 Subject: [PATCH 1/2] fix: outstanding tokenomics module non-status (gRPC) errors --- .../keeper/msg_server_update_param.go | 10 ++++++++-- x/tokenomics/keeper/msg_update_params.go | 19 +++++++++++++------ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/x/tokenomics/keeper/msg_server_update_param.go b/x/tokenomics/keeper/msg_server_update_param.go index 92af35e30..643ee17a8 100644 --- a/x/tokenomics/keeper/msg_server_update_param.go +++ b/x/tokenomics/keeper/msg_server_update_param.go @@ -22,11 +22,17 @@ func (k msgServer) UpdateParam( ) if err := msg.ValidateBasic(); err != nil { - return nil, err + return nil, status.Error(codes.InvalidArgument, err.Error()) } if k.GetAuthority() != msg.Authority { - return nil, tokenomicstypes.ErrTokenomicsInvalidSigner.Wrapf("invalid authority; expected %s, got %s", k.GetAuthority(), msg.Authority) + return nil, status.Error( + codes.PermissionDenied, + tokenomicstypes.ErrTokenomicsInvalidSigner.Wrapf( + "invalid authority; expected %s, got %s", + k.GetAuthority(), msg.Authority, + ).Error(), + ) } params := k.GetParams(ctx) diff --git a/x/tokenomics/keeper/msg_update_params.go b/x/tokenomics/keeper/msg_update_params.go index cefb8e7d6..067ebf608 100644 --- a/x/tokenomics/keeper/msg_update_params.go +++ b/x/tokenomics/keeper/msg_update_params.go @@ -4,6 +4,9 @@ import ( "context" "fmt" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + "github.com/pokt-network/poktroll/x/tokenomics/types" ) @@ -11,21 +14,25 @@ func (k msgServer) UpdateParams(ctx context.Context, msg *types.MsgUpdateParams) logger := k.Logger() if err := msg.ValidateBasic(); err != nil { - return nil, err + return nil, status.Error(codes.InvalidArgument, err.Error()) } if msg.Authority != k.GetAuthority() { - return nil, types.ErrTokenomicsInvalidSigner.Wrapf( - "invalid authority; expected %s, got %s", - k.GetAuthority(), - msg.Authority, + return nil, status.Error( + codes.PermissionDenied, + types.ErrTokenomicsInvalidSigner.Wrapf( + "invalid authority; expected %s, got %s", + k.GetAuthority(), + msg.Authority, + ).Error(), ) } logger.Info(fmt.Sprintf("About to update params from [%v] to [%v]", k.GetParams(ctx), msg.Params)) if err := k.SetParams(ctx, msg.Params); err != nil { - return nil, err + err = status.Error(codes.Internal, err.Error()) + return nil, status.Error(codes.Internal, err.Error()) } logger.Info("Done updating params") From 039364d59c6473f91f49df18658f9327af9a5602 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Mon, 2 Dec 2024 09:25:38 +0100 Subject: [PATCH 2/2] chore: review feedback improvements Co-authored-by: red-0ne --- x/tokenomics/keeper/msg_update_params.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x/tokenomics/keeper/msg_update_params.go b/x/tokenomics/keeper/msg_update_params.go index 067ebf608..16e1bfe95 100644 --- a/x/tokenomics/keeper/msg_update_params.go +++ b/x/tokenomics/keeper/msg_update_params.go @@ -31,7 +31,8 @@ func (k msgServer) UpdateParams(ctx context.Context, msg *types.MsgUpdateParams) logger.Info(fmt.Sprintf("About to update params from [%v] to [%v]", k.GetParams(ctx), msg.Params)) if err := k.SetParams(ctx, msg.Params); err != nil { - err = status.Error(codes.Internal, err.Error()) + err = fmt.Errorf("unable to set params: %w", err) + logger.Error(err.Error()) return nil, status.Error(codes.Internal, err.Error()) }