Skip to content

Commit

Permalink
fix(gnovm/store): copy store caches (gnolang#2105)
Browse files Browse the repository at this point in the history
Hotfix for the failing CI on master. Changes `cacheTypes`, `cacheNodes`
and `cacheNativeTypes` to be copies when forking the store, so that the
forked store doesn't modify its parent.

cc @zivkovicmilos
  • Loading branch information
thehowl authored and jefft0 committed May 15, 2024
1 parent 3f05f1e commit 5326d0b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
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

0 comments on commit 5326d0b

Please sign in to comment.