Skip to content

Commit

Permalink
ConnectedStakeWeight%, not CachedSigWeight%
Browse files Browse the repository at this point in the history
  • Loading branch information
feuGeneA committed Aug 21, 2024
1 parent c4ee2df commit 22eabca
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 36 deletions.
14 changes: 8 additions & 6 deletions signature-aggregator/aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ func (s *SignatureAggregator) CreateSignedMessage(
s.metrics.FailuresToGetValidatorSet.Inc()
return nil, fmt.Errorf("%s: %w", msg, err)
}
s.metrics.ConnectedStakeWeightPercentage.WithLabelValues(
signingSubnet.String(),
).Set(
float64(
connectedValidators.ConnectedWeight /
connectedValidators.TotalValidatorWeight,
),
)

if !utils.CheckStakeWeightPercentageExceedsThreshold(
big.NewInt(0).SetUint64(connectedValidators.ConnectedWeight),
Expand Down Expand Up @@ -152,12 +160,6 @@ func (s *SignatureAggregator) CreateSignedMessage(
}
}
s.metrics.SignatureCacheHits.Add(float64(len(signatureMap)))
s.metrics.CachedSignatureWeightPercentage.Set(
float64(utils.GetStakeWeightPercentage(
accumulatedSignatureWeight,
connectedValidators.TotalValidatorWeight,
)),
)
}
if signedMsg, err := s.aggregateIfSufficientWeight(
unsignedMessage,
Expand Down
17 changes: 9 additions & 8 deletions signature-aggregator/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var Opts = struct {
InvalidSignatureResponses prometheus.CounterOpts
SignatureCacheHits prometheus.CounterOpts
SignatureCacheMisses prometheus.CounterOpts
CachedSignatureWeightPercentage prometheus.GaugeOpts
ConnectedStakeWeightPercentage prometheus.GaugeOpts
}{
AggregateSignaturesLatencyMS: prometheus.GaugeOpts{
Name: "agg_sigs_latency_ms",
Expand Down Expand Up @@ -73,9 +73,9 @@ var Opts = struct {
Name: "signature_cache_misses",
Help: "Number of signatures that were not found in the cache",
},
CachedSignatureWeightPercentage: prometheus.GaugeOpts{
Name: "cached_signature_weight_percentage",
Help: "The percentage of stake weight represented by the cached signatures for a given warp message ID",
ConnectedStakeWeightPercentage: prometheus.GaugeOpts{
Name: "connected_stake_weight_percentage",
Help: "The percentage of connected stake weight for a specific subnet",
},
}

Expand All @@ -90,7 +90,7 @@ type SignatureAggregatorMetrics struct {
InvalidSignatureResponses prometheus.Counter
SignatureCacheHits prometheus.Counter
SignatureCacheMisses prometheus.Counter
CachedSignatureWeightPercentage prometheus.Gauge
ConnectedStakeWeightPercentage *prometheus.GaugeVec

// TODO: consider other failures to monitor. Issue #384 requires
// "network failures", but we probably don't handle those directly.
Expand Down Expand Up @@ -135,8 +135,9 @@ func NewSignatureAggregatorMetrics(
SignatureCacheMisses: prometheus.NewCounter(
Opts.SignatureCacheMisses,
),
CachedSignatureWeightPercentage: prometheus.NewGauge(
Opts.CachedSignatureWeightPercentage,
ConnectedStakeWeightPercentage: prometheus.NewGaugeVec(
Opts.ConnectedStakeWeightPercentage,
[]string{"subnetID"},
),
}

Expand All @@ -150,7 +151,7 @@ func NewSignatureAggregatorMetrics(
registerer.MustRegister(m.InvalidSignatureResponses)
registerer.MustRegister(m.SignatureCacheHits)
registerer.MustRegister(m.SignatureCacheMisses)
registerer.MustRegister(m.CachedSignatureWeightPercentage)
registerer.MustRegister(m.ConnectedStakeWeightPercentage)

return &m
}
Expand Down
19 changes: 13 additions & 6 deletions tests/signature_aggregator_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,15 @@ func SignatureAggregatorAPI(network interfaces.LocalNetwork) {
{metrics.Opts.InvalidSignatureResponses.Name, "==", 0},
{metrics.Opts.SignatureCacheHits.Name, "==", 0},
{metrics.Opts.SignatureCacheMisses.Name, "==", 0},
{metrics.Opts.CachedSignatureWeightPercentage.Name, "==", 0},
{
fmt.Sprintf(
"%s{subnetID=\"%s\"}",
metrics.Opts.ConnectedStakeWeightPercentage.Name,
subnetAInfo.SubnetID.String(),
),
"==",
1,
},
} {
Expect(metricsSample[m.name]).Should(
BeNumerically(m.op, m.value),
Expand All @@ -158,9 +166,6 @@ func SignatureAggregatorAPI(network interfaces.LocalNetwork) {
Expect(
metricsSample2[metrics.Opts.SignatureCacheMisses.Name],
).Should(Equal(metricsSample[metrics.Opts.SignatureCacheMisses.Name]))
Expect(
metricsSample2[metrics.Opts.CachedSignatureWeightPercentage.Name],
).Should(BeNumerically("==", 75))
}

// returns a map of metric names to metric samples
Expand Down Expand Up @@ -189,7 +194,7 @@ func sampleMetrics(port uint16) map[string]uint64 {
metrics.Opts.InvalidSignatureResponses.Name,
metrics.Opts.SignatureCacheHits.Name,
metrics.Opts.SignatureCacheMisses.Name,
metrics.Opts.CachedSignatureWeightPercentage.Name,
metrics.Opts.ConnectedStakeWeightPercentage.Name,
} {
if strings.HasPrefix(
line,
Expand All @@ -198,7 +203,9 @@ func sampleMetrics(port uint16) map[string]uint64 {
log.Debug("Found metric line", "line", line)
parts := strings.Fields(line)

// Fetch the metric count from the last field of the line
metricName = strings.Replace(parts[0], "U__signature_2d_aggregator_", "", 1)

// Parse the metric count from the last field of the line
value, err := strconv.ParseUint(parts[len(parts)-1], 10, 64)
if err != nil {
log.Warn("failed to parse value from metric line")
Expand Down
16 changes: 0 additions & 16 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,6 @@ func CheckStakeWeightExceedsThreshold(
return scaledTotalWeight.Cmp(scaledSigWeight) != 1
}

func GetStakeWeightPercentage(
proportionalWeight *big.Int,
totalWeight uint64,
) uint64 {
totalWeightBI := new(big.Int).SetUint64(totalWeight)
scaledProportionalWeight := new(big.Int).Mul(
proportionalWeight,
new(big.Int).SetUint64(100),
)
percentage := scaledProportionalWeight.Div(
scaledProportionalWeight,
totalWeightBI,
)
return percentage.Uint64()
}

// Wrapper for CheckStakeWeightExceedThreshold with a quorumDen of 100.
func CheckStakeWeightPercentageExceedsThreshold(
accumulatedSignatureWeight *big.Int,
Expand Down

0 comments on commit 22eabca

Please sign in to comment.