diff --git a/CHANGELOG.md b/CHANGELOG.md index 64dbc17da0ae..734ca492f1eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (auth) [#13460](https://github.com/cosmos/cosmos-sdk/pull/13460) The `q auth address-by-id` CLI command has been renamed to `q auth address-by-acc-num` to be more explicit. However, the old `address-by-id` version is still kept as an alias, for backwards compatibility. +### Bug Fixes + +* (store) [#13459](https://github.com/cosmos/cosmos-sdk/pull/13459) Don't let state listener observe the uncommitted writes. + ## [v0.46.2](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.2) - 2022-10-03 ### API Breaking Changes diff --git a/store/cachemulti/store.go b/store/cachemulti/store.go index cf15b13d16d7..3b0265cb0f22 100644 --- a/store/cachemulti/store.go +++ b/store/cachemulti/store.go @@ -41,6 +41,9 @@ func NewFromKVStore( store types.KVStore, stores map[types.StoreKey]types.CacheWrapper, keys map[string]types.StoreKey, traceWriter io.Writer, traceContext types.TraceContext, ) Store { + if listeners == nil { + listeners = make(map[types.StoreKey][]types.WriteListener) + } cms := Store{ db: cachekv.NewStore(store), stores: make(map[types.StoreKey]types.CacheWrap, len(stores)), @@ -78,7 +81,8 @@ func newCacheMultiStoreFromCMS(cms Store) Store { stores[k] = v } - return NewFromKVStore(cms.db, stores, nil, cms.traceWriter, cms.traceContext) + // don't pass listeners to nested cache store. + return NewFromKVStore(cms.db, stores, nil, cms.traceWriter, cms.traceContext, nil) } // SetTracer sets the tracer for the MultiStore that the underlying diff --git a/store/rootmulti/store_test.go b/store/rootmulti/store_test.go index c4d760ae4b2c..989e12a77b11 100644 --- a/store/rootmulti/store_test.go +++ b/store/rootmulti/store_test.go @@ -872,7 +872,7 @@ func (tl *MockListener) OnWrite(storeKey types.StoreKey, key []byte, value []byt func TestStateListeners(t *testing.T) { var db dbm.DB = dbm.NewMemDB() - ms := newMultiStoreWithMounts(db, types.NewPruningOptionsFromString(types.PruningOptionNothing)) + ms := newMultiStoreWithMounts(db, pruningtypes.NewPruningOptions(pruningtypes.PruningNothing)) listener := &MockListener{} ms.AddListeners(testStoreKey1, []types.WriteListener{listener})