core/state: lazy sorting, snapshot invalidation

This commit is contained in:
Martin Holst Swende
2019-10-04 15:24:01 +02:00
committed by Péter Szilágyi
parent 542df8898e
commit e146fbe4e7
8 changed files with 671 additions and 92 deletions

View File

@ -204,13 +204,13 @@ func (s *stateObject) GetCommittedState(db Database, key common.Hash) common.Has
if metrics.EnabledExpensive {
defer func(start time.Time) { s.db.SnapshotStorageReads += time.Since(start) }(time.Now())
}
enc = s.db.snap.Storage(s.addrHash, crypto.Keccak256Hash(key[:]))
} else {
// Track the amount of time wasted on reading the storage trie
enc, err = s.db.snap.Storage(s.addrHash, crypto.Keccak256Hash(key[:]))
}
// If snapshot unavailable or reading from it failed, load from the database
if s.db.snap == nil || err != nil {
if metrics.EnabledExpensive {
defer func(start time.Time) { s.db.StorageReads += time.Since(start) }(time.Now())
}
// Otherwise load the value from the database
if enc, err = s.getTrie(db).TryGet(key[:]); err != nil {
s.setError(err)
return common.Hash{}