@@ -14,13 +14,14 @@ import (
14
14
gossipv1 "github.com/certusone/wormhole/node/pkg/proto/gossip/v1"
15
15
"github.com/certusone/wormhole/node/pkg/supervisor"
16
16
promremotew "github.com/certusone/wormhole/node/pkg/telemetry/prom_remote_write"
17
- eth_common "github.com/ethereum/go-ethereum/common"
18
17
ipfslog "github.com/ipfs/go-log/v2"
19
18
"github.com/joho/godotenv"
20
19
"github.com/libp2p/go-libp2p/core/crypto"
21
20
"github.com/prometheus/client_golang/prometheus"
22
21
"github.com/prometheus/client_golang/prometheus/promauto"
23
22
"github.com/wormhole-foundation/wormhole-monitor/fly/common"
23
+ "github.com/wormhole-foundation/wormhole-monitor/fly/pkg/db"
24
+ "github.com/wormhole-foundation/wormhole-monitor/fly/pkg/historical_uptime"
24
25
"github.com/wormhole-foundation/wormhole-monitor/fly/utils"
25
26
"github.com/wormhole-foundation/wormhole/sdk/vaa"
26
27
"go.uber.org/zap"
56
57
},
57
58
[]string {"guardian" , "chain" },
58
59
)
60
+
61
+ guardianMissedObservations = promauto .NewCounterVec (
62
+ prometheus.CounterOpts {
63
+ Name : "guardian_missed_observations_total" ,
64
+ Help : "Total number of observations missed by each guardian on each chain" ,
65
+ },
66
+ []string {"guardian" , "chain" },
67
+ )
59
68
)
60
69
61
70
const PYTHNET_CHAIN_ID = int (vaa .ChainIDPythNet )
@@ -120,6 +129,7 @@ func initPromScraper(promRemoteURL string, logger *zap.Logger) {
120
129
// adding this will make sure chain labels are present regardless
121
130
for _ , guardianName := range common .GetGuardianIndexToNameMap () {
122
131
guardianObservations .WithLabelValues (guardianName , chainName ).Add (0 )
132
+ guardianMissedObservations .WithLabelValues (guardianName , chainName ).Add (0 )
123
133
}
124
134
}
125
135
err := promremotew .ScrapeAndSendLocalMetrics (ctx , info , promLogger )
@@ -134,6 +144,37 @@ func initPromScraper(promRemoteURL string, logger *zap.Logger) {
134
144
}
135
145
}
136
146
147
+ func initObservationScraper (db * db.Database , logger * zap.Logger ) {
148
+ node_common .StartRunnable (rootCtx , nil , false , "observation_scraper" , func (ctx context.Context ) error {
149
+ t := time .NewTicker (15 * time .Second )
150
+
151
+ for {
152
+ select {
153
+ case <- ctx .Done ():
154
+ return nil
155
+ case <- t .C :
156
+ messages , err := db .QueryMessagesByIndex (false , common .ExpiryDuration )
157
+ if err != nil {
158
+ logger .Error ("QueryMessagesByIndex error" , zap .Error (err ))
159
+ continue
160
+ }
161
+
162
+ // Tally the number of messages for each chain
163
+ messagesPerChain := historical_uptime .TallyMessagesPerChain (logger , messages )
164
+
165
+ // Initialize the missing observations count for each guardian for each chain
166
+ guardianMissingObservations := historical_uptime .InitializeMissingObservationsCount (logger , messages , messagesPerChain )
167
+
168
+ // Decrement the missing observations count for each observed message
169
+ historical_uptime .DecrementMissingObservationsCount (logger , guardianMissingObservations , messages )
170
+
171
+ // Update the metrics with the final count of missing observations
172
+ historical_uptime .UpdateMetrics (guardianMissedObservations , guardianMissingObservations )
173
+ }
174
+ }
175
+ })
176
+ }
177
+
137
178
func main () {
138
179
loadEnvVars ()
139
180
p2pBootstrap = "/dns4/wormhole-v2-mainnet-bootstrap.xlabs.xyz/udp/8999/quic/p2p/12D3KooWNQ9tVrcb64tw6bNs2CaNrUGPM7yRrKvBBheQ5yCyPHKC,/dns4/wormhole.mcf.rocks/udp/8999/quic/p2p/12D3KooWDZVv7BhZ8yFLkarNdaSWaB43D6UbQwExJ8nnGAEmfHcU,/dns4/wormhole-v2-mainnet-bootstrap.staking.fund/udp/8999/quic/p2p/12D3KooWG8obDX9DNi1KUwZNu9xkGwfKqTp2GFwuuHpWZ3nQruS1"
@@ -180,15 +221,18 @@ func main() {
180
221
if err != nil {
181
222
logger .Fatal ("Failed to fetch guardian set" , zap .Error (err ))
182
223
}
183
- logger . Info ( "guardian set" , zap . Uint32 ( "index" , idx ), zap . Any ( "gs" , sgs ))
224
+
184
225
gs := node_common.GuardianSet {
185
226
Keys : sgs .Keys ,
186
227
Index : idx ,
187
228
}
188
229
gst .Set (& gs )
189
230
231
+ db := db .OpenDb (logger , nil )
232
+
190
233
// Start Prometheus scraper
191
234
initPromScraper (promRemoteURL , logger )
235
+ initObservationScraper (db , logger )
192
236
193
237
// WIP(bing): add metrics for guardian observations
194
238
go func () {
@@ -197,23 +241,7 @@ func main() {
197
241
case <- rootCtx .Done ():
198
242
return
199
243
case o := <- obsvC :
200
- // Ignore observations from pythnnet
201
- // Pythnet sends too many observations that could deteriorate the performance of the fly node
202
- if o .Msg .MessageId [:3 ] != strconv .Itoa (PYTHNET_CHAIN_ID ) + "/" {
203
- ga := eth_common .BytesToAddress (o .Msg .Addr ).String ()
204
- chainID := strings .Split (o .Msg .MessageId , "/" )[0 ]
205
- ui64 , err := strconv .ParseUint (chainID , 10 , 16 )
206
- if err != nil {
207
- panic (err )
208
- }
209
- chainName := vaa .ChainID (ui64 ).String ()
210
- guardianName , ok := common .GetGuardianName (ga )
211
- if ! ok {
212
- logger .Error ("guardian name not found" , zap .String ("guardian" , ga ))
213
- continue // Skip setting the metric if guardianName is not found
214
- }
215
- guardianObservations .WithLabelValues (guardianName , chainName ).Inc ()
216
- }
244
+ historical_uptime .ProcessObservation (* db , logger , * o )
217
245
}
218
246
}
219
247
}()
0 commit comments