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 1 commit
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
32 changes: 21 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,27 @@ 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,
alloc: ds.alloc.Fork().Reset(),

// copy the cache so it's not shared with the parent store.
cacheObjects: make(map[ObjectID]Object), // new cache.
cacheTypes: ds.cacheTypes,
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.
cacheTypes: maps.Clone(ds.cacheTypes),
cacheNodes: maps.Clone(ds.cacheNodes),
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