MCPcopy
hub / github.com/canopy-network/canopy / UpdateValidator

Method UpdateValidator

lib/metrics.go:560–627  ·  view source on GitHub ↗

UpdateValidator() updates the validator metrics for prometheus

(address string, stakeAmount uint64, unstaking, paused, delegate, compounding, isProducer bool,
	nonSigners map[string]uint64, doubleSigners []crypto.AddressI)

Source from the content-addressed store, hash-verified

558
559// UpdateValidator() updates the validator metrics for prometheus
560func (m *Metrics) UpdateValidator(address string, stakeAmount uint64, unstaking, paused, delegate, compounding, isProducer bool,
561 nonSigners map[string]uint64, doubleSigners []crypto.AddressI) {
562 // exit if empty
563 if m == nil {
564 return
565 }
566 // update the auto-compounding metric
567 if compounding {
568 m.ValidatorCompounding.WithLabelValues(address).Set(float64(1))
569 } else {
570 m.ValidatorCompounding.WithLabelValues(address).Set(float64(0))
571 }
572 // update the validator stake amount
573 m.ValidatorStakeAmount.WithLabelValues(address).Set(float64(stakeAmount))
574 // update the delegate metric
575 if delegate {
576 m.ValidatorType.WithLabelValues(address).Set(float64(0))
577 } else {
578 m.ValidatorType.WithLabelValues(address).Set(float64(1))
579 }
580 // update block producer
581 if isProducer {
582 m.ValidatorBlockProducer.WithLabelValues(address).Set(float64(1))
583 } else {
584 m.ValidatorBlockProducer.WithLabelValues(address).Set(float64(0))
585 }
586 var isNonSigner bool
587 // update non signer
588 for nonSignerAddress := range nonSigners {
589 if address == nonSignerAddress {
590 isNonSigner = true
591 }
592 }
593 m.ValidatorNonSignerCount.WithLabelValues("any").Set(float64(len(nonSigners)))
594 if isNonSigner {
595 m.ValidatorNonSigner.WithLabelValues(address).Set(float64(1))
596 } else {
597 m.ValidatorNonSigner.WithLabelValues(address).Set(float64(0))
598 }
599 var isDoubleSigner bool
600 // update double signer
601 for _, doubleSigner := range doubleSigners {
602 if doubleSigner.String() == address {
603 isDoubleSigner = true
604 }
605 }
606 m.ValidatorDoubleSignerCount.WithLabelValues("any").Set(float64(len(doubleSigners)))
607 if isDoubleSigner {
608 m.ValidatorDoubleSigner.WithLabelValues(address).Set(float64(1))
609 } else {
610 m.ValidatorDoubleSigner.WithLabelValues(address).Set(float64(0))
611 }
612 // update the status metric
613 switch {
614 case unstaking:
615 // if the val is unstaking
616 m.ValidatorStatus.WithLabelValues(address).Set(2)
617 case paused:

Callers 1

UpdateTelemetryMethod · 0.80

Calls 2

SetMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected