forked from okx/xlayer-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
l1_rollup_info_consumer_statistics.go
69 lines (61 loc) · 2.48 KB
/
l1_rollup_info_consumer_statistics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package synchronizer
import (
"fmt"
"time"
"github.com/0xPolygonHermez/zkevm-node/log"
"github.com/0xPolygonHermez/zkevm-node/synchronizer/metrics"
)
type l1RollupInfoConsumerStatistics struct {
numProcessedRollupInfo uint64
numProcessedRollupInfoForCheckTime uint64
numProcessedBlocks uint64
startTime time.Time
timePreviousProcessingDuration time.Duration
startStepTime time.Time
cfg configConsumer
}
func (l *l1RollupInfoConsumerStatistics) onStart() {
l.startTime = time.Now()
l.startStepTime = time.Time{}
l.numProcessedRollupInfoForCheckTime = 0
}
func (l *l1RollupInfoConsumerStatistics) onStartStep() {
l.startStepTime = time.Now()
}
func (l *l1RollupInfoConsumerStatistics) onReset() {
l.numProcessedRollupInfoForCheckTime = 0
l.startStepTime = time.Time{}
}
func (l *l1RollupInfoConsumerStatistics) onStartProcessIncommingRollupInfoData(rollupInfo rollupInfoByBlockRangeResult) string {
now := time.Now()
// Time have have been blocked in the select statement
waitingTimeForData := now.Sub(l.startStepTime)
blocksPerSecond := float64(l.numProcessedBlocks) / time.Since(l.startTime).Seconds()
generatedWarning := false
if l.numProcessedRollupInfoForCheckTime > uint64(l.cfg.ApplyAfterNumRollupReceived) && waitingTimeForData > l.cfg.AceptableInacctivityTime {
msg := fmt.Sprintf("wasted waiting for new rollupInfo from L1: %s last_process: %s new range: %s block_per_second: %f",
waitingTimeForData, l.timePreviousProcessingDuration, rollupInfo.blockRange.String(), blocksPerSecond)
log.Warnf("consumer:: Too much wasted time (waiting to receive a new data):%s", msg)
generatedWarning = true
}
l.numProcessedRollupInfo++
l.numProcessedRollupInfoForCheckTime++
msg := fmt.Sprintf("wasted_time_waiting_for_data [%s] last_process_time [%s] block_per_second [%f]",
waitingTimeForData.Round(time.Second).String(),
l.timePreviousProcessingDuration,
blocksPerSecond)
if waitingTimeForData > l.cfg.AceptableInacctivityTime {
msg = msg + " WASTED_TIME_EXCEED "
}
if generatedWarning {
msg = msg + " WARNING_WASTED_TIME "
}
return msg
}
func (l *l1RollupInfoConsumerStatistics) onFinishProcessIncommingRollupInfoData(rollupInfo rollupInfoByBlockRangeResult, executionTime time.Duration, err error) {
l.timePreviousProcessingDuration = executionTime
if err == nil {
l.numProcessedBlocks += uint64(len(rollupInfo.blocks))
metrics.ProcessL1DataTime(executionTime)
}
}