Skip to content

Commit

Permalink
Add api for the percentage of unsigned batches monitoring (#137)
Browse files Browse the repository at this point in the history
Co-authored-by: Wellington Barbosa <[email protected]>
Co-authored-by: Jian Xiao <[email protected]>
  • Loading branch information
3 people authored Jan 17, 2024
1 parent bd5897e commit 1355bd9
Show file tree
Hide file tree
Showing 12 changed files with 607 additions and 21 deletions.
2 changes: 1 addition & 1 deletion disperser/cmd/dataapi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func RunDataApi(ctx *cli.Context) error {
blobMetadataStore = blobstore.NewBlobMetadataStore(dynamoClient, logger, config.BlobstoreConfig.TableName, 0)
sharedStorage = blobstore.NewSharedStorage(config.BlobstoreConfig.BucketName, s3Client, blobMetadataStore, logger)
subgraphApi = subgraph.NewApi(config.SubgraphApiBatchMetadataAddr, config.SubgraphApiOperatorStateAddr)
subgraphClient = dataapi.NewSubgraphClient(subgraphApi)
subgraphClient = dataapi.NewSubgraphClient(subgraphApi, logger)
chainState = coreeth.NewChainState(tx, client)
metrics = dataapi.NewMetrics(config.MetricsConfig.HTTPPort, logger)
server = dataapi.NewServer(
Expand Down
83 changes: 80 additions & 3 deletions disperser/dataapi/docs/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 78 additions & 2 deletions disperser/dataapi/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,51 @@
}
}
},
"/metrics/operator_nonsigning_percentage": {
"get": {
"produces": [
"application/json"
],
"tags": [
"Metrics"
],
"summary": "Fetch operators non signing percentage",
"parameters": [
{
"type": "integer",
"description": "Interval to query for operators nonsigning percentage [default: 3600]",
"name": "interval",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/dataapi.OperatorsNonsigningPercentage"
}
},
"400": {
"description": "error: Bad request",
"schema": {
"$ref": "#/definitions/dataapi.ErrorResponse"
}
},
"404": {
"description": "error: Not found",
"schema": {
"$ref": "#/definitions/dataapi.ErrorResponse"
}
},
"500": {
"description": "error: Server error",
"schema": {
"$ref": "#/definitions/dataapi.ErrorResponse"
}
}
}
}
},
"/metrics/throughput": {
"get": {
"produces": [
Expand Down Expand Up @@ -338,6 +383,9 @@
"confirmation_block_number": {
"type": "integer"
},
"confirmation_txn_hash": {
"type": "string"
},
"fee": {
"type": "string"
},
Expand Down Expand Up @@ -391,8 +439,8 @@
"dataapi.Metric": {
"type": "object",
"properties": {
"cost_in_wei": {
"type": "integer"
"cost_in_gas": {
"type": "number"
},
"throughput": {
"type": "number"
Expand All @@ -413,6 +461,34 @@
}
}
},
"dataapi.OperatorNonsigningPercentageMetrics": {
"type": "object",
"properties": {
"percentage": {
"type": "number"
},
"total_batches": {
"type": "integer"
},
"total_unsigned_batches": {
"type": "integer"
}
}
},
"dataapi.OperatorsNonsigningPercentage": {
"type": "object",
"properties": {
"operators": {
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/dataapi.OperatorNonsigningPercentageMetrics"
}
},
"total_non_signers": {
"type": "integer"
}
}
},
"dataapi.Throughput": {
"type": "object",
"properties": {
Expand Down
54 changes: 52 additions & 2 deletions disperser/dataapi/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ definitions:
$ref: '#/definitions/github_com_Layr-Labs_eigenda_disperser.BlobStatus'
confirmation_block_number:
type: integer
confirmation_txn_hash:
type: string
fee:
type: string
reference_block_number:
Expand Down Expand Up @@ -90,8 +92,8 @@ definitions:
type: object
dataapi.Metric:
properties:
cost_in_wei:
type: integer
cost_in_gas:
type: number
throughput:
type: number
total_stake:
Expand All @@ -104,6 +106,24 @@ definitions:
operatorId:
type: string
type: object
dataapi.OperatorNonsigningPercentageMetrics:
properties:
percentage:
type: number
total_batches:
type: integer
total_unsigned_batches:
type: integer
type: object
dataapi.OperatorsNonsigningPercentage:
properties:
operators:
additionalProperties:
$ref: '#/definitions/dataapi.OperatorNonsigningPercentageMetrics'
type: object
total_non_signers:
type: integer
type: object
dataapi.Throughput:
properties:
throughput:
Expand Down Expand Up @@ -258,6 +278,36 @@ paths:
summary: Fetch non signers
tags:
- Metrics
/metrics/operator_nonsigning_percentage:
get:
parameters:
- description: 'Interval to query for operators nonsigning percentage [default:
3600]'
in: query
name: interval
type: integer
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/dataapi.OperatorsNonsigningPercentage'
"400":
description: 'error: Bad request'
schema:
$ref: '#/definitions/dataapi.ErrorResponse'
"404":
description: 'error: Not found'
schema:
$ref: '#/definitions/dataapi.ErrorResponse'
"500":
description: 'error: Server error'
schema:
$ref: '#/definitions/dataapi.ErrorResponse'
summary: Fetch operators non signing percentage
tags:
- Metrics
/metrics/throughput:
get:
parameters:
Expand Down
49 changes: 49 additions & 0 deletions disperser/dataapi/metrics_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"math/big"
"strconv"
"time"

"github.com/Layr-Labs/eigenda/core"
Expand Down Expand Up @@ -142,3 +143,51 @@ func (s *server) getNonSigners(ctx context.Context, intervalSeconds int64) (*[]N

return &nonSignersObj, nil
}

func (s *server) getOperatorNonsigningPercentage(ctx context.Context, intervalSeconds int64) (*OperatorsNonsigningPercentage, error) {
nonSigners, err := s.subgraphClient.QueryBatchNonSigningOperatorIdsInInterval(ctx, intervalSeconds)
if err != nil {
return nil, err
}

if len(nonSigners) == 0 {
return &OperatorsNonsigningPercentage{}, nil
}

pastBlockTimestamp := uint64(time.Now().Add(-time.Duration(intervalSeconds) * time.Second).Unix())
numBatchesByOperators, err := s.subgraphClient.QueryNumBatchesByOperatorsInThePastBlockTimestamp(ctx, pastBlockTimestamp)
if err != nil {
return nil, err
}

if len(numBatchesByOperators) == 0 {
return &OperatorsNonsigningPercentage{}, nil
}

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

for operatorId, totalUnsignedBatches := range nonSigners {
if totalUnsignedBatches > 0 {
numBatches := numBatchesByOperators[operatorId]
if numBatches == 0 {
continue
}
ps := fmt.Sprintf("%.2f", (float64(totalUnsignedBatches)/float64(numBatches))*100)
pf, err := strconv.ParseFloat(ps, 64)
if err != nil {
return nil, err
}

operators[operatorId] = OperatorNonsigningPercentageMetrics{
TotalUnsignedBatches: totalUnsignedBatches,
TotalBatches: numBatches,
Percentage: pf,
}
}
}

return &OperatorsNonsigningPercentage{
TotalNonSigners: len(operators),
Operators: operators,
}, nil
}
Loading

0 comments on commit 1355bd9

Please sign in to comment.