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

[Bug]: Gas Consumption idiosyncracies in BeginBlock / DeliverTx #18609

Closed
1 task done
nivasan1 opened this issue Dec 1, 2023 · 1 comment · Fixed by #18714
Closed
1 task done

[Bug]: Gas Consumption idiosyncracies in BeginBlock / DeliverTx #18609

nivasan1 opened this issue Dec 1, 2023 · 1 comment · Fixed by #18714
Labels

Comments

@nivasan1
Copy link
Contributor

nivasan1 commented Dec 1, 2023

Is there an existing issue for this?

  • I have searched the existing issues

What happened?

Context

  • The BaseApp has two gas-meters in state blockGasMeter, gasMeter
    • blockGasMeter - Should track all gas consumed across block execution
    • gasMeter - Should track gas consumed in tx-execution

Bug

  • expected behavior
    • The blockGasMeter tracks gas consumed across the block's executon (BeginBlock, DeliverTx, EndBlock)
    • The gasMeter in runTx is 0 before tx-execution occurs
  • actual behavior
    • Gas is not consumed in BeginBlock, instead, the gas consumed from BeginBlock exists on the gasMeter that runs into runTx, and is reset by the SetupDecorator in the execution of the first tx's AnteHandler sequence.

Simplest Fix

  • The simplest fix (not necessarily correct)
    • Consume blockGas in BeginBlock from the gasMeter
    • After consumption, reset the gasMeter at the end of BeginBlock

Cosmos SDK Version

0.47

How to reproduce?

No response

@nivasan1 nivasan1 added the T:Bug label Dec 1, 2023
@alexanderbez
Copy link
Contributor

alexanderbez commented Dec 1, 2023

The blockGasMeter tracks gas consumed across the block's executon (BeginBlock, DeliverTx, EndBlock)

I just want to clarify something. The BlockGasMeter is only meant to track the cumulative gas consumed across all txs in a block. I.e. it should ignore BeginBlock and EndBlock.

The fix should actually be to ensure the GasMeter is 0 when processing the 1st tx in each block. This could simply be done at the end of BeginBlock.

Regardless, I'd like to write a unit test to reproduce it.

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

Successfully merging a pull request may close this issue.

2 participants