From c8bdd2ad1a8f9e5f4c8597c8440caaa15b6fe5e4 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Tue, 19 Apr 2022 12:39:34 +0300 Subject: [PATCH] core: remove Persist from NativeCache interface Lower native cache should be assigned to the upper's value during persist. --- pkg/core/native/designate.go | 13 ------------- pkg/core/native/management.go | 15 --------------- pkg/core/native/native_neo.go | 13 ------------- pkg/core/native/notary.go | 13 ------------- pkg/core/native/oracle.go | 13 ------------- pkg/core/native/policy.go | 14 -------------- pkg/core/storage/memcached_store.go | 23 +++-------------------- 7 files changed, 3 insertions(+), 101 deletions(-) diff --git a/pkg/core/native/designate.go b/pkg/core/native/designate.go index 33cda42c2..7700a4af9 100644 --- a/pkg/core/native/designate.go +++ b/pkg/core/native/designate.go @@ -87,19 +87,6 @@ func (c *DesignationCache) Copy() storage.NativeContractCache { return cp } -// Persist implements NativeContractCache interface. -func (c *DesignationCache) Persist(ps storage.NativeContractCache) (storage.NativeContractCache, error) { - if ps == nil { - ps = &DesignationCache{} - } - psCache, ok := ps.(*DesignationCache) - if !ok { - return nil, errors.New("not a Designation native cache") - } - copyDesignationCache(c, psCache) - return psCache, nil -} - func copyDesignationCache(src, dst *DesignationCache) { *dst = *src } diff --git a/pkg/core/native/management.go b/pkg/core/native/management.go index 00286955b..81b79d7bf 100644 --- a/pkg/core/native/management.go +++ b/pkg/core/native/management.go @@ -84,21 +84,6 @@ func (c *ManagementCache) Copy() storage.NativeContractCache { return cp } -// Persist implements NativeContractCache interface. -func (c *ManagementCache) Persist(ps storage.NativeContractCache) (storage.NativeContractCache, error) { - if ps == nil { - ps = &ManagementCache{} - } - psCache, ok := ps.(*ManagementCache) - if !ok { - return nil, errors.New("not a Management native cache") - } - psCache.contracts = c.contracts - psCache.nep17 = c.nep17 - psCache.nep11 = c.nep11 - return psCache, nil -} - // MakeContractKey creates a key from account script hash. func MakeContractKey(h util.Uint160) []byte { return makeUint160Key(prefixContract, h) diff --git a/pkg/core/native/native_neo.go b/pkg/core/native/native_neo.go index 85ec58fed..3f8128e3b 100644 --- a/pkg/core/native/native_neo.go +++ b/pkg/core/native/native_neo.go @@ -119,19 +119,6 @@ func (c *NeoCache) Copy() storage.NativeContractCache { return cp } -// Persist implements NativeContractCache interface. -func (c *NeoCache) Persist(ps storage.NativeContractCache) (storage.NativeContractCache, error) { - if ps == nil { - ps = &NeoCache{} - } - psCache, ok := ps.(*NeoCache) - if !ok { - return nil, errors.New("not a NEO native cache") - } - copyNeoCache(c, psCache) - return psCache, nil -} - func copyNeoCache(src, dst *NeoCache) { dst.votesChanged = src.votesChanged dst.nextValidators = src.nextValidators.Copy() diff --git a/pkg/core/native/notary.go b/pkg/core/native/notary.go index 325cedce6..c5dc4903e 100644 --- a/pkg/core/native/notary.go +++ b/pkg/core/native/notary.go @@ -68,19 +68,6 @@ func (c *NotaryCache) Copy() storage.NativeContractCache { return cp } -// Persist implements NativeContractCache interface. -func (c *NotaryCache) Persist(ps storage.NativeContractCache) (storage.NativeContractCache, error) { - if ps == nil { - ps = &NotaryCache{} - } - psCache, ok := ps.(*NotaryCache) - if !ok { - return nil, errors.New("not a Notary native cache") - } - copyNotaryCache(c, psCache) - return psCache, nil -} - func copyNotaryCache(src, dst *NotaryCache) { *dst = *src } diff --git a/pkg/core/native/oracle.go b/pkg/core/native/oracle.go index f1914cd65..16903397e 100644 --- a/pkg/core/native/oracle.go +++ b/pkg/core/native/oracle.go @@ -96,19 +96,6 @@ func (c *OracleCache) Copy() storage.NativeContractCache { return cp } -// Persist implements NativeContractCache interface. -func (c *OracleCache) Persist(ps storage.NativeContractCache) (storage.NativeContractCache, error) { - if ps == nil { - ps = &OracleCache{} - } - psCache, ok := ps.(*OracleCache) - if !ok { - return nil, errors.New("not an Oracle native cache") - } - copyOracleCache(c, psCache) - return psCache, nil -} - func copyOracleCache(src, dst *OracleCache) { *dst = *src } diff --git a/pkg/core/native/policy.go b/pkg/core/native/policy.go index 78b64d652..1a886ae67 100644 --- a/pkg/core/native/policy.go +++ b/pkg/core/native/policy.go @@ -1,7 +1,6 @@ package native import ( - "errors" "fmt" "math/big" "sort" @@ -79,19 +78,6 @@ func (c *PolicyCache) Copy() storage.NativeContractCache { return cp } -// Persist implements NativeContractCache interface. -func (c *PolicyCache) Persist(ps storage.NativeContractCache) (storage.NativeContractCache, error) { - if ps == nil { - ps = &PolicyCache{} - } - psCache, ok := ps.(*PolicyCache) - if !ok { - return nil, errors.New("not a Policy native cache") - } - copyPolicyCache(c, psCache) - return psCache, nil -} - func copyPolicyCache(src, dst *PolicyCache) { *dst = *src dst.blockedAccounts = make([]util.Uint160, len(src.blockedAccounts)) diff --git a/pkg/core/storage/memcached_store.go b/pkg/core/storage/memcached_store.go index fcb50a346..42fdccf69 100644 --- a/pkg/core/storage/memcached_store.go +++ b/pkg/core/storage/memcached_store.go @@ -3,7 +3,6 @@ package storage import ( "bytes" "context" - "fmt" "sort" "strings" "sync" @@ -33,9 +32,6 @@ type NativeContractCache interface { // Copy returns a copy of native cache item that can safely be changed within // the subsequent DAO operations. Copy() NativeContractCache - // Persist persists changes from upper native cache wrapper to the underlying - // native cache `ps`. The resulting up-to-date cache and an error are returned. - Persist(ps NativeContractCache) (NativeContractCache, error) } type ( @@ -369,11 +365,7 @@ func (s *MemCachedStore) persist(isSync bool) (int, error) { s.stor = nil if cached, ok := s.ps.(*MemCachedStore); ok { for id, nativeCache := range s.nativeCache { - updatedCache, err := nativeCache.Persist(cached.nativeCache[id]) - if err != nil { - return 0, fmt.Errorf("failed to persist native cache changes for private MemCachedStore: %w", err) - } - cached.nativeCache[id] = updatedCache + cached.nativeCache[id] = nativeCache } s.nativeCache = nil } @@ -411,12 +403,7 @@ func (s *MemCachedStore) persist(isSync bool) (int, error) { if isPSCached { cached.nativeCacheLock.Lock() for id, nativeCache := range tempstore.nativeCache { - updatedCache, err := nativeCache.Persist(cached.nativeCache[id]) - if err != nil { - cached.nativeCacheLock.Unlock() - return 0, fmt.Errorf("failed to persist native cache changes: %w", err) - } - cached.nativeCache[id] = updatedCache + cached.nativeCache[id] = nativeCache } cached.nativeCacheLock.Unlock() } @@ -442,11 +429,7 @@ func (s *MemCachedStore) persist(isSync bool) (int, error) { } if isPSCached { for id, nativeCache := range s.nativeCache { - updatedCache, err := nativeCache.Persist(tempstore.nativeCache[id]) - if err != nil { - return 0, fmt.Errorf("failed to persist native cache changes: %w", err) - } - tempstore.nativeCache[id] = updatedCache + tempstore.nativeCache[id] = nativeCache } s.nativeCache = tempstore.nativeCache }