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

x/authz charge gas for expensive authorizations #8995

Merged
merged 20 commits into from
Apr 9, 2021
Merged

Conversation

aleem1314
Copy link
Contributor

Description

closes: #8984


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

@orijbot
Copy link

orijbot commented Mar 25, 2021

@orijbot
Copy link

orijbot commented Mar 25, 2021

@orijbot
Copy link

orijbot commented Mar 25, 2021

@orijbot
Copy link

orijbot commented Mar 25, 2021

x/staking/types/authz.go Outdated Show resolved Hide resolved
@orijbot
Copy link

orijbot commented Mar 25, 2021

@orijbot
Copy link

orijbot commented Mar 25, 2021

x/staking/types/authz.go Outdated Show resolved Hide resolved
@aleem1314 aleem1314 requested a review from aaronc March 25, 2021 17:19
@orijbot
Copy link

orijbot commented Mar 25, 2021

Copy link
Member

@aaronc aaronc left a comment

Choose a reason for hiding this comment

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

Looks like a good start. Is this R4R?

@orijbot
Copy link

orijbot commented Mar 26, 2021

@aleem1314 aleem1314 marked this pull request as ready for review March 26, 2021 05:19
@codecov
Copy link

codecov bot commented Mar 26, 2021

Codecov Report

Merging #8995 (f497bcc) into master (6e26ee9) will increase coverage by 0.12%.
The diff coverage is 51.85%.

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

@@            Coverage Diff             @@
##           master    #8995      +/-   ##
==========================================
+ Coverage   58.97%   59.10%   +0.12%     
==========================================
  Files         576      574       -2     
  Lines       32377    32241     -136     
==========================================
- Hits        19095    19055      -40     
+ Misses      11041    10950      -91     
+ Partials     2241     2236       -5     
Impacted Files Coverage Δ
x/bank/types/send_authorization.go 61.11% <20.00%> (+61.11%) ⬆️
x/authz/types/msgs.go 53.19% <50.00%> (-0.66%) ⬇️
x/staking/types/authz.go 84.93% <57.14%> (-2.95%) ⬇️
x/authz/simulation/operations.go 80.32% <60.00%> (-0.79%) ⬇️
x/authz/types/generic_authorization.go 71.42% <60.00%> (+71.42%) ⬆️
x/authz/keeper/keeper.go 71.29% <100.00%> (ø)
x/auth/keeper/keeper.go 48.61% <0.00%> (-0.69%) ⬇️
x/bank/keeper/keeper.go 70.64% <0.00%> (-0.29%) ⬇️
types/query/pagination.go 80.00% <0.00%> (ø)
x/upgrade/keeper/keeper.go 76.51% <0.00%> (ø)
... and 12 more

@orijbot
Copy link

orijbot commented Mar 26, 2021

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.

nits left, so pre-approving 🎉

types/tx/types.go Outdated Show resolved Hide resolved
x/authz/types/msgs.go Outdated Show resolved Hide resolved
x/staking/types/authz.go Show resolved Hide resolved
@orijbot
Copy link

orijbot commented Mar 29, 2021

@orijbot
Copy link

orijbot commented Mar 29, 2021

@orijbot
Copy link

orijbot commented Mar 29, 2021

@orijbot
Copy link

orijbot commented Mar 29, 2021

@orijbot
Copy link

orijbot commented Mar 29, 2021

@orijbot
Copy link

orijbot commented Mar 29, 2021

@@ -68,13 +80,16 @@ func (authorization StakeAuthorization) Accept(msg sdk.ServiceMsg, block tmproto
isValidatorExists := false
allowedList := authorization.GetAllowList().GetAddress()
for _, validator := range allowedList {
ctx.GasMeter().ConsumeGas(gasCostPerIteration, "stake authorization")
Copy link
Member

Choose a reason for hiding this comment

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

how do external clients know how much this number is? Are they required to dive into the code?

Copy link
Collaborator

Choose a reason for hiding this comment

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

They are not able to know exact number of gas. It would require a simulated run.
You can't do it, because one message can trigger many operations. And I don't think it would make sense to give exact numbers to clients. However, we should provide some estimates based on simulations.

Copy link
Member

Choose a reason for hiding this comment

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

Could you possibly help with that @robert-zaremba ?

denyList := authorization.GetDenyList().GetAddress()
for _, validator := range denyList {
ctx.GasMeter().ConsumeGas(gasCostPerIteration, "stake authorization")
Copy link
Member

Choose a reason for hiding this comment

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

ditto

@tac0turtle
Copy link
Member

Thank you for the PR. I like where this is going, but it's hard to justify a hard coded value for gas like this. I may have missed something, but it doesn't seem there is a way for clients to know the cost of this transaction. What is wrong with adding a new method to Module.BasicManager that allows modules to register custom gas costs of a tx allowing clients to see the cost?

I may also be conflating gas and fees here.

@amaury1093 amaury1093 requested a review from cyberbono3 March 31, 2021 17:18
@aleem1314 aleem1314 mentioned this pull request Apr 6, 2021
4 tasks
@clevinson
Copy link
Contributor

@robert-zaremba suggesting on our call that we go with 10 (per iteration) for gas charge.

@atheeshp atheeshp self-requested a review April 8, 2021 10:48
Copy link
Contributor

@atheeshp atheeshp left a comment

Choose a reason for hiding this comment

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

LGTM, couple of nits.

x/staking/types/authz_test.go Outdated Show resolved Hide resolved
x/staking/types/authz_test.go Outdated Show resolved Hide resolved

// ValidateBasic implements Authorization.ValidateBasic.
func (authorization GenericAuthorization) ValidateBasic() error {
if !msgservice.IsServiceMsg(authorization.MessageName) {
Copy link
Contributor

@cyberbono3 cyberbono3 Apr 9, 2021

Choose a reason for hiding this comment

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

I am not sure if counting of "/" in IsServiceMsg is sufficient to check if typeURL satisfies service method name type e.g. i.e. /cosmos.bank.Msg/Send

@amaury1093 amaury1093 added the A:automerge Automatically merge PR once all prerequisites pass. label Apr 9, 2021
@mergify mergify bot merged commit 8a376a4 into master Apr 9, 2021
@mergify mergify bot deleted the aleem/8984-authz-gas branch April 9, 2021 12:33
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/authz
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add sdk.Context to Authorization.Accept method and charge gas for expensive authorizations
10 participants