core: remove Persist from NativeCache interface
Lower native cache should be assigned to the upper's value during persist.
This commit is contained in:
parent
8ec8511d9d
commit
c8bdd2ad1a
7 changed files with 3 additions and 101 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue