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 or Feature]: the changes made in precommiter and abci listeners are ignored #22246

Open
1 task done
beer-1 opened this issue Oct 12, 2024 · 0 comments
Open
1 task done
Labels

Comments

@beer-1
Copy link
Contributor

beer-1 commented Oct 12, 2024

Is there an existing issue for this?

  • I have searched the existing issues

What happened?

Current cosmos sdk is writing the changes infinalizeBlockState right after internalFinalize finished by calling app.workingHash().

cosmos-sdk/baseapp/abci.go

Lines 925 to 928 in 65ed5eb

res, err = app.internalFinalizeBlock(context.Background(), req)
if res != nil {
res.AppHash = app.workingHash()
}

cosmos-sdk/baseapp/abci.go

Lines 1013 to 1017 in 65ed5eb

func (app *BaseApp) workingHash() []byte {
// Write the FinalizeBlock state into branched storage and commit the MultiStore.
// The write to the FinalizeBlock state writes all state transitions to the root
// MultiStore (app.cms) so when Commit() is called it persists those values.
app.finalizeBlockState.ms.Write()

but abci listeners and precommiter are called with this already written finalizeBlockState

cosmos-sdk/baseapp/abci.go

Lines 897 to 901 in 65ed5eb

for _, streamingListener := range app.streamingManager.ABCIListeners {
if err := streamingListener.ListenFinalizeBlock(app.finalizeBlockState.Context(), *req, *res); err != nil {
app.logger.Error("ListenFinalizeBlock listening hook failed", "height", req.Height, "err", err)
}
}

cosmos-sdk/baseapp/abci.go

Lines 979 to 987 in 65ed5eb

ctx := app.finalizeBlockState.Context()
blockHeight := ctx.BlockHeight()
changeSet := app.cms.PopStateCache()
for _, abciListener := range abciListeners {
if err := abciListener.ListenCommit(ctx, *resp, changeSet); err != nil {
app.logger.Error("Commit listening hook failed", "height", blockHeight, "err", err)
}
}

cosmos-sdk/baseapp/abci.go

Lines 962 to 964 in 65ed5eb

if app.precommiter != nil {
app.precommiter(app.finalizeBlockState.Context())
}

and the finalizeBlockState is trashed in commit

app.finalizeBlockState = nil

so all changes made in the abci listeners and precommiter are trashed.

Is it intended?

If this is intended, it should be good to make a new interface to pass finalize request and response for custom logics similar with ListenFinalizeBlock but can write some state changes. Need this interface in v0.50!!

Cosmos SDK Version

v0.50, latest

How to reproduce?

update state in abci listeners or precommiter

@beer-1 beer-1 added the T:Bug label Oct 12, 2024
@beer-1 beer-1 changed the title [Bug]: the changes made in precommiter and abci listeners are ignored [Bug or Feature]: the changes made in precommiter and abci listeners are ignored Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: 📋 Backlog
Development

No branches or pull requests

1 participant