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

fix(gnovm/store): copy store caches #2105

Merged
merged 3 commits into from
May 14, 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
37 changes: 26 additions & 11 deletions gnovm/pkg/gnolang/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gnolang

import (
"fmt"
"maps"
"reflect"
"slices"
"strconv"
Expand Down Expand Up @@ -619,18 +620,32 @@ func (ds *defaultStore) ClearObjectCache() {
// This function is used to handle queries and checktx transactions.
func (ds *defaultStore) Fork() Store {
ds2 := &defaultStore{
alloc: ds.alloc.Fork().Reset(),
pkgGetter: ds.pkgGetter,
cacheObjects: make(map[ObjectID]Object), // new cache.
cacheTypes: ds.cacheTypes,
alloc: ds.alloc.Fork().Reset(),

// Re-initialize caches. Some are cloned for speed.
cacheObjects: make(map[ObjectID]Object),
cacheTypes: maps.Clone(ds.cacheTypes),
// XXX: This is bad to say the least (ds.cacheNodes is shared with a
// child Store); however, cacheNodes is _not_ a cache, but a proper
// data store instead. SetBlockNode does not write anything to
// the underlying baseStore, and cloning this map makes everything run
// 4x slower, so here we are, copying the reference.
cacheNodes: ds.cacheNodes,
cacheNativeTypes: ds.cacheNativeTypes,
baseStore: ds.baseStore,
iavlStore: ds.iavlStore,
pkgInjector: ds.pkgInjector,
nativeStore: ds.nativeStore,
go2gnoStrict: ds.go2gnoStrict,
opslog: nil, // new ops log.
cacheNativeTypes: maps.Clone(ds.cacheNativeTypes),

// baseStore and iavlStore should generally be changed using SwapStores.
baseStore: ds.baseStore,
iavlStore: ds.iavlStore,

// native injections / store "config"
pkgGetter: ds.pkgGetter,
pkgInjector: ds.pkgInjector,
nativeStore: ds.nativeStore,
go2gnoStrict: ds.go2gnoStrict,

// reset opslog and current.
opslog: nil,
current: nil,
}
ds2.SetCachePackage(Uverse())
return ds2
Expand Down
Loading