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

fix(baseapp): introduce simulate state #23391

Draft
wants to merge 2 commits into
base: release/v0.52.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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 baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,7 @@ func (app *BaseApp) Commit() (*abci.CommitResponse, error) {
// NOTE: This is safe because CometBFT holds a lock on the mempool for
// Commit. Use the header from this latest block.
app.setState(execModeCheck, header)
app.setState(execModeSimulate, header)

app.finalizeBlockState = nil

Comment on lines 1018 to 1024
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).Commit (baseapp/abci.go:972)

Expand Down
10 changes: 9 additions & 1 deletion baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ type BaseApp struct {
// - finalizeBlockState: Used for FinalizeBlock, which is set based on the
// previous block's state. This state is committed.
checkState *state
simulateState *state
prepareProposalState *state
processProposalState *state
finalizeBlockState *state
Expand Down Expand Up @@ -503,6 +504,10 @@ func (app *BaseApp) setState(mode execMode, h cmtproto.Header) {
case execModeFinalize:
app.finalizeBlockState = baseState

case execModeSimulate:
baseState.SetContext(baseState.Context().WithExecMode(sdk.ExecMode(mode)).WithMinGasPrices(app.minGasPrices))
app.simulateState = baseState

default:
panic(fmt.Sprintf("invalid runTxMode for setState: %d", mode))
}
Expand Down Expand Up @@ -638,6 +643,9 @@ func (app *BaseApp) getState(mode execMode) *state {
case execModeProcessProposal:
return app.processProposalState

case execModeSimulate:
return app.simulateState

default:
return app.checkState
}
Expand Down Expand Up @@ -1025,7 +1033,7 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, reflectMsgs []proto
}

// ADR 031 request type routing
msgResult, err := handler(ctx, msg)
msgResult, err := handler(ctx.WithExecMode(sdk.ExecMode(mode)), msg)
if err != nil {
return nil, errorsmod.Wrapf(err, "failed to execute message; message index: %d", i)
}
Expand Down
Loading