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

Fail early to consume gas if a user doesn't have enough balance #10908

Open
4 tasks
robert-zaremba opened this issue Jan 7, 2022 · 8 comments
Open
4 tasks

Comments

@robert-zaremba
Copy link
Collaborator

robert-zaremba commented Jan 7, 2022

Summary of Bug

This is the highlevel overview of how the fee processing works today in DeliverTx:

  1. When processing a transaction, we consume gas in middlewares and msg handlers
  2. Gas is translated into fees, and fees are paid in https://github.com/cosmos/cosmos-sdk/blob/5d86db3/x/auth/middleware/fee.go#L191 . However:
    • if a user doesn't have enough balance, he won't pay anything
    • the problem is that we will waste resources and user won't pay anything for that
  3. If a block is full, potentially the last transaction is unlucky: if the tx consume more gas than the block limit (we check it only after executing the tx, not as with fee payment - in the checktx), we don't persist the unlucky tx's state transitions (but the sender will still pay the fees).

Proposal:

Refactore Gas framework to:

  • try to adjust the tx fee to the balance user has
    • if user has 1k uatoms, and fees are 1.1k uatoms, we should charge 1k uatoms..
    • adjust gas limit accordingly

Nice to have: #2150

Moreover:

  • DeductFees should be private - it seams to was made public only for the sake of tests, which can be easily translated into the private tests. That function shouldn't be used outside of the middlewares.

Ref:


For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
@robert-zaremba robert-zaremba added this to the v0.46 milestone Jan 7, 2022
@robert-zaremba robert-zaremba changed the title Early fail to consume gas if a user doesn't have enough balance Fail early to consume gas if a user doesn't have enough balance Jan 7, 2022
@amaury1093
Copy link
Contributor

i'm a bit confused tbh, because my understanding of your proposal is what we currently do.

  • "set at the very beginning the max amount of gas we can use": ref, which is a top middleware.
  • "early fail the TX if we use more gas": GasMeter panics, which means we fail as early as possible
  • "charge as much fee for used gas as possible": we always deduct the tx.auth_info.fee. I don't think we should deduct more than that.

@amaury1093
Copy link
Contributor

However, I do agree that if the user does not have enough balance to pay for fees, we should still charge the user something.

@alexanderbez
Copy link
Contributor

alexanderbez commented Jan 7, 2022

if a user doesn't have enough balance, he won't pay anything, and his transaction will be cancelled
the problem is that we will waist resources and user won't pay anything for that

I fail to see how this is a problem really? This check happens during CheckTx and doesn't cost much in the grand scheme of things.

I would suggest restructuring the issue. The proposal doesn't like up with what you claim to be the issue.

@robert-zaremba
Copy link
Collaborator Author

The issue is not related to CheckTx but to DeliverTx phase. Sorry if that was confusing, in the issue I was trying to say that in CheckTx we do the necessary checks, but later, in edge cases, we don't charge the user correctly. I'm going to rephrase that in the issue.

@robert-zaremba
Copy link
Collaborator Author

Maybe, during this task, we should consider implementing "not used feed" (fee we paid for not used gas) return?

@alexanderbez
Copy link
Contributor

@robert-zaremba this might interest you: #2150

@tac0turtle tac0turtle removed this from the v0.46 milestone May 12, 2022
@tac0turtle tac0turtle removed the R:0.46 label Apr 3, 2023
@tac0turtle
Copy link
Member

is this still relevant @alexanderbez ? with application based mempools i feel like most of this is solved, except the fee returning if overpaying.

@alexanderbez
Copy link
Contributor

yeah I still don't quite follow the exact proposal. The main thing I get out of this is that we should perhaps charge a user something in the case where the don't have a sufficient balance to pay fees.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants