mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
core/state: lazily init snapshot storage map
This commit is contained in:
parent
dd88bd82c9
commit
cf82fca583
1 changed files with 9 additions and 10 deletions
|
|
@ -303,16 +303,8 @@ func (s *stateObject) updateTrie(db Database) Trie {
|
||||||
if metrics.EnabledExpensive {
|
if metrics.EnabledExpensive {
|
||||||
defer func(start time.Time) { s.db.StorageUpdates += time.Since(start) }(time.Now())
|
defer func(start time.Time) { s.db.StorageUpdates += time.Since(start) }(time.Now())
|
||||||
}
|
}
|
||||||
// Retrieve the snapshot storage map for the object
|
// The snapshot storage map for the object
|
||||||
var storage map[common.Hash][]byte
|
var storage map[common.Hash][]byte
|
||||||
if s.db.snap != nil {
|
|
||||||
// Retrieve the old storage map, if available, create a new one otherwise
|
|
||||||
storage = s.db.snapStorage[s.addrHash]
|
|
||||||
if storage == nil {
|
|
||||||
storage = make(map[common.Hash][]byte)
|
|
||||||
s.db.snapStorage[s.addrHash] = storage
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Insert all the pending updates into the trie
|
// Insert all the pending updates into the trie
|
||||||
tr := s.getTrie(db)
|
tr := s.getTrie(db)
|
||||||
for key, value := range s.pendingStorage {
|
for key, value := range s.pendingStorage {
|
||||||
|
|
@ -331,7 +323,14 @@ func (s *stateObject) updateTrie(db Database) Trie {
|
||||||
s.setError(tr.TryUpdate(key[:], v))
|
s.setError(tr.TryUpdate(key[:], v))
|
||||||
}
|
}
|
||||||
// If state snapshotting is active, cache the data til commit
|
// If state snapshotting is active, cache the data til commit
|
||||||
if storage != nil {
|
if s.db.snap != nil {
|
||||||
|
if storage == nil {
|
||||||
|
// Retrieve the old storage map, if available, create a new one otherwise
|
||||||
|
if storage = s.db.snapStorage[s.addrHash]; storage == nil {
|
||||||
|
storage = make(map[common.Hash][]byte)
|
||||||
|
s.db.snapStorage[s.addrHash] = storage
|
||||||
|
}
|
||||||
|
}
|
||||||
storage[crypto.Keccak256Hash(key[:])] = v // v will be nil if value is 0x00
|
storage[crypto.Keccak256Hash(key[:])] = v // v will be nil if value is 0x00
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue