Skip to content

Commit

Permalink
Update response for nonsigners endpoint (Layr-Labs#219)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmanc authored Jan 30, 2024
1 parent b2d11b5 commit 70ee112
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 32 deletions.
36 changes: 36 additions & 0 deletions disperser/cmd/dataapi/docs/docs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Package docs Code generated by swaggo/swag. DO NOT EDIT
package docs

import "github.com/swaggo/swag"

const docTemplate = `{
"schemes": {{ marshal .Schemes }},
"swagger": "2.0",
"info": {
"description": "{{escape .Description}}",
"title": "{{.Title}}",
"contact": {},
"version": "{{.Version}}"
},
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {}
}`

// SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = &swag.Spec{
Version: "1",
Host: "",
BasePath: "",
Schemes: []string{"https", "http"},
Title: "EigenDA Data Access API",
Description: "This is the EigenDA Data Access API server.",
InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate,
LeftDelim: "{{",
RightDelim: "}}",
}

func init() {
swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
}
16 changes: 9 additions & 7 deletions disperser/dataapi/docs/docs.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Code generated by swaggo/swag. DO NOT EDIT.

// Package docs Code generated by swaggo/swag. DO NOT EDIT
package docs

import "github.com/swaggo/swag"
Expand Down Expand Up @@ -469,6 +468,9 @@ const docTemplate = `{
"dataapi.OperatorNonsigningPercentageMetrics": {
"type": "object",
"properties": {
"operator_id": {
"type": "string"
},
"percentage": {
"type": "number"
},
Expand All @@ -483,14 +485,14 @@ const docTemplate = `{
"dataapi.OperatorsNonsigningPercentage": {
"type": "object",
"properties": {
"operators": {
"type": "object",
"additionalProperties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/dataapi.OperatorNonsigningPercentageMetrics"
}
},
"total_non_signers": {
"type": "integer"
"meta": {
"$ref": "#/definitions/dataapi.Meta"
}
}
},
Expand Down
13 changes: 8 additions & 5 deletions disperser/dataapi/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,9 @@
"dataapi.OperatorNonsigningPercentageMetrics": {
"type": "object",
"properties": {
"operator_id": {
"type": "string"
},
"percentage": {
"type": "number"
},
Expand All @@ -478,14 +481,14 @@
"dataapi.OperatorsNonsigningPercentage": {
"type": "object",
"properties": {
"operators": {
"type": "object",
"additionalProperties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/dataapi.OperatorNonsigningPercentageMetrics"
}
},
"total_non_signers": {
"type": "integer"
"meta": {
"$ref": "#/definitions/dataapi.Meta"
}
}
},
Expand Down
12 changes: 7 additions & 5 deletions disperser/dataapi/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ definitions:
type: object
dataapi.OperatorNonsigningPercentageMetrics:
properties:
operator_id:
type: string
percentage:
type: number
total_batches:
Expand All @@ -117,12 +119,12 @@ definitions:
type: object
dataapi.OperatorsNonsigningPercentage:
properties:
operators:
additionalProperties:
data:
items:
$ref: '#/definitions/dataapi.OperatorNonsigningPercentageMetrics'
type: object
total_non_signers:
type: integer
type: array
meta:
$ref: '#/definitions/dataapi.Meta'
type: object
dataapi.Throughput:
properties:
Expand Down
14 changes: 8 additions & 6 deletions disperser/dataapi/metrics_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ func (s *server) getOperatorNonsigningPercentage(ctx context.Context, intervalSe
return &OperatorsNonsigningPercentage{}, nil
}

operators := make(map[string]OperatorNonsigningPercentageMetrics, 0)

operators := make([]*OperatorNonsigningPercentageMetrics, 0)
for operatorId, totalUnsignedBatches := range nonSigners {
if totalUnsignedBatches > 0 {
numBatches := numBatchesByOperators[operatorId]
Expand All @@ -177,17 +176,20 @@ func (s *server) getOperatorNonsigningPercentage(ctx context.Context, intervalSe
if err != nil {
return nil, err
}

operators[operatorId] = OperatorNonsigningPercentageMetrics{
operatorMetric := OperatorNonsigningPercentageMetrics{
OperatorId: operatorId,
TotalUnsignedBatches: totalUnsignedBatches,
TotalBatches: numBatches,
Percentage: pf,
}
operators = append(operators, &operatorMetric)
}
}

return &OperatorsNonsigningPercentage{
TotalNonSigners: len(operators),
Operators: operators,
Meta: Meta{
Size: len(operators),
},
Data: operators,
}, nil
}
5 changes: 3 additions & 2 deletions disperser/dataapi/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,15 @@ type (
}

OperatorNonsigningPercentageMetrics struct {
OperatorId string `json:"operator_id"`
TotalUnsignedBatches int `json:"total_unsigned_batches"`
TotalBatches int `json:"total_batches"`
Percentage float64 `json:"percentage"`
}

OperatorsNonsigningPercentage struct {
TotalNonSigners int `json:"total_non_signers"`
Operators map[string]OperatorNonsigningPercentageMetrics `json:"operators"`
Meta Meta `json:"meta"`
Data []*OperatorNonsigningPercentageMetrics `json:"data"`
}

ErrorResponse struct {
Expand Down
15 changes: 8 additions & 7 deletions disperser/dataapi/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,14 @@ func TestFetchUnsignedBatchesHandler(t *testing.T) {
assert.NoError(t, err)
assert.NotNil(t, response)

operator := response.Operators["0xe1cdae12a0074f20b8fc96a0489376db34075e545ef60c4845d264a732568310"]
assert.Equal(t, http.StatusOK, res.StatusCode)
assert.Equal(t, 2, response.TotalNonSigners)
assert.Equal(t, 3, operator.TotalBatches)
assert.Equal(t, 1, operator.TotalUnsignedBatches)
assert.Equal(t, float64(33.33), operator.Percentage)
assert.Equal(t, 2, len(response.Operators))
responseData := response.Data[0]
operatorId := responseData.OperatorId
assert.Equal(t, 2, response.Meta.Size)
assert.Equal(t, 3, responseData.TotalBatches)
assert.Equal(t, 1, responseData.TotalUnsignedBatches)
assert.Equal(t, float64(33.33), responseData.Percentage)
assert.Equal(t, "0xe1cdae12a0074f20b8fc96a0489376db34075e545ef60c4845d264a732568310", operatorId)
assert.Equal(t, 2, len(response.Data))
}

func setUpRouter() *gin.Engine {
Expand Down

0 comments on commit 70ee112

Please sign in to comment.