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

chore: (x/feegrant) update keeper logic to do not allow duplicate grant #14294

Merged
merged 14 commits into from
Jan 9, 2023

Conversation

atheeshp
Copy link
Contributor

@atheeshp atheeshp commented Dec 14, 2022

Description

Closes: #XXXX

in x/feegrant:

  • msg_server logic rejects the duplicate grants, but the keeper logic had the logic to update the duplicate grant request.
  • in a recent discussion, we decided to clean the keeper logic of grant updation and move the duplicate grant request logic from msg_server to keeper.

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)

@@ -41,6 +41,11 @@

// GrantAllowance creates a new grant
func (k Keeper) GrantAllowance(ctx sdk.Context, granter, grantee sdk.AccAddress, feeAllowance feegrant.FeeAllowanceI) error {
// Checking for duplicate entry
if f, _ := k.GetAllowance(ctx, granter, grantee); f != nil {

Check warning

Code scanning / gosec

Returned error is not propagated up the stack.

Returned error is not propagated up the stack.
@atheeshp atheeshp requested a review from amaury1093 December 14, 2022 10:23
@atheeshp atheeshp marked this pull request as ready for review December 14, 2022 10:54
@atheeshp atheeshp requested a review from a team as a code owner December 14, 2022 10:54
@julienrbrt
Copy link
Member

Do we backport that to 0.47? I think this warrants a changelog.

@alexanderbez alexanderbez added the backport/v0.47.x PR scheduled for inclusion in the v0.47's next stable release label Dec 15, 2022
@alexanderbez
Copy link
Contributor

Do we backport that to 0.47? I think this warrants a changelog.

yes and yes. Please add a CL entry :)

x/feegrant/keeper/keeper.go Show resolved Hide resolved
Comment on lines +59 to +60
exp, err := feeAllowance.ExpiresAt()
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought the PR was only about moving the duplicate entry check from msg_server to keeper.

Can you explain what these changes are about?

Copy link
Contributor

Choose a reason for hiding this comment

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

up

Copy link
Contributor Author

@atheeshp atheeshp Jan 3, 2023

Choose a reason for hiding this comment

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

Yes, the removed logic is for handling duplicate grant (previously we are updating the expiration with the newer grant's expiration for the duplicate grant), which is now unreachable if duplicate grant found.

@alexanderbez
Copy link
Contributor

Message service handlers should validate input/output. Keepers should validate the state machine transitions. So if a dup grant exists, that validation should happen in the keeper and that error should bubble up to the message service handler and be returned there IMO.

@atheeshp
Copy link
Contributor Author

Do we backport that to 0.47? I think this warrants a changelog.

I guess this shouldn't go in v0.47
cc: @AmauryM

@atheeshp atheeshp requested a review from amaury1093 December 21, 2022 06:54
@alexanderbez alexanderbez mentioned this pull request Dec 21, 2022
54 tasks
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 4, 2023

[Cosmos SDK] Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

Copy link
Contributor

@amaury1093 amaury1093 left a comment

Choose a reason for hiding this comment

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

utACK, new logic is much easier to understand.

@amaury1093
Copy link
Contributor

Since we already audited feegrant, I propose to leave it out of 0.47, and just include it in 0.48.

Unless someones wants to do a more thorough auditing e.g. w/ manual testing, then we can also backport. In 99% of the app chains it actually won't be state-machine breaking.

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.

minor nit, utACK

x/feegrant/keeper/keeper_test.go Outdated Show resolved Hide resolved
@julienrbrt julienrbrt removed the backport/v0.47.x PR scheduled for inclusion in the v0.47's next stable release label Jan 9, 2023
@julienrbrt
Copy link
Member

Removing the backport tag as per #14294 (comment)

Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

utACK

@julienrbrt julienrbrt enabled auto-merge (squash) January 9, 2023 09:08
CHANGELOG.md Outdated Show resolved Hide resolved
@julienrbrt julienrbrt merged commit b8b34a6 into main Jan 9, 2023
@julienrbrt julienrbrt deleted the ap/cleanup_feegrant branch January 9, 2023 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants