diff --git a/CHANGELOG.md b/CHANGELOG.md index de12296b03..e5e8ee70cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -71,6 +71,7 @@ - [#1099](https://github.com/crypto-org-chain/cronos/pull/1099) clean up memiavl tmp directories left behind. - [#940](https://github.com/crypto-org-chain/cronos/pull/940) Update rocksdb dependency to 8.1.1. - [#1149](https://github.com/crypto-org-chain/cronos/pull/1149) memiavl support `WorkingHash` api required by `FinalizeBlock`. +- [#1151](https://github.com/crypto-org-chain/cronos/pull/1151) memiavl `CacheMultiStoreWithVersion` supports `io.Closer`. *April 13, 2023* diff --git a/store/cachemulti/store.go b/store/cachemulti/store.go new file mode 100644 index 0000000000..891bf61274 --- /dev/null +++ b/store/cachemulti/store.go @@ -0,0 +1,37 @@ +package cachemulti + +import ( + "io" + + "github.com/cosmos/cosmos-sdk/store/cachemulti" + "github.com/cosmos/cosmos-sdk/store/types" + dbm "github.com/tendermint/tm-db" +) + +var NoopCloser io.Closer = CloserFunc(func() error { return nil }) + +type CloserFunc func() error + +func (fn CloserFunc) Close() error { + return fn() +} + +// Store wraps sdk's cachemulti.Store to add io.Closer interface +type Store struct { + cachemulti.Store + io.Closer +} + +func NewStore( + db dbm.DB, stores map[types.StoreKey]types.CacheWrapper, keys map[string]types.StoreKey, + traceWriter io.Writer, traceContext types.TraceContext, + closer io.Closer, +) Store { + if closer == nil { + closer = NoopCloser + } + return Store{ + Store: cachemulti.NewStore(db, stores, keys, traceWriter, traceContext), + Closer: closer, + } +} diff --git a/store/rootmulti/store.go b/store/rootmulti/store.go index 9f8c69cff1..8395dc6ca9 100644 --- a/store/rootmulti/store.go +++ b/store/rootmulti/store.go @@ -15,7 +15,6 @@ import ( pruningtypes "github.com/cosmos/cosmos-sdk/pruning/types" snapshottypes "github.com/cosmos/cosmos-sdk/snapshots/types" - "github.com/cosmos/cosmos-sdk/store/cachemulti" "github.com/cosmos/cosmos-sdk/store/listenkv" "github.com/cosmos/cosmos-sdk/store/mem" "github.com/cosmos/cosmos-sdk/store/rootmulti" @@ -24,6 +23,7 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/crypto-org-chain/cronos/memiavl" + "github.com/crypto-org-chain/cronos/store/cachemulti" "github.com/crypto-org-chain/cronos/store/memiavlstore" ) @@ -191,7 +191,7 @@ func (rs *Store) CacheMultiStore() types.CacheMultiStore { } stores[k] = store } - return cachemulti.NewStore(nil, stores, rs.keysByName, nil, nil) + return cachemulti.NewStore(nil, stores, rs.keysByName, nil, nil, nil) } // Implements interface MultiStore @@ -222,7 +222,7 @@ func (rs *Store) CacheMultiStoreWithVersion(version int64) (types.CacheMultiStor stores[rs.keysByName[tree.Name]] = memiavlstore.New(tree.Tree, rs.logger) } - return cachemulti.NewStore(nil, stores, rs.keysByName, nil, nil), nil + return cachemulti.NewStore(nil, stores, rs.keysByName, nil, nil, db), nil } // Implements interface MultiStore