diff --git a/core/state/statedb.go b/core/state/statedb.go index 3061cdab62..84d4142034 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -356,7 +356,7 @@ func (s *StateDB) GetBalance(addr common.Address) *big.Int { start := time.Now() stateObject := s.getStateObject(addr) end := time.Now() - s.markMetrics(start, end, false) + s.markMetrics(&start, &end, false) if stateObject != nil { return stateObject.Balance() } @@ -367,7 +367,7 @@ func (s *StateDB) GetNonce(addr common.Address) uint64 { start := time.Now() stateObject := s.getStateObject(addr) end := time.Now() - s.markMetrics(start, end, false) + s.markMetrics(&start, &end, false) if stateObject != nil { return stateObject.Nonce() } @@ -388,7 +388,7 @@ func (s *StateDB) GetCode(addr common.Address) []byte { start := time.Now() stateObject := s.getStateObject(addr) end := time.Now() - s.markMetrics(start, end, false) + s.markMetrics(&start, &end, false) if stateObject != nil { return stateObject.Code(s.db) } @@ -399,7 +399,7 @@ func (s *StateDB) GetCodeSize(addr common.Address) int { start := time.Now() stateObject := s.getStateObject(addr) end := time.Now() - defer s.markMetrics(start, end, false) + defer s.markMetrics(&start, &end, false) if stateObject != nil { return stateObject.CodeSize(s.db) } @@ -410,20 +410,20 @@ func (s *StateDB) GetCodeHash(addr common.Address) common.Hash { start := time.Now() stateObject := s.getStateObject(addr) end := time.Now() - s.markMetrics(start, end, false) + s.markMetrics(&start, &end, false) if stateObject == nil { return common.Hash{} } return common.BytesToHash(stateObject.CodeHash()) } -func (s *StateDB) markMetrics(start time.Time, end time.Time, reachStorage bool) { +func (s *StateDB) markMetrics(start *time.Time, end *time.Time, reachStorage bool) { goid := cachemetrics.Goid() isSyncMainProcess := cachemetrics.IsSyncMainRoutineID(goid) isMinerMainProcess := cachemetrics.IsMinerMainRoutineID(goid) // record metrics of syncing main process if isSyncMainProcess { - totalSyncIOCounter.Inc((end.Sub(start)).Nanoseconds()) + totalSyncIOCounter.Inc((*end).Sub(*start).Nanoseconds()) l1AccountMeter.Mark(1) if reachStorage { l1StorageMeter.Mark(1) @@ -431,7 +431,7 @@ func (s *StateDB) markMetrics(start time.Time, end time.Time, reachStorage bool) } // record metrics of mining main process if isMinerMainProcess { - totalMinerIOCounter.Inc((end.Sub(start)).Nanoseconds()) + totalMinerIOCounter.Inc((*end).Sub(*start).Nanoseconds()) minerL1AccountMeter.Mark(1) if reachStorage { l1StorageMeter.Mark(1) @@ -520,7 +520,7 @@ func (s *StateDB) GetCommittedState(addr common.Address, hash common.Hash) commo start := time.Now() var end time.Time needStorage := false - defer s.markMetrics(start, end, needStorage) + defer s.markMetrics(&start, &end, needStorage) stateObject := s.getStateObject(addr) hit := false end = time.Now() @@ -567,7 +567,7 @@ func (s *StateDB) AddBalance(addr common.Address, amount *big.Int) { start := time.Now() stateObject := s.GetOrNewStateObject(addr) end := time.Now() - s.markMetrics(start, end, false) + s.markMetrics(&start, &end, false) if stateObject != nil { stateObject.AddBalance(amount) } @@ -578,7 +578,7 @@ func (s *StateDB) SubBalance(addr common.Address, amount *big.Int) { start := time.Now() stateObject := s.GetOrNewStateObject(addr) end := time.Now() - s.markMetrics(start, end, false) + s.markMetrics(&start, &end, false) if stateObject != nil { stateObject.SubBalance(amount) } @@ -588,7 +588,7 @@ func (s *StateDB) SetBalance(addr common.Address, amount *big.Int) { start := time.Now() stateObject := s.GetOrNewStateObject(addr) end := time.Now() - s.markMetrics(start, end, false) + s.markMetrics(&start, &end, false) if stateObject != nil { stateObject.SetBalance(amount) } @@ -598,7 +598,7 @@ func (s *StateDB) SetNonce(addr common.Address, nonce uint64) { start := time.Now() stateObject := s.GetOrNewStateObject(addr) end := time.Now() - s.markMetrics(start, end, false) + s.markMetrics(&start, &end, false) if stateObject != nil { stateObject.SetNonce(nonce) } @@ -608,7 +608,7 @@ func (s *StateDB) SetCode(addr common.Address, code []byte) { start := time.Now() stateObject := s.GetOrNewStateObject(addr) end := time.Now() - s.markMetrics(start, end, false) + s.markMetrics(&start, &end, false) if stateObject != nil { stateObject.SetCode(crypto.Keccak256Hash(code), code) } @@ -618,7 +618,7 @@ func (s *StateDB) SetState(addr common.Address, key, value common.Hash) { start := time.Now() markStorage := false var end time.Time - defer s.markMetrics(start, end, markStorage) + defer s.markMetrics(&start, &end, markStorage) stateObject := s.GetOrNewStateObject(addr) end = time.Now() if stateObject != nil { @@ -946,7 +946,7 @@ func (s *StateDB) CreateAccount(addr common.Address) { start := time.Now() newObj, prev := s.createObject(addr) end := time.Now() - s.markMetrics(start, end, false) + s.markMetrics(&start, &end, false) if prev != nil { newObj.setBalance(prev.data.Balance) }