Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jianoaix committed Apr 17, 2024
1 parent 07c85a0 commit f52d82e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
2 changes: 1 addition & 1 deletion core/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ type Transactor interface {
UpdateOperatorSocket(ctx context.Context, socket string) error

// EjectOperators ejects operators from AVS registryCoordinator.
// The operatorsByQuorum provides the a list of operators for each quorum. Within a quorum,
// The operatorsByQuorum provides a list of operators for each quorum. Within a quorum,
// the operators are ordered; in case of rate limiting, the first operators will be ejected.
EjectOperators(ctx context.Context, operatorsByQuorum [][]OperatorID) (*types.Transaction, error)

Expand Down
16 changes: 14 additions & 2 deletions disperser/dataapi/ejector.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,15 @@ func (e *Ejector) eject(ctx context.Context, nonsigningRate *OperatorsNonsigning
return err
}

_, err = e.Transactor.EjectOperators(ctx, operatorsByQuorum)
return err
if _, err = e.Transactor.EjectOperators(ctx, operatorsByQuorum); err != nil {
e.Logger.Error("Ejection transaction failed", "err", err)
return err
}
e.Logger.Info("Ejection transaction succeeded")

// TODO: get the txn response and update the metrics.

return nil
}

func (e *Ejector) convertOperators(nonsigners []*OperatorNonsigningPercentageMetrics) ([][]core.OperatorID, error) {
Expand All @@ -94,14 +99,21 @@ func (e *Ejector) convertOperators(nonsigners []*OperatorNonsigningPercentageMet
}
}

numOperatorByQuorum := make(map[uint8]int)
stakeShareByQuorum := make(map[uint8]float64)

result := make([][]core.OperatorID, maxQuorumId+1)
for _, metric := range nonsigners {
id, err := core.OperatorIDFromHex(metric.OperatorId)
if err != nil {
return nil, err
}
result[metric.QuorumId] = append(result[metric.QuorumId], id)
numOperatorByQuorum[metric.QuorumId]++
stakeShareByQuorum[metric.QuorumId] += metric.StakePercentage
}

e.Metrics.UpdateRequestedOperatorMetric(numOperatorByQuorum, stakeShareByQuorum)

return result, nil
}
20 changes: 19 additions & 1 deletion disperser/dataapi/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ func NewMetrics(blobMetadataStore *blobstore.BlobMetadataStore, httpPort string,
},
[]string{"status", "mode"},
),

// The "state" could be:
// - "requested": operator is requested for ejection; or
// - "ejected": operator is actually ejected
Expand Down Expand Up @@ -125,6 +124,25 @@ func (g *Metrics) IncrementFailedEjection(mode string) {
}).Inc()
}

func (g *Metrics) UpdateRequestedOperatorMetric(numOperatorsByQuorum map[uint8]int, stakeShareByQuorum map[uint8]float64) {
for q, count := range numOperatorsByQuorum {
for i := 0; i < count; i++ {
g.Operators.With(prometheus.Labels{
"quorum": string(q),
"state": "requested",
"type": "number",
}).Inc()
}
}
for q, stakeShare := range stakeShareByQuorum {
g.Operators.With(prometheus.Labels{
"quorum": string(q),
"state": "requested",
"type": "stake",
}).Add(stakeShare)
}
}

// Start starts the metrics server
func (g *Metrics) Start(ctx context.Context) {
g.logger.Info("Starting metrics server at ", "port", g.httpPort)
Expand Down
4 changes: 3 additions & 1 deletion disperser/dataapi/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ func (s *server) Start() error {
metrics.GET("/churner-service-availability", s.FetchChurnerServiceAvailability)
metrics.GET("/batcher-service-availability", s.FetchBatcherAvailability)
}
ejection := v1.Group("/ejection")
ejection.GET("/operators", s.EjectOperatorsHandler)
swagger := v1.Group("/swagger")
{
swagger.GET("/*any", ginswagger.WrapHandler(swaggerfiles.Handler))
Expand Down Expand Up @@ -331,7 +333,7 @@ func (s *server) EjectOperatorsHandler(c *gin.Context) {
}

nonSigningRate, err := s.getOperatorNonsigningRate(c.Request.Context(), endTime.Unix()-interval, endTime.Unix())
if err != nil {
if err == nil {
err = s.ejector.eject(c.Request.Context(), nonSigningRate, mode)
}
if err != nil {
Expand Down

0 comments on commit f52d82e

Please sign in to comment.