-
Notifications
You must be signed in to change notification settings - Fork 147
/
chain_state_lag.go
48 lines (40 loc) · 998 Bytes
/
chain_state_lag.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
package metrics
import "github.com/iotaledger/wasp/packages/isc"
type ChainStateLag map[isc.ChainID]*chainSyncLagEntry
type chainSyncLagEntry struct {
wantStateIndex uint32
haveStateIndex uint32
}
func (ce chainSyncLagEntry) Lag() uint32 {
return ce.wantStateIndex - ce.haveStateIndex
}
func (c ChainStateLag) Want(chainID isc.ChainID, stateIndex uint32) {
if e, ok := c[chainID]; ok {
e.wantStateIndex = stateIndex
return
}
c[chainID] = &chainSyncLagEntry{wantStateIndex: stateIndex}
}
func (c ChainStateLag) Have(chainID isc.ChainID, stateIndex uint32) {
if e, ok := c[chainID]; ok {
e.haveStateIndex = stateIndex
return
}
c[chainID] = &chainSyncLagEntry{haveStateIndex: stateIndex}
}
func (c ChainStateLag) ChainLag(chainID isc.ChainID) uint32 {
if e, ok := c[chainID]; ok {
return e.Lag()
}
return 0
}
func (c ChainStateLag) MaxLag() uint32 {
maxLag := uint32(0)
for _, e := range c {
lag := e.Lag()
if maxLag < lag {
maxLag = lag
}
}
return maxLag
}