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

Add CacheMultiStoreForExport to support wasm snapshot export #523

Merged
merged 2 commits into from
Jul 16, 2024
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
4 changes: 4 additions & 0 deletions server/mock/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
panic("not implemented")
}

func (ms multiStore) CacheMultiStoreForExport(version int64) (store.CacheMultiStore, error) {
panic("not implemented")

Check warning on line 33 in server/mock/store.go

View check run for this annotation

Codecov / codecov/patch

server/mock/store.go#L32-L33

Added lines #L32 - L33 were not covered by tests
}

func (ms multiStore) CacheWrap(_ store.StoreKey) sdk.CacheWrap {
panic("not implemented")
}
Expand Down
16 changes: 16 additions & 0 deletions store/cachemulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
traceContext types.TraceContext

listeners map[types.StoreKey][]types.WriteListener
closers []io.Closer
}

var _ types.CacheMultiStore = Store{}
Expand All @@ -52,6 +53,7 @@
traceWriter: traceWriter,
traceContext: traceContext,
listeners: listeners,
closers: []io.Closer{},

Check warning on line 56 in store/cachemulti/store.go

View check run for this annotation

Codecov / codecov/patch

store/cachemulti/store.go#L56

Added line #L56 was not covered by tests
}

for key, store := range stores {
Expand Down Expand Up @@ -225,3 +227,17 @@
}
return cms
}

func (cms Store) CacheMultiStoreForExport(_ int64) (types.CacheMultiStore, error) {
panic("Not implemented")

Check warning on line 232 in store/cachemulti/store.go

View check run for this annotation

Codecov / codecov/patch

store/cachemulti/store.go#L231-L232

Added lines #L231 - L232 were not covered by tests
}

func (cms Store) AddCloser(closer io.Closer) {
cms.closers = append(cms.closers, closer)

Check warning on line 236 in store/cachemulti/store.go

View check run for this annotation

Codecov / codecov/patch

store/cachemulti/store.go#L235-L236

Added lines #L235 - L236 were not covered by tests
}

func (cms Store) Close() {
for _, closer := range cms.closers {
closer.Close()
}

Check warning on line 242 in store/cachemulti/store.go

View check run for this annotation

Codecov / codecov/patch

store/cachemulti/store.go#L239-L242

Added lines #L239 - L242 were not covered by tests
}
4 changes: 4 additions & 0 deletions store/rootmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,10 @@
return cachemulti.NewStore(rs.db, cachedStores, rs.keysByName, rs.traceWriter, rs.getTracingContext(), rs.listeners), nil
}

func (rs *Store) CacheMultiStoreForExport(version int64) (types.CacheMultiStore, error) {
return rs.CacheMultiStoreWithVersion(version)

Check warning on line 591 in store/rootmulti/store.go

View check run for this annotation

Codecov / codecov/patch

store/rootmulti/store.go#L590-L591

Added lines #L590 - L591 were not covered by tests
}

// GetStore returns a mounted Store for a given StoreKey. If the StoreKey does
// not exist, it will panic. If the Store is wrapped in an inter-block cache, it
// will be unwrapped prior to being returned.
Expand Down
5 changes: 5 additions & 0 deletions store/types/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ type MultiStore interface {
// each stored is loaded at a specific version (height).
CacheMultiStoreWithVersion(version int64) (CacheMultiStore, error)

// CacheMultiStoreForExport create a cache multistore specifically for state export
CacheMultiStoreForExport(version int64) (CacheMultiStore, error)

// Convenience for fetching substores.
// If the store does not exist, panics.
GetStore(StoreKey) Store
Expand Down Expand Up @@ -159,6 +162,8 @@ type CacheMultiStore interface {

// Writes operations to underlying KVStore
Write()

Close()
}

// CommitMultiStore is an interface for a MultiStore without cache capabilities.
Expand Down
30 changes: 30 additions & 0 deletions storev2/rootmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,36 @@
return cachemulti.NewStore(nil, stores, rs.storeKeys, nil, nil, nil), nil
}

func (rs *Store) CacheMultiStoreForExport(version int64) (types.CacheMultiStore, error) {
if version <= 0 || (rs.lastCommitInfo != nil && version == rs.lastCommitInfo.Version) {
return rs.CacheMultiStore(), nil
}
rs.mtx.RLock()
defer rs.mtx.RUnlock()
stores := make(map[types.StoreKey]types.CacheWrapper)
// add the transient/mem stores registered in current app.
for k, store := range rs.ckvStores {
if store.GetStoreType() != types.StoreTypeIAVL {
stores[k] = store
}

Check warning on line 283 in storev2/rootmulti/store.go

View check run for this annotation

Codecov / codecov/patch

storev2/rootmulti/store.go#L272-L283

Added lines #L272 - L283 were not covered by tests
}
// add SC stores for historical queries
scStore, err := rs.scStore.LoadVersion(version, true)
if err != nil {
return nil, err
}
for k, store := range rs.ckvStores {
if store.GetStoreType() == types.StoreTypeIAVL {
tree := scStore.GetTreeByName(k.Name())
stores[k] = commitment.NewStore(tree, rs.logger)
}

Check warning on line 294 in storev2/rootmulti/store.go

View check run for this annotation

Codecov / codecov/patch

storev2/rootmulti/store.go#L286-L294

Added lines #L286 - L294 were not covered by tests
}
cacheMs := cachemulti.NewStore(nil, stores, rs.storeKeys, nil, nil, nil)
// We need this because we need to make sure sc is closed after being used to release the resources
cacheMs.AddCloser(scStore)
return cacheMs, nil

Check warning on line 299 in storev2/rootmulti/store.go

View check run for this annotation

Codecov / codecov/patch

storev2/rootmulti/store.go#L296-L299

Added lines #L296 - L299 were not covered by tests
}

// GetStore Implements interface MultiStore
func (rs *Store) GetStore(key types.StoreKey) types.Store {
return rs.ckvStores[key]
Expand Down
Loading