Fail early to consume gas if a user doesn't have enough balance #10908
Open
Description
opened on Jan 7, 2022
Summary of Bug
This is the highlevel overview of how the fee processing works today in DeliverTx
:
- When processing a transaction, we consume gas in middlewares and msg handlers
- 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
- 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:
- fix: use full gas on overflow #10897
- fix: should revert tx when block gas limit exceeded #10770
- Refunding unused but allocated gas #2150
For Admin Use
- Not duplicate issue
- Appropriate labels applied
- Appropriate contributors tagged
- Contributor assigned/self-assigned
Activity