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: feegrant grant period not resetting #9450

Merged
merged 6 commits into from
Jun 7, 2021
Merged

Conversation

ryanchristo
Copy link
Contributor

@ryanchristo ryanchristo commented Jun 2, 2021

Description

This pull request fixes grant period reset to account for an ongoing periodic grant with no total limit.

closes: #9439


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer
  • Review Codecov Report in the comment section below once CI passes

@codecov
Copy link

codecov bot commented Jun 3, 2021

Codecov Report

Merging #9450 (c4d527e) into master (33c045c) will increase coverage by 0.10%.
The diff coverage is 75.63%.

❗ Current head c4d527e differs from pull request most recent head a07658a. Consider uploading reports for the commit a07658a to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #9450      +/-   ##
==========================================
+ Coverage   60.39%   60.50%   +0.10%     
==========================================
  Files         589      590       +1     
  Lines       37099    37342     +243     
==========================================
+ Hits        22405    22592     +187     
- Misses      12715    12769      +54     
- Partials     1979     1981       +2     
Impacted Files Coverage Δ
types/coin.go 93.47% <ø> (ø)
x/authz/msgs.go 51.13% <0.00%> (-5.83%) ⬇️
x/feegrant/msgs.go 63.26% <0.00%> (-8.83%) ⬇️
x/gov/client/cli/query.go 0.00% <0.00%> (ø)
x/gov/client/utils/query.go 23.67% <0.00%> (-4.49%) ⬇️
x/gov/client/testutil/deposits.go 93.75% <93.75%> (ø)
store/types/gas.go 81.48% <100.00%> (+2.31%) ⬆️
x/authz/client/testutil/tx.go 97.78% <100.00%> (+0.15%) ⬆️
x/authz/simulation/operations.go 77.51% <100.00%> (-0.14%) ⬇️
x/feegrant/client/testutil/suite.go 99.68% <100.00%> (+0.01%) ⬆️
... and 4 more

Comment on lines 68 to 71
// if Basic.SpendLimit is not set, reset to PeriodSpendLimit
if a.Basic.SpendLimit.Empty() {
a.PeriodCanSpend = a.PeriodSpendLimit
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can add this check to the condition above but I thought it might be nice to separate for clarity.

Copy link
Contributor

@amaury1093 amaury1093 Jun 4, 2021

Choose a reason for hiding this comment

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

Isn't it a logic error to put here?

Say I create a grant of 200token total, with a max periodic spend limit of 100token/mo, and the grantee uses everything.

  • Expected at beginning of 1st month: a.Basic.SpendLimit == 200, a.PeriodCanSpend == 100
  • Expected at end of 1st month: a.Basic.SpendLimit == 100, a.PeriodCanSpend == 0
  • Expected at beginning of 2nd month: a.Basic.SpendLimit == 100, a.PeriodCanSpend == 100
  • Expected at end of 2nd months: a.Basic.SpendLimit == 0, a.PeriodCanSpend == 0
  • But with this code, after two months: a.Basic.SpendLimit == 0, a.PeriodCanSpend == 100

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At the end of the second month, the grant would be removed. I will take another look and double check.

Copy link
Contributor Author

@ryanchristo ryanchristo Jun 4, 2021

Choose a reason for hiding this comment

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

Just to note, we're not actually updating the value of a.Basic.SpendLimit within the tryResetPeriod method; we are doing that within the Accept method. Maybe this is causing some confusion.

If a.Basic.SpendLimit is set and the result of a.Basic.SpendLimit.SafeSub(a.PeriodSpendLimit) is negative, we will set a.PeriodCanSpend to a.Basic.SpendLimit.

If a.Basic.SpendLimit is not set, the result of a.Basic.SpendLimit.SafeSub(a.PeriodSpendLimit) is always negative, and a.PeriodCanSpend is always set to empty. This pull request fixes this issue.

I believe this is covered in the tests. I also manually tested the above scenario and the grant is removed after the second month (2 minutes in my test). Let me know if you think there is still an edge case I am missing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I consolidated this into the condition that was already there. The same logic applies so let me know if you think I might still be overlooking something.

@ryanchristo ryanchristo marked this pull request as ready for review June 4, 2021 04:45
@ryanchristo ryanchristo force-pushed the ryan/9439-feegrant-reset branch from 41e0146 to 14630ad Compare June 4, 2021 15:34
Copy link
Contributor

@technicallyty technicallyty left a comment

Choose a reason for hiding this comment

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

LGTM! a side note - it might be an unnecessary micro-optimization but I think you could move the added check into one singular if / else if / else block 🤷

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.

lgtm

@amaury1093 amaury1093 added the A:automerge Automatically merge PR once all prerequisites pass. label Jun 7, 2021
@mergify mergify bot merged commit cab40b4 into master Jun 7, 2021
@mergify mergify bot deleted the ryan/9439-feegrant-reset branch June 7, 2021 15:02
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:x/feegrant
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feegrant grant period not resetting
3 participants