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

Problem: memiavl db in CacheMultiStoreWithVersion not closed #1151

Merged
merged 2 commits into from
Sep 4, 2023
Merged
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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*

Expand Down
37 changes: 37 additions & 0 deletions store/cachemulti/store.go
Original file line number Diff line number Diff line change
@@ -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,
}
}
6 changes: 3 additions & 3 deletions store/rootmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down