2023-06-14 12:43:34 +00:00
|
|
|
// Copyright 2019 The go-ethereum Authors
|
|
|
|
// This file is part of the go-ethereum library.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package statediff
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2023-06-23 12:42:55 +00:00
|
|
|
"github.com/cerc-io/plugeth-statediff/utils/log"
|
2023-06-14 12:43:34 +00:00
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
|
|
|
)
|
|
|
|
|
2023-06-21 15:49:57 +00:00
|
|
|
func countStateDiffBegin(block *types.Block, logger log.Logger) time.Time {
|
2023-06-14 12:43:34 +00:00
|
|
|
start := time.Now()
|
|
|
|
|
|
|
|
defaultStatediffMetrics.underway.Inc(1)
|
2023-06-20 12:35:31 +00:00
|
|
|
logger.Debug("writeStateDiff BEGIN",
|
|
|
|
"underway", defaultStatediffMetrics.underway.Count(),
|
|
|
|
"succeeded", defaultStatediffMetrics.succeeded.Count(),
|
|
|
|
"failed", defaultStatediffMetrics.failed.Count(),
|
|
|
|
"total_time", defaultStatediffMetrics.totalProcessingTime.Value(),
|
|
|
|
)
|
2023-06-14 12:43:34 +00:00
|
|
|
|
2023-06-21 15:49:57 +00:00
|
|
|
return start
|
2023-06-14 12:43:34 +00:00
|
|
|
}
|
|
|
|
|
2023-06-21 13:32:07 +00:00
|
|
|
func countStateDiffEnd(start time.Time, logger log.Logger, err *error) time.Duration {
|
2023-06-14 12:43:34 +00:00
|
|
|
duration := time.Since(start)
|
|
|
|
defaultStatediffMetrics.underway.Dec(1)
|
2023-06-21 13:32:07 +00:00
|
|
|
failed := nil != err && nil != *err
|
|
|
|
if failed {
|
2023-06-14 12:43:34 +00:00
|
|
|
defaultStatediffMetrics.failed.Inc(1)
|
2023-06-21 13:32:07 +00:00
|
|
|
} else {
|
|
|
|
defaultStatediffMetrics.succeeded.Inc(1)
|
2023-06-14 12:43:34 +00:00
|
|
|
}
|
|
|
|
defaultStatediffMetrics.totalProcessingTime.Inc(duration.Milliseconds())
|
|
|
|
|
2023-06-20 12:35:31 +00:00
|
|
|
logger.Debug("writeStateDiff END",
|
|
|
|
"duration", duration,
|
2023-06-21 13:32:07 +00:00
|
|
|
"error", failed,
|
2023-06-20 12:35:31 +00:00
|
|
|
"underway", defaultStatediffMetrics.underway.Count(),
|
|
|
|
"succeeded", defaultStatediffMetrics.succeeded.Count(),
|
|
|
|
"failed", defaultStatediffMetrics.failed.Count(),
|
|
|
|
"total_time", defaultStatediffMetrics.totalProcessingTime.Value(),
|
|
|
|
)
|
2023-06-14 12:43:34 +00:00
|
|
|
|
|
|
|
return duration
|
|
|
|
}
|
|
|
|
|
|
|
|
func countApiRequestBegin(methodName string, blockHashOrNumber interface{}) (time.Time, log.Logger) {
|
|
|
|
start := time.Now()
|
|
|
|
logger := log.New(methodName, blockHashOrNumber)
|
|
|
|
|
|
|
|
defaultStatediffMetrics.apiRequests.Inc(1)
|
|
|
|
defaultStatediffMetrics.apiRequestsUnderway.Inc(1)
|
|
|
|
|
2023-06-20 12:35:31 +00:00
|
|
|
logger.Debug("statediff API BEGIN",
|
|
|
|
"underway", defaultStatediffMetrics.apiRequestsUnderway.Count(),
|
|
|
|
"requests", defaultStatediffMetrics.apiRequests.Count(),
|
|
|
|
)
|
2023-06-14 12:43:34 +00:00
|
|
|
|
|
|
|
return start, logger
|
|
|
|
}
|
|
|
|
|
|
|
|
func countApiRequestEnd(start time.Time, logger log.Logger, err error) time.Duration {
|
|
|
|
duration := time.Since(start)
|
|
|
|
defaultStatediffMetrics.apiRequestsUnderway.Dec(1)
|
|
|
|
|
2023-06-20 12:35:31 +00:00
|
|
|
logger.Debug("statediff API END",
|
|
|
|
"duration", duration,
|
|
|
|
"error", err != nil,
|
|
|
|
"underway", defaultStatediffMetrics.apiRequestsUnderway.Count(),
|
|
|
|
"requests", defaultStatediffMetrics.apiRequests.Count(),
|
|
|
|
)
|
2023-06-14 12:43:34 +00:00
|
|
|
|
|
|
|
return duration
|
|
|
|
}
|