2022-03-28 11:59:41 +08:00
|
|
|
package state
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
)
|
|
|
|
|
2024-03-11 14:51:59 +08:00
|
|
|
// StoragePool is used to store maps of originStorage of stateObjects
|
2022-03-28 11:59:41 +08:00
|
|
|
type StoragePool struct {
|
|
|
|
sync.RWMutex
|
|
|
|
sharedMap map[common.Address]*sync.Map
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewStoragePool() *StoragePool {
|
|
|
|
sharedMap := make(map[common.Address]*sync.Map)
|
|
|
|
return &StoragePool{
|
|
|
|
sync.RWMutex{},
|
|
|
|
sharedMap,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// getStorage Check whether the storage exist in pool,
|
|
|
|
// new one if not exist, the content of storage will be fetched in stateObjects.GetCommittedState()
|
|
|
|
func (s *StoragePool) getStorage(address common.Address) *sync.Map {
|
|
|
|
s.RLock()
|
|
|
|
storageMap, ok := s.sharedMap[address]
|
|
|
|
s.RUnlock()
|
|
|
|
if !ok {
|
|
|
|
s.Lock()
|
|
|
|
defer s.Unlock()
|
|
|
|
if storageMap, ok = s.sharedMap[address]; !ok {
|
|
|
|
m := new(sync.Map)
|
|
|
|
s.sharedMap[address] = m
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return storageMap
|
|
|
|
}
|