Skip to content

Commit

Permalink
Add a param to return only live nonsigners
Browse files Browse the repository at this point in the history
  • Loading branch information
jianoaix committed Apr 18, 2024
1 parent 66a8486 commit 9a3eae3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
4 changes: 4 additions & 0 deletions disperser/dataapi/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,10 @@ paths:
in: query
name: end
type: string
- description: 'Whether return only live nonsigners [default: true]'
in: query
name: live_only
type: string
produces:
- application/json
responses:
Expand Down
5 changes: 4 additions & 1 deletion disperser/dataapi/nonsigner_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/Layr-Labs/eigenda/core/eth"
)

func (s *server) getOperatorNonsigningRate(ctx context.Context, startTime, endTime int64) (*OperatorsNonsigningPercentage, error) {
func (s *server) getOperatorNonsigningRate(ctx context.Context, startTime, endTime int64, liveOnly bool) (*OperatorsNonsigningPercentage, error) {
batches, err := s.subgraphClient.QueryBatchNonSigningInfoInInterval(ctx, startTime, endTime)
if err != nil {
return nil, err
Expand Down Expand Up @@ -101,6 +101,9 @@ func (s *server) getOperatorNonsigningRate(ctx context.Context, startTime, endTi
if stake, ok := state.Operators[q][opID]; ok {
p, _ := new(big.Int).Div(new(big.Int).Mul(stake.Stake, big.NewInt(multipler)), state.Totals[q].Stake).Float64()
stakePercentage = p / multipler
} else if liveOnly {
// Operator "opID" isn't live at "endBlock", skip it.
continue
}

nonsignerMetric := OperatorNonsigningPercentageMetrics{
Expand Down
32 changes: 21 additions & 11 deletions disperser/dataapi/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,16 +459,17 @@ func (s *server) FetchNonSigners(c *gin.Context) {

// FetchOperatorsNonsigningPercentageHandler godoc
//
// @Summary Fetch operators non signing percentage
// @Tags Metrics
// @Produce json
// @Param interval query int false "Interval to query for operators nonsigning percentage [default: 3600]"
// @Param end query string false "End time (2006-01-02T15:04:05Z) to query for operators nonsigning percentage [default: now]"
// @Success 200 {object} OperatorsNonsigningPercentage
// @Failure 400 {object} ErrorResponse "error: Bad request"
// @Failure 404 {object} ErrorResponse "error: Not found"
// @Failure 500 {object} ErrorResponse "error: Server error"
// @Router /metrics/operator-nonsigning-percentage [get]
// @Summary Fetch operators non signing percentage
// @Tags Metrics
// @Produce json
// @Param interval query int false "Interval to query for operators nonsigning percentage [default: 3600]"
// @Param end query string false "End time (2006-01-02T15:04:05Z) to query for operators nonsigning percentage [default: now]"
// @Param live_only query string false "Whether return only live nonsigners [default: true]"
// @Success 200 {object} OperatorsNonsigningPercentage
// @Failure 400 {object} ErrorResponse "error: Bad request"
// @Failure 404 {object} ErrorResponse "error: Not found"
// @Failure 500 {object} ErrorResponse "error: Server error"
// @Router /metrics/operator-nonsigning-percentage [get]
func (s *server) FetchOperatorsNonsigningPercentageHandler(c *gin.Context) {
timer := prometheus.NewTimer(prometheus.ObserverFunc(func(f float64) {
s.metrics.ObserveLatency("FetchOperatorsNonsigningPercentageHandler", f*1000) // make milliseconds
Expand All @@ -491,9 +492,18 @@ func (s *server) FetchOperatorsNonsigningPercentageHandler(c *gin.Context) {
interval = 3600
}

liveOnly := "true"
if c.Query("live_only") != "" {
liveOnly = c.Query("live_only")
if liveOnly != "true" && liveOnly != "false" {
errorResponse(c, errors.New("the live_only param must be \"true\" or \"false\""))
return
}
}

startTime := endTime.Add(-time.Duration(interval) * time.Second)

metric, err := s.getOperatorNonsigningRate(c.Request.Context(), startTime.Unix(), endTime.Unix())
metric, err := s.getOperatorNonsigningRate(c.Request.Context(), startTime.Unix(), endTime.Unix(), liveOnly == "true")
if err != nil {
s.metrics.IncrementFailedRequestNum("FetchOperatorsNonsigningPercentageHandler")
errorResponse(c, err)
Expand Down

0 comments on commit 9a3eae3

Please sign in to comment.