-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
fix: set block gas meter on prepare/process proposal #15012
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
1e3f16e
updates
alexanderbez 226673f
updates
alexanderbez 33b0927
Merge branch 'main' into bez/14998
alexanderbez 26afd27
updates
alexanderbez 865e785
Merge branch 'main' into bez/14998
alexanderbez 4b60bd5
Merge branch 'bez/14998' of github.com:cosmos/cosmos-sdk into bez/14998
alexanderbez fd556f2
Merge branch 'main' into bez/14998
alexanderbez 5fa36ef
updates
alexanderbez c161d51
Merge branch 'main' into bez/14998
julienrbrt 27e2f57
Merge branch 'main' into bez/14998
alexanderbez 46f317c
Merge branch 'main' into bez/14998
alexanderbez 17d0e67
Merge branch 'main' into bez/14998
alexanderbez aed86b2
updates
alexanderbez 3a6804a
Merge branch 'main' into bez/14998
alexanderbez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -543,15 +543,26 @@ func (app *BaseApp) getState(mode runTxMode) *state { | |
switch mode { | ||
case runTxModeDeliver: | ||
return app.deliverState | ||
|
||
case runTxPrepareProposal: | ||
return app.prepareProposalState | ||
|
||
case runTxProcessProposal: | ||
return app.processProposalState | ||
|
||
default: | ||
return app.checkState | ||
} | ||
} | ||
|
||
func (app *BaseApp) getBlockGasMeter(ctx sdk.Context) storetypes.GasMeter { | ||
if maxGas := app.GetMaximumBlockGas(ctx); maxGas > 0 { | ||
return storetypes.NewGasMeter(maxGas) | ||
} | ||
|
||
return storetypes.NewInfiniteGasMeter() | ||
} | ||
|
||
// retrieve the context for the tx w/ txBytes and other memoized values. | ||
func (app *BaseApp) getContextForTx(mode runTxMode, txBytes []byte) sdk.Context { | ||
modeState := app.getState(mode) | ||
|
@@ -625,8 +636,10 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte) (gInfo sdk.GasInfo, re | |
}() | ||
|
||
blockGasConsumed := false | ||
// consumeBlockGas makes sure block gas is consumed at most once. It must happen after | ||
// tx processing, and must be executed even if tx processing fails. Hence, we use trick with `defer` | ||
|
||
// consumeBlockGas makes sure block gas is consumed at most once. It must | ||
// happen after tx processing, and must be executed even if tx processing | ||
// fails. Hence, it's execution is deferred. | ||
consumeBlockGas := func() { | ||
if !blockGasConsumed { | ||
Comment on lines
636
to
644
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change potentially affects state. Call sequence:
|
||
blockGasConsumed = true | ||
|
@@ -639,8 +652,9 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte) (gInfo sdk.GasInfo, re | |
// If BlockGasMeter() panics it will be caught by the above recover and will | ||
// return an error - in any case BlockGasMeter will consume gas past the limit. | ||
// | ||
// NOTE: This must exist in a separate defer function for the above recovery | ||
// to recover from this one. | ||
// NOTE: consumeBlockGas must exist in a separate defer function from the | ||
// general deferred recovery function to recover from consumeBlockGas as it'll | ||
// be executed first (deferred statements are executed as stack). | ||
if mode == runTxModeDeliver { | ||
defer consumeBlockGas() | ||
} | ||
|
@@ -718,9 +732,7 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte) (gInfo sdk.GasInfo, re | |
// and we're in DeliverTx. Note, runMsgs will never return a reference to a | ||
// Result if any single message fails or does not have a registered Handler. | ||
result, err = app.runMsgs(runMsgCtx, msgs, mode) | ||
|
||
if err == nil { | ||
|
||
// Run optional postHandlers. | ||
// | ||
// Note: If the postHandler fails, we also revert the runMsgs state. | ||
|
@@ -766,7 +778,6 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode runTxMode) (*s | |
|
||
// NOTE: GasWanted is determined by the AnteHandler and GasUsed by the GasMeter. | ||
for i, msg := range msgs { | ||
|
||
if mode != runTxModeDeliver && mode != runTxModeSimulate { | ||
break | ||
} | ||
|
@@ -936,6 +947,7 @@ func (app *BaseApp) DefaultProcessProposal() sdk.ProcessProposalHandler { | |
return abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT} | ||
} | ||
} | ||
|
||
return abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This files contains cosmetic changes only FYI.