-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[R4R]add sharedStorage for prefetching to L1 (#792)
* add sharedStorage for prefetching to L1 * remote originStorage in stateObjects * fix core * fix bug of sync map * remove read lock when get & set keys * statedb copy use CopyWithSharedStorage * reduce lock access * fix comment * avoid sharedPool effects on other modules * remove tryPreload * fix comment * fix var name * fix lint * fix L1 miss data && data condition * fix comment
- Loading branch information
Showing
6 changed files
with
108 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package state | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
) | ||
|
||
// sharedPool is used to store maps of originStorage of stateObjects | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters