Skip to content

Commit

Permalink
[Code Health] fix: proof module gRPC status error returns (#956)
Browse files Browse the repository at this point in the history
## Summary

Ensure all proof module message and query handlers return gRPC status
errors.

## Issue

- #954 

## Type of change

Select one or more from the following:

- [ ] New feature, functionality or library
- [x] Consensus breaking; add the `consensus-breaking` label if so. See
#791 for details
- [ ] Bug fix
- [x] Code health or cleanup
- [ ] Documentation
- [ ] Other (specify)

## Testing

- [ ] **Documentation**: `make docusaurus_start`; only needed if you
make doc changes
- [x] **Unit Tests**: `make go_develop_and_test`
- [ ] **LocalNet E2E Tests**: `make test_e2e`
- [x] **DevNet E2E Tests**: Add the `devnet-test-e2e` label to the PR.

## Sanity Checklist

- [x] I have tested my changes using the available tooling
- [ ] I have commented my code
- [x] I have performed a self-review of my own code; both comments &
source code
- [ ] I create and reference any new tickets, if applicable
- [ ] I have left TODOs throughout the codebase, if applicable
  • Loading branch information
bryanchriswhite authored Dec 2, 2024
1 parent 09702d6 commit be817c2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
2 changes: 1 addition & 1 deletion x/proof/keeper/msg_server_create_claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
19 changes: 16 additions & 3 deletions x/proof/keeper/msg_update_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,33 @@ package keeper

import (
"context"
"fmt"

"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) {
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.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 {
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: 6 additions & 1 deletion x/proof/keeper/query_claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
"context"
"encoding/binary"
"fmt"

"cosmossdk.io/store/prefix"
"github.com/cosmos/cosmos-sdk/runtime"
Expand All @@ -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")
}
Expand Down Expand Up @@ -65,7 +68,9 @@ 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
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)
}
Expand Down
6 changes: 5 additions & 1 deletion x/proof/keeper/query_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -63,7 +65,9 @@ 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
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())
}

proofs = append(proofs, proof)
Expand Down

0 comments on commit be817c2

Please sign in to comment.