@@ -23,6 +23,7 @@ import {
23
23
Typography ,
24
24
} from '@mui/material' ;
25
25
import { useMemo } from 'react' ;
26
+ import { Environment , useCurrentEnvironment } from '../contexts/NetworkContext' ;
26
27
import { ChainIdToHeartbeats } from '../hooks/useChainHeartbeats' ;
27
28
import useLatestRelease from '../hooks/useLatestRelease' ;
28
29
import chainIdToName from '../utils/chainIdToName' ;
@@ -36,8 +37,16 @@ const isLayer2 = (chainId: number) =>
36
37
export const getBehindDiffForChain = ( chainId : number ) =>
37
38
isLayer2 ( chainId ) ? BEHIND_DIFF * 2 : BEHIND_DIFF ;
38
39
39
- export const QUORUM_COUNT = Math . floor ( ( GUARDIAN_SET_3 . length * 2 ) / 3 + 1 ) ;
40
- export const QUORUM_LOSS_COUNT = GUARDIAN_SET_3 . length - QUORUM_COUNT + 1 ;
40
+ export const getNumGuardians = ( environment : Environment ) =>
41
+ environment === 'mainnet' ? GUARDIAN_SET_3 . length : 1 ;
42
+
43
+ export function getQuorumCount ( environment : Environment ) : number {
44
+ return Math . floor ( ( getNumGuardians ( environment ) * 2 ) / 3 + 1 ) ;
45
+ }
46
+
47
+ function getQuorumLossCount ( environment : Environment ) : number {
48
+ return getNumGuardians ( environment ) - getQuorumCount ( environment ) + 1 ;
49
+ }
41
50
42
51
type AlertEntry = {
43
52
severity : AlertColor ;
@@ -48,7 +57,8 @@ const alertSeverityOrder: AlertColor[] = ['error', 'warning', 'success', 'info']
48
57
49
58
function chainDownAlerts (
50
59
heartbeats : Heartbeat [ ] ,
51
- chainIdsToHeartbeats : ChainIdToHeartbeats
60
+ chainIdsToHeartbeats : ChainIdToHeartbeats ,
61
+ environment : Environment
52
62
) : AlertEntry [ ] {
53
63
const downChains : { [ chainId : string ] : string [ ] } = { } ;
54
64
Object . entries ( chainIdsToHeartbeats )
@@ -99,7 +109,7 @@ function chainDownAlerts(
99
109
} ) ;
100
110
} ) ;
101
111
return Object . entries ( downChains ) . map ( ( [ chainId , names ] ) => ( {
102
- severity : names . length >= QUORUM_LOSS_COUNT ? 'error' : 'warning' ,
112
+ severity : names . length >= getQuorumLossCount ( environment ) ? 'error' : 'warning' ,
103
113
text : `${ names . length } guardian${ names . length > 1 ? 's' : '' } [${ names . join ( ', ' ) } ] ${
104
114
names . length > 1 ? 'are' : 'is'
105
115
} down on ${ chainIdToName ( Number ( chainId ) ) } (${ chainId } )!`,
@@ -124,9 +134,10 @@ function Alerts({
124
134
chainIdsToHeartbeats : ChainIdToHeartbeats ;
125
135
} ) {
126
136
const latestRelease = useLatestRelease ( ) ;
137
+ const environment = useCurrentEnvironment ( ) ;
127
138
const alerts = useMemo ( ( ) => {
128
139
const alerts : AlertEntry [ ] = [
129
- ...chainDownAlerts ( heartbeats , chainIdsToHeartbeats ) ,
140
+ ...chainDownAlerts ( heartbeats , chainIdsToHeartbeats , environment ) ,
130
141
...releaseChecker ( latestRelease , heartbeats ) ,
131
142
] ;
132
143
return alerts . sort ( ( a , b ) =>
@@ -136,7 +147,7 @@ function Alerts({
136
147
? 1
137
148
: 0
138
149
) ;
139
- } , [ latestRelease , heartbeats , chainIdsToHeartbeats ] ) ;
150
+ } , [ latestRelease , heartbeats , chainIdsToHeartbeats , environment ] ) ;
140
151
const numErrors = useMemo (
141
152
( ) => alerts . filter ( ( alert ) => alert . severity === 'error' ) . length ,
142
153
[ alerts ]
0 commit comments