Skip to content

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

Open
@robert-zaremba

Description

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

Activity

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

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions