92
92
Name : "gossip_vaas_unique_total" ,
93
93
Help : "The unique number of vaas received over gossip" ,
94
94
})
95
+ uniqueVAAsByGuardianPerChain = promauto .NewCounterVec (prometheus.CounterOpts {
96
+ Name : "gossip_vaas_by_guardian_per_chain_total" ,
97
+ Help : "The number of unique VAAs received over gossip, grouped by guardian and chain" ,
98
+ }, []string {"guardian_name" , "chain_name" })
95
99
heartbeatsByGuardian = promauto .NewCounterVec (prometheus.CounterOpts {
96
100
Name : "gossip_heartbeats_by_guardian_total" ,
97
101
Help : "The number of heartbeats received over gossip by guardian" ,
@@ -293,7 +297,6 @@ func main() {
293
297
294
298
// Count signed VAAs
295
299
go func () {
296
- // TODO: move this to a function / struct with a mutex so that the cleanup can be run independently from the message handling, so as to not back up the channel
297
300
uniqueVAAs := make (map [string ]time.Time )
298
301
timeout := time .Hour
299
302
delay := time .Minute * 10
@@ -314,18 +317,34 @@ func main() {
314
317
logger .Info ("Cleaned up unique VAAs cache" , zap .Int ("beforeCount" , beforeCount ), zap .Int ("afterCount" , afterCount ), zap .Int ("cleanedUpCount" , beforeCount - afterCount ))
315
318
timer .Reset (delay )
316
319
case m := <- signedInC :
317
- // This only has VAABytes. It doesn't have the guardian address
318
320
gossipByType .WithLabelValues ("vaa" ).Inc ()
319
321
v , err := vaa .Unmarshal (m .Vaa )
320
322
if err != nil {
321
323
logger .Warn ("received invalid VAA in SignedVAAWithQuorum message" , zap .Error (err ), zap .Any ("message" , m ))
322
- } else {
323
- digest := v .HexDigest ()
324
- if _ , exists := uniqueVAAs [digest ]; exists {
325
- uniqueVAAsCounter .Inc ()
324
+ continue
325
+ }
326
+
327
+ digest := v .HexDigest ()
328
+ chain := v .EmitterChain .String () // Extract chain name
329
+
330
+ // Extract guardian name using signature index
331
+ guardianName := "unknown"
332
+ for _ , sig := range v .Signatures {
333
+ guardianIndex := int (sig .Index ) // Extract the guardian index
334
+ if name , found := guardianIndexToNameMap [guardianIndex ]; found {
335
+ guardianName = name
336
+ break // Take the first matched guardian
326
337
}
327
- uniqueVAAs [digest ] = time .Now ()
328
338
}
339
+
340
+ if _ , exists := uniqueVAAs [digest ]; ! exists {
341
+ // Increment the original gossip_vaas_unique_total metric
342
+ uniqueVAAsCounter .Inc ()
343
+
344
+ // Increment the new metric with guardian and chain labels
345
+ uniqueVAAsByGuardianPerChain .WithLabelValues (guardianName , chain ).Inc ()
346
+ }
347
+ uniqueVAAs [digest ] = time .Now ()
329
348
}
330
349
}
331
350
}()
0 commit comments