Skip to content

Commit

Permalink
[Code Health] fix: tokenomics module gRPC return errors (#963)
Browse files Browse the repository at this point in the history
## Summary

Ensure all supplier message and query handlers return gRPC status
errors.

## Issue

- #860

## Type of change

Select one or more from the following:

- [ ] New feature, functionality or library
- [ ] 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

---------

Co-authored-by: red-0ne <[email protected]>
  • Loading branch information
bryanchriswhite and red-0ne authored Dec 2, 2024
1 parent 1a6cabd commit 74a23eb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
10 changes: 8 additions & 2 deletions x/tokenomics/keeper/msg_server_update_param.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 14 additions & 6 deletions x/tokenomics/keeper/msg_update_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,36 @@ import (
"context"
"fmt"

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

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

func (k msgServer) UpdateParams(ctx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) {
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 = fmt.Errorf("unable to set params: %w", err)
logger.Error(err.Error())
return nil, status.Error(codes.Internal, err.Error())
}

logger.Info("Done updating params")
Expand Down

0 comments on commit 74a23eb

Please sign in to comment.