Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: (x/feegrant) expiration when overwriting an existing grant #11845

Merged
merged 13 commits into from
May 6, 2022

Conversation

atheeshp
Copy link
Contributor

@atheeshp atheeshp commented May 2, 2022

Description

This PR couple of bugs with expiration not being updated when we overwrite an existing grant with different expiry.

Bug 1
grantee, granter passed wrongly to the getGrant method here:

existingGrant, err := k.getGrant(ctx, grantee, granter)

grantee is passed at granter's place and vice versa

// getGrant returns entire grant between both accounts
func (k Keeper) getGrant(ctx sdk.Context, granter sdk.AccAddress, grantee sdk.AccAddress) (*feegrant.Grant, error) {
store := ctx.KVStore(k.storeKey)
key := feegrant.FeeAllowanceKey(granter, grantee)
bz := store.Get(key)
if len(bz) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "fee-grant not found")
}
var feegrant feegrant.Grant
if err := k.cdc.Unmarshal(bz, &feegrant); err != nil {
return nil, err
}
return &feegrant, nil
}

Bug 2
The following if condition never gets satisfied, getGrant returns err, grant with two possible out comes which are nil, grant or err, nil

if err != nil && existingGrant != nil && existingGrant.GetAllowance() != nil {

and also there is not only one possible error from getGrant with fee-grant not found and also one another possible error is unmarshal error, when there is an unmarshal error we should return the error.


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

@atheeshp atheeshp changed the title fix: expiration when overwriting an existing grant fix: (x/feegrant) expiration when overwriting an existing grant May 2, 2022
@atheeshp atheeshp marked this pull request as ready for review May 2, 2022 14:38
@atheeshp atheeshp requested a review from a team as a code owner May 2, 2022 14:38
Copy link
Contributor

@likhita-809 likhita-809 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

x/feegrant/keeper/keeper.go Outdated Show resolved Hide resolved
@atheeshp atheeshp requested a review from alexanderbez May 5, 2022 10:16
@alexanderbez alexanderbez added the A:automerge Automatically merge PR once all prerequisites pass. label May 5, 2022
@alexanderbez
Copy link
Contributor

@atheeshp can you look into the failing feegrant test?

    --- FAIL: TestIntegrationTestSuite/TestNewCmdRevokeFeegrant (11.80s)

@github-actions github-actions bot added the C:CLI label May 6, 2022
@mergify mergify bot merged commit b1725bf into main May 6, 2022
@mergify mergify bot deleted the ap/fix-feegrant-exp branch May 6, 2022 05:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:automerge Automatically merge PR once all prerequisites pass. C:CLI C:x/feegrant
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants