From 9d9844105cf2facefa07a304cd330d512e1b104d Mon Sep 17 00:00:00 2001 From: Bryan White Date: Fri, 22 Nov 2024 12:03:25 +0100 Subject: [PATCH 1/4] fix: proof module gRPC status error returns --- x/proof/keeper/msg_update_params.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/x/proof/keeper/msg_update_params.go b/x/proof/keeper/msg_update_params.go index 392f9333f..40706284a 100644 --- a/x/proof/keeper/msg_update_params.go +++ b/x/proof/keeper/msg_update_params.go @@ -3,15 +3,23 @@ package keeper import ( "context" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + "github.com/pokt-network/poktroll/x/proof/types" ) func (k msgServer) UpdateParams(ctx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { 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.ErrProofInvalidSigner.Wrapf("invalid authority; expected %s, got %s", k.GetAuthority(), req.Authority) + return nil, status.Error( + codes.PermissionDenied, + types.ErrProofInvalidSigner.Wrapf( + "invalid authority; expected %s, got %s", k.GetAuthority(), req.Authority, + ).Error(), + ) } if err := k.SetParams(ctx, req.Params); err != nil { From b4e3422c8cafa6f0d0144aa0f4b01865d7ec25f8 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Mon, 25 Nov 2024 14:14:35 +0100 Subject: [PATCH 2/4] fix: outstanding proof module non-status (gRPC) errors --- x/proof/keeper/msg_server_create_claim.go | 2 +- x/proof/keeper/msg_update_params.go | 6 +++++- x/proof/keeper/query_claim.go | 6 +++++- x/proof/keeper/query_proof.go | 5 ++++- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/x/proof/keeper/msg_server_create_claim.go b/x/proof/keeper/msg_server_create_claim.go index d9c4a32d3..f9e06055c 100644 --- a/x/proof/keeper/msg_server_create_claim.go +++ b/x/proof/keeper/msg_server_create_claim.go @@ -33,7 +33,7 @@ func (k msgServer) CreateClaim( // Basic validation of the CreateClaim message. if err = msg.ValidateBasic(); err != nil { - return nil, err + return nil, status.Error(codes.InvalidArgument, err.Error()) } logger.Info("validated the createClaim message") diff --git a/x/proof/keeper/msg_update_params.go b/x/proof/keeper/msg_update_params.go index 40706284a..9694a2677 100644 --- a/x/proof/keeper/msg_update_params.go +++ b/x/proof/keeper/msg_update_params.go @@ -2,6 +2,7 @@ package keeper import ( "context" + "fmt" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -10,6 +11,8 @@ import ( ) 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, status.Error(codes.InvalidArgument, err.Error()) } @@ -23,7 +26,8 @@ func (k msgServer) UpdateParams(ctx context.Context, req *types.MsgUpdateParams) } if err := k.SetParams(ctx, req.Params); err != nil { - return nil, err + logger.Error(fmt.Sprintf("unable to set params: %+v", err)) + return nil, status.Error(codes.Internal, err.Error()) } return &types.MsgUpdateParamsResponse{}, nil diff --git a/x/proof/keeper/query_claim.go b/x/proof/keeper/query_claim.go index 520aa4b0c..62900ee51 100644 --- a/x/proof/keeper/query_claim.go +++ b/x/proof/keeper/query_claim.go @@ -3,6 +3,7 @@ package keeper import ( "context" "encoding/binary" + "fmt" "cosmossdk.io/store/prefix" "github.com/cosmos/cosmos-sdk/runtime" @@ -14,6 +15,8 @@ import ( ) func (k Keeper) AllClaims(ctx context.Context, req *types.QueryAllClaimsRequest) (*types.QueryAllClaimsResponse, error) { + logger := k.Logger().With("method", "AllClaims") + if req == nil { return nil, status.Error(codes.InvalidArgument, "invalid request") } @@ -65,7 +68,8 @@ func (k Keeper) AllClaims(ctx context.Context, req *types.QueryAllClaimsRequest) // The value is the encoded claim. var claim types.Claim if err := k.cdc.Unmarshal(value, &claim); err != nil { - return err + logger.Error(fmt.Sprintf("unable to unmarshal claim with key (hex): %x: %+v", key, err)) + return status.Error(codes.Internal, err.Error()) } claims = append(claims, claim) } diff --git a/x/proof/keeper/query_proof.go b/x/proof/keeper/query_proof.go index 12eae432c..c7e2072c1 100644 --- a/x/proof/keeper/query_proof.go +++ b/x/proof/keeper/query_proof.go @@ -14,6 +14,8 @@ import ( ) func (k Keeper) AllProofs(ctx context.Context, req *types.QueryAllProofsRequest) (*types.QueryAllProofsResponse, error) { + logger := k.Logger().With("method", "AllProofs") + if req == nil { return nil, status.Error(codes.InvalidArgument, "invalid request") } @@ -63,7 +65,8 @@ func (k Keeper) AllProofs(ctx context.Context, req *types.QueryAllProofsRequest) // The value is the encoded proof. var proof types.Proof if err := k.cdc.Unmarshal(value, &proof); err != nil { - return err + logger.Error(fmt.Sprintf("unable to unmarshal proof with key (hex): %x: %+v", key, err)) + return status.Error(codes.Internal, err.Error()) } proofs = append(proofs, proof) From 2bd63a6e4f21afcecfa9a5f142491778ff5790a5 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Mon, 25 Nov 2024 15:24:04 +0100 Subject: [PATCH 3/4] chore: self-review improvements --- x/proof/keeper/msg_update_params.go | 3 ++- x/proof/keeper/query_claim.go | 3 ++- x/proof/keeper/query_proof.go | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/x/proof/keeper/msg_update_params.go b/x/proof/keeper/msg_update_params.go index 9694a2677..b4133a5e3 100644 --- a/x/proof/keeper/msg_update_params.go +++ b/x/proof/keeper/msg_update_params.go @@ -26,7 +26,8 @@ func (k msgServer) UpdateParams(ctx context.Context, req *types.MsgUpdateParams) } if err := k.SetParams(ctx, req.Params); err != nil { - logger.Error(fmt.Sprintf("unable to set params: %+v", err)) + fmt.Errorf("unable to set params: %w", err) + logger.Error(err.Error) return nil, status.Error(codes.Internal, err.Error()) } diff --git a/x/proof/keeper/query_claim.go b/x/proof/keeper/query_claim.go index 62900ee51..399cf3f27 100644 --- a/x/proof/keeper/query_claim.go +++ b/x/proof/keeper/query_claim.go @@ -68,7 +68,8 @@ func (k Keeper) AllClaims(ctx context.Context, req *types.QueryAllClaimsRequest) // The value is the encoded claim. var claim types.Claim if err := k.cdc.Unmarshal(value, &claim); err != nil { - logger.Error(fmt.Sprintf("unable to unmarshal claim with key (hex): %x: %+v", key, err)) + err = fmt.Errorf("unable to unmarshal claim with key (hex): %x: %+v", key, err) + logger.Error(err.Error()) return status.Error(codes.Internal, err.Error()) } claims = append(claims, claim) diff --git a/x/proof/keeper/query_proof.go b/x/proof/keeper/query_proof.go index c7e2072c1..f2a84ba42 100644 --- a/x/proof/keeper/query_proof.go +++ b/x/proof/keeper/query_proof.go @@ -65,7 +65,8 @@ func (k Keeper) AllProofs(ctx context.Context, req *types.QueryAllProofsRequest) // The value is the encoded proof. var proof types.Proof if err := k.cdc.Unmarshal(value, &proof); err != nil { - logger.Error(fmt.Sprintf("unable to unmarshal proof with key (hex): %x: %+v", key, err)) + err = fmt.Errorf("unable to unmarshal proof with key (hex): %x: %+v", key, err) + logger.Error(err.Error()) return status.Error(codes.Internal, err.Error()) } From 1edb9b6bad23241cfd4b662e01596de8467236ec Mon Sep 17 00:00:00 2001 From: Bryan White Date: Mon, 25 Nov 2024 15:59:29 +0100 Subject: [PATCH 4/4] fix: typo --- x/proof/keeper/msg_update_params.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/proof/keeper/msg_update_params.go b/x/proof/keeper/msg_update_params.go index b4133a5e3..8b95781b2 100644 --- a/x/proof/keeper/msg_update_params.go +++ b/x/proof/keeper/msg_update_params.go @@ -26,8 +26,8 @@ func (k msgServer) UpdateParams(ctx context.Context, req *types.MsgUpdateParams) } if err := k.SetParams(ctx, req.Params); err != nil { - fmt.Errorf("unable to set params: %w", err) - logger.Error(err.Error) + err = fmt.Errorf("unable to set params: %w", err) + logger.Error(err.Error()) return nil, status.Error(codes.Internal, err.Error()) }