mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
core/state: fix flawed meter on storage reads
This commit is contained in:
parent
cf82fca583
commit
31e89911b1
1 changed files with 22 additions and 4 deletions
|
|
@ -197,12 +197,24 @@ func (s *stateObject) GetCommittedState(db Database, key common.Hash) common.Has
|
|||
}
|
||||
// If no live objects are available, attempt to use snapshots
|
||||
var (
|
||||
enc []byte
|
||||
err error
|
||||
enc []byte
|
||||
err error
|
||||
meter *time.Duration
|
||||
)
|
||||
readStart := time.Now()
|
||||
if metrics.EnabledExpensive {
|
||||
// If the snap is 'under construction', the first lookup may fail. If that
|
||||
// happens, we don't want to double-count the time elapsed. Thus this
|
||||
// dance with the metering.
|
||||
defer func() {
|
||||
if meter != nil {
|
||||
*meter += time.Since(readStart)
|
||||
}
|
||||
}()
|
||||
}
|
||||
if s.db.snap != nil {
|
||||
if metrics.EnabledExpensive {
|
||||
defer func(start time.Time) { s.db.SnapshotStorageReads += time.Since(start) }(time.Now())
|
||||
meter = &s.db.SnapshotStorageReads
|
||||
}
|
||||
// If the object was destructed in *this* block (and potentially resurrected),
|
||||
// the storage has been cleared out, and we should *not* consult the previous
|
||||
|
|
@ -217,8 +229,14 @@ func (s *stateObject) GetCommittedState(db Database, key common.Hash) common.Has
|
|||
}
|
||||
// If snapshot unavailable or reading from it failed, load from the database
|
||||
if s.db.snap == nil || err != nil {
|
||||
if meter != nil {
|
||||
// If we already spent time checking the snapshot, account for it
|
||||
// and reset the readStart
|
||||
*meter += time.Since(readStart)
|
||||
readStart = time.Now()
|
||||
}
|
||||
if metrics.EnabledExpensive {
|
||||
defer func(start time.Time) { s.db.StorageReads += time.Since(start) }(time.Now())
|
||||
meter = &s.db.StorageReads
|
||||
}
|
||||
if enc, err = s.getTrie(db).TryGet(key[:]); err != nil {
|
||||
s.setError(err)
|
||||
|
|
|
|||
Loading…
Reference in a new issue