Skip to content

[Bug or Feature]: the changes made in precommiter and abci listeners are ignored #22246

Open
@beer-1

Description

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.

Not sure this is intended or not?

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    • Status

      📋 Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions