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

State Breaking: Backport fix to prevent failed transactions from commiting state when block gas limit is reached #21

Merged
merged 2 commits into from
Jan 14, 2022

Conversation

nddeluca
Copy link
Member

@nddeluca nddeluca commented Jan 14, 2022

Based off of @yihuang's work in cosmos#10814.

}()
}
if mode == runTxModeDeliver {
defer consumeBlockGas()
Copy link
Member Author

Choose a reason for hiding this comment

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

This defer behavior is unchanged and still runs if we do not make it to runMessages for a transaction

if mode == runTxModeDeliver {
blockGasConsumed := false
consumeBlockGas := func() {
if !blockGasConsumed {
Copy link
Member Author

Choose a reason for hiding this comment

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

This check ensures block gas is only consumed once

@@ -678,6 +683,8 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte) (gInfo sdk.GasInfo, re
// Result if any single message fails or does not have a registered Handler.
result, err = app.runMsgs(runMsgCtx, msgs, mode)
if err == nil && mode == runTxModeDeliver {
consumeBlockGas()
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the main fix -- gas is consumed before calling msCache.Write(), ensuring a panic is thrown when if the transaction consumes more than the block limit

Copy link
Member

@karzak karzak left a comment

Choose a reason for hiding this comment

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

Fix looks good, stepped through tests locally as well.

@nddeluca nddeluca merged commit 34462d9 into kd-cosmos-sdk-v0.44.5 Jan 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants