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

feat: exceeding block gas meter don't fail #19318

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i
* (crypto/keys) [#18026](https://github.com/cosmos/cosmos-sdk/pull/18026) Made public key generation constant time on `secp256k1`
* (crypto | x/auth) [#14372](https://github.com/cosmos/cosmos-sdk/pull/18194) Key checks on signatures antehandle.
* (types) [#18963](https://github.com/cosmos/cosmos-sdk/pull/18963) Swap out amino json encoding of `ABCIMessageLogs` for std lib json encoding
* (baseapp) [#]() Exceeding block gas meter don't make transaction fail.
yihuang marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

The changelog entry for the modification in baseapp behavior regarding the block gas meter is missing a PR link. Including the PR link provides valuable context and allows readers to easily access more detailed information about the changes. Consider adding the PR link for consistency with other entries and to improve the documentation's utility.


There's a grammatical error in the changelog entry. The correct form should maintain proper subject-verb agreement. Consider revising the sentence for clarity and correctness.

- Exceeding block gas meter don't make transaction fail.
+ Exceeding the block gas meter does not cause transactions to fail.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
* (baseapp) [#]() Exceeding block gas meter don't make transaction fail.
* (baseapp) [#]() Exceeding the block gas meter does not cause transactions to fail.


### Deprecated

Expand Down
6 changes: 6 additions & 0 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,12 @@ func (app *BaseApp) runTx(mode execMode, txBytes []byte) (gInfo sdk.GasInfo, res
// fails. Hence, it's execution is deferred.
consumeBlockGas := func() {
if !blockGasConsumed {
defer func() {
// log and ignore, see: https://github.com/cosmos/cosmos-sdk/issues/19317
if err := recover(); err != nil {
ctx.Logger().Error("block gas limit exceeded", "err", err)
Comment on lines 842 to +848
Copy link
Contributor

Choose a reason for hiding this comment

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

Change potentially affects state.

Call sequence:

(*github.com/cosmos/cosmos-sdk/baseapp.BaseApp).runTx (baseapp/baseapp.go:814)
(*github.com/cosmos/cosmos-sdk/baseapp.BaseApp).deliverTx (baseapp/baseapp.go:744)
(*github.com/cosmos/cosmos-sdk/baseapp.BaseApp).internalFinalizeBlock (baseapp/baseapp.go:713)
(*github.com/cosmos/cosmos-sdk/baseapp.BaseApp).FinalizeBlock (baseapp/baseapp.go:874)

}
}()
blockGasConsumed = true
ctx.BlockGasMeter().ConsumeGas(
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, can you please explain again how this could panic, thus making recovery needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's related to unused gas refunding, if we include tx by user provided gas limit, they can fill block space with unused gas, the actually used gas is always lower than the block gas limit, we did some hack to include more txs, so we got exceeding block gas limit situation occasionally.
If we plan to remove block gas meter at all, maybe we can simply live with the situation.

ctx.GasMeter().GasConsumedToLimit(), "block gas meter",
Expand Down
Loading