mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
core/state: prefetch storage trie values even if snapshot is enabled
This commit is contained in:
parent
e61b438900
commit
974aafd4e6
2 changed files with 17 additions and 0 deletions
|
|
@ -74,6 +74,7 @@ type stateObject struct {
|
||||||
originStorage Storage // Storage cache of original entries to dedup rewrites
|
originStorage Storage // Storage cache of original entries to dedup rewrites
|
||||||
pendingStorage Storage // Storage entries that need to be flushed to disk, at the end of an entire block
|
pendingStorage Storage // Storage entries that need to be flushed to disk, at the end of an entire block
|
||||||
dirtyStorage Storage // Storage entries that have been modified in the current transaction execution, reset for every transaction
|
dirtyStorage Storage // Storage entries that have been modified in the current transaction execution, reset for every transaction
|
||||||
|
readStorage []common.Hash
|
||||||
|
|
||||||
// Cache flags.
|
// Cache flags.
|
||||||
dirtyCode bool // true if the code was updated
|
dirtyCode bool // true if the code was updated
|
||||||
|
|
@ -111,6 +112,7 @@ func newObject(db *StateDB, address common.Address, acct *types.StateAccount) *s
|
||||||
originStorage: make(Storage),
|
originStorage: make(Storage),
|
||||||
pendingStorage: make(Storage),
|
pendingStorage: make(Storage),
|
||||||
dirtyStorage: make(Storage),
|
dirtyStorage: make(Storage),
|
||||||
|
readStorage: []common.Hash{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -256,12 +258,23 @@ func (s *stateObject) finalise(prefetch bool) {
|
||||||
slotsToPrefetch = append(slotsToPrefetch, common.CopyBytes(key[:])) // Copy needed for closure
|
slotsToPrefetch = append(slotsToPrefetch, common.CopyBytes(key[:])) // Copy needed for closure
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// prefetch slots that are read so that they will appear in witness
|
||||||
|
for _, value := range s.readStorage {
|
||||||
|
if _, ok := s.dirtyStorage[value]; !ok {
|
||||||
|
slotsToPrefetch = append(slotsToPrefetch, common.CopyBytes(value[:]))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if s.db.prefetcher != nil && prefetch && len(slotsToPrefetch) > 0 && s.data.Root != types.EmptyRootHash {
|
if s.db.prefetcher != nil && prefetch && len(slotsToPrefetch) > 0 && s.data.Root != types.EmptyRootHash {
|
||||||
s.db.prefetcher.prefetch(s.addrHash, s.data.Root, s.address, slotsToPrefetch)
|
s.db.prefetcher.prefetch(s.addrHash, s.data.Root, s.address, slotsToPrefetch)
|
||||||
}
|
}
|
||||||
if len(s.dirtyStorage) > 0 {
|
if len(s.dirtyStorage) > 0 {
|
||||||
s.dirtyStorage = make(Storage)
|
s.dirtyStorage = make(Storage)
|
||||||
}
|
}
|
||||||
|
if len(s.readStorage) > 0 {
|
||||||
|
s.readStorage = []common.Hash{}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// updateTrie is responsible for persisting cached storage changes into the
|
// updateTrie is responsible for persisting cached storage changes into the
|
||||||
|
|
@ -394,6 +407,7 @@ func (s *stateObject) commit() (*trienode.NodeSet, map[string][]byte, error) {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
s.data.Root = root
|
s.data.Root = root
|
||||||
|
fmt.Printf("node count %d\n", len(nodes.Leaves))
|
||||||
|
|
||||||
// Update original account data after commit
|
// Update original account data after commit
|
||||||
s.origin = s.data.Copy()
|
s.origin = s.data.Copy()
|
||||||
|
|
|
||||||
|
|
@ -1232,6 +1232,9 @@ func (s *StateDB) Commit(block uint64, deleteEmptyObjects bool) (common.Hash, er
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return common.Hash{}, err
|
return common.Hash{}, err
|
||||||
}
|
}
|
||||||
|
if set != nil {
|
||||||
|
fmt.Printf("leaf count: %d\n", len(set.Leaves))
|
||||||
|
}
|
||||||
// Merge the dirty nodes of account trie into global set
|
// Merge the dirty nodes of account trie into global set
|
||||||
if set != nil {
|
if set != nil {
|
||||||
if err := nodes.Merge(set); err != nil {
|
if err := nodes.Merge(set); err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue