Skip to content

Commit

Permalink
Add support for fetch all operators' responses for a batch
Browse files Browse the repository at this point in the history
  • Loading branch information
jianoaix committed Jan 8, 2025
1 parent 5e23e1a commit 28b3368
Show file tree
Hide file tree
Showing 10 changed files with 169 additions and 90 deletions.
29 changes: 29 additions & 0 deletions disperser/common/v2/blobstore/dynamo_metadata_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,35 @@ func (s *BlobMetadataStore) GetDispersalResponse(ctx context.Context, batchHeade
return res, nil
}

func (s *BlobMetadataStore) GetDispersalResponses(ctx context.Context, batchHeaderHash [32]byte) ([]*corev2.DispersalResponse, error) {
items, err := s.dynamoDBClient.Query(ctx, s.tableName, "PK = :pk AND begins_with(SK, :prefix)", commondynamodb.ExpressionValues{
":pk": &types.AttributeValueMemberS{
Value: dispersalKeyPrefix + hex.EncodeToString(batchHeaderHash[:]),
},
":prefix": &types.AttributeValueMemberS{
Value: dispersalResponseSKPrefix,
},
})

if err != nil {
return nil, err
}

if len(items) == 0 {
return nil, fmt.Errorf("%w: dispersal responses not found for batch header hash %x", common.ErrMetadataNotFound, batchHeaderHash)
}

responses := make([]*corev2.DispersalResponse, len(items))
for i, item := range items {
responses[i], err = UnmarshalDispersalResponse(item)
if err != nil {
return nil, err
}
}

return responses, nil
}

func (s *BlobMetadataStore) PutBatchHeader(ctx context.Context, batchHeader *corev2.BatchHeader) error {
item, err := MarshalBatchHeader(batchHeader)
if err != nil {
Expand Down
37 changes: 37 additions & 0 deletions disperser/common/v2/blobstore/dynamo_metadata_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,15 +336,52 @@ func TestBlobMetadataStoreDispersals(t *testing.T) {
err = blobMetadataStore.PutDispersalResponse(ctx, dispersalResponse)
assert.ErrorIs(t, err, common.ErrAlreadyExists)

// the other operator's response for the same batch
opID2 := core.OperatorID{2, 3}
dispersalRequest2 := &corev2.DispersalRequest{
OperatorID: opID2,
OperatorAddress: gethcommon.HexToAddress("0x2234567"),
Socket: "socket",
DispersedAt: uint64(time.Now().UnixNano()),
BatchHeader: corev2.BatchHeader{
BatchRoot: [32]byte{1, 2, 3},
ReferenceBlockNumber: 100,
},
}
err = blobMetadataStore.PutDispersalRequest(ctx, dispersalRequest2)
assert.NoError(t, err)
dispersalResponse2 := &corev2.DispersalResponse{
DispersalRequest: dispersalRequest2,
RespondedAt: uint64(time.Now().UnixNano()),
Signature: [32]byte{1, 1, 1},
Error: "",
}
err = blobMetadataStore.PutDispersalResponse(ctx, dispersalResponse2)
assert.NoError(t, err)

responses, err := blobMetadataStore.GetDispersalResponses(ctx, bhh)
assert.NoError(t, err)
assert.Equal(t, 2, len(responses))
assert.Equal(t, dispersalResponse, responses[0])
assert.Equal(t, dispersalResponse2, responses[1])

deleteItems(t, []commondynamodb.Key{
{
"PK": &types.AttributeValueMemberS{Value: "BatchHeader#" + hex.EncodeToString(bhh[:])},
"SK": &types.AttributeValueMemberS{Value: "DispersalRequest#" + opID.Hex()},
},
{
"PK": &types.AttributeValueMemberS{Value: "BatchHeader#" + hex.EncodeToString(bhh[:])},
"SK": &types.AttributeValueMemberS{Value: "DispersalRequest#" + opID2.Hex()},
},
{
"PK": &types.AttributeValueMemberS{Value: "BatchHeader#" + hex.EncodeToString(bhh[:])},
"SK": &types.AttributeValueMemberS{Value: "DispersalResponse#" + opID.Hex()},
},
{
"PK": &types.AttributeValueMemberS{Value: "BatchHeader#" + hex.EncodeToString(bhh[:])},
"SK": &types.AttributeValueMemberS{Value: "DispersalResponse#" + opID2.Hex()},
},
})
}

Expand Down
18 changes: 0 additions & 18 deletions disperser/dataapi/docs/v1/V1_docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1126,12 +1126,6 @@ const docTemplateV1 = `{
"items": {
"type": "integer"
}
},
"y": {
"type": "array",
"items": {
"type": "integer"
}
}
}
},
Expand All @@ -1140,9 +1134,6 @@ const docTemplateV1 = `{
"properties": {
"x": {
"$ref": "#/definitions/github_com_consensys_gnark-crypto_ecc_bn254_internal_fptower.E2"
},
"y": {
"$ref": "#/definitions/github_com_consensys_gnark-crypto_ecc_bn254_internal_fptower.E2"
}
}
},
Expand All @@ -1151,9 +1142,6 @@ const docTemplateV1 = `{
"properties": {
"x": {
"$ref": "#/definitions/github_com_consensys_gnark-crypto_ecc_bn254_internal_fptower.E2"
},
"y": {
"$ref": "#/definitions/github_com_consensys_gnark-crypto_ecc_bn254_internal_fptower.E2"
}
}
},
Expand Down Expand Up @@ -1184,12 +1172,6 @@ const docTemplateV1 = `{
"items": {
"type": "integer"
}
},
"a1": {
"type": "array",
"items": {
"type": "integer"
}
}
}
},
Expand Down
18 changes: 0 additions & 18 deletions disperser/dataapi/docs/v1/V1_swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1122,12 +1122,6 @@
"items": {
"type": "integer"
}
},
"y": {
"type": "array",
"items": {
"type": "integer"
}
}
}
},
Expand All @@ -1136,9 +1130,6 @@
"properties": {
"x": {
"$ref": "#/definitions/github_com_consensys_gnark-crypto_ecc_bn254_internal_fptower.E2"
},
"y": {
"$ref": "#/definitions/github_com_consensys_gnark-crypto_ecc_bn254_internal_fptower.E2"
}
}
},
Expand All @@ -1147,9 +1138,6 @@
"properties": {
"x": {
"$ref": "#/definitions/github_com_consensys_gnark-crypto_ecc_bn254_internal_fptower.E2"
},
"y": {
"$ref": "#/definitions/github_com_consensys_gnark-crypto_ecc_bn254_internal_fptower.E2"
}
}
},
Expand Down Expand Up @@ -1180,12 +1168,6 @@
"items": {
"type": "integer"
}
},
"a1": {
"type": "array",
"items": {
"type": "integer"
}
}
}
},
Expand Down
12 changes: 0 additions & 12 deletions disperser/dataapi/docs/v1/V1_swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -253,24 +253,16 @@ definitions:
items:
type: integer
type: array
"y":
items:
type: integer
type: array
type: object
encoding.G2Commitment:
properties:
x:
$ref: '#/definitions/github_com_consensys_gnark-crypto_ecc_bn254_internal_fptower.E2'
"y":
$ref: '#/definitions/github_com_consensys_gnark-crypto_ecc_bn254_internal_fptower.E2'
type: object
encoding.LengthProof:
properties:
x:
$ref: '#/definitions/github_com_consensys_gnark-crypto_ecc_bn254_internal_fptower.E2'
"y":
$ref: '#/definitions/github_com_consensys_gnark-crypto_ecc_bn254_internal_fptower.E2'
type: object
github_com_Layr-Labs_eigenda_disperser.BlobStatus:
enum:
Expand All @@ -294,10 +286,6 @@ definitions:
items:
type: integer
type: array
a1:
items:
type: integer
type: array
type: object
semver.SemverMetrics:
properties:
Expand Down
13 changes: 8 additions & 5 deletions disperser/dataapi/docs/v2/V2_docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ const docTemplateV2 = `{
},
{
"type": "string",
"description": "Operator ID in hex string",
"description": "Operator ID in hex string [default: all operators if unspecified]",
"name": "operator_id",
"in": "query"
}
Expand All @@ -454,7 +454,7 @@ const docTemplateV2 = `{
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/v2.OperatorDispersalResponse"
"$ref": "#/definitions/v2.OperatorDispersalResponses"
}
},
"400": {
Expand Down Expand Up @@ -917,11 +917,14 @@ const docTemplateV2 = `{
}
}
},
"v2.OperatorDispersalResponse": {
"v2.OperatorDispersalResponses": {
"type": "object",
"properties": {
"operator_dispersal_response": {
"$ref": "#/definitions/v2.DispersalResponse"
"operator_dispersal_responses": {
"type": "array",
"items": {
"$ref": "#/definitions/v2.DispersalResponse"
}
}
}
},
Expand Down
13 changes: 8 additions & 5 deletions disperser/dataapi/docs/v2/V2_swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@
},
{
"type": "string",
"description": "Operator ID in hex string",
"description": "Operator ID in hex string [default: all operators if unspecified]",
"name": "operator_id",
"in": "query"
}
Expand All @@ -451,7 +451,7 @@
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/v2.OperatorDispersalResponse"
"$ref": "#/definitions/v2.OperatorDispersalResponses"
}
},
"400": {
Expand Down Expand Up @@ -914,11 +914,14 @@
}
}
},
"v2.OperatorDispersalResponse": {
"v2.OperatorDispersalResponses": {
"type": "object",
"properties": {
"operator_dispersal_response": {
"$ref": "#/definitions/v2.DispersalResponse"
"operator_dispersal_responses": {
"type": "array",
"items": {
"$ref": "#/definitions/v2.DispersalResponse"
}
}
}
},
Expand Down
12 changes: 7 additions & 5 deletions disperser/dataapi/docs/v2/V2_swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,12 @@ definitions:
$ref: '#/definitions/big.Int'
type: object
type: object
v2.OperatorDispersalResponse:
v2.OperatorDispersalResponses:
properties:
operator_dispersal_response:
$ref: '#/definitions/v2.DispersalResponse'
operator_dispersal_responses:
items:
$ref: '#/definitions/v2.DispersalResponse'
type: array
type: object
v2.OperatorPortCheckResponse:
properties:
Expand Down Expand Up @@ -559,7 +561,7 @@ paths:
name: batch_header_hash
required: true
type: string
- description: Operator ID in hex string
- description: 'Operator ID in hex string [default: all operators if unspecified]'
in: query
name: operator_id
type: string
Expand All @@ -569,7 +571,7 @@ paths:
"200":
description: OK
schema:
$ref: '#/definitions/v2.OperatorDispersalResponse'
$ref: '#/definitions/v2.OperatorDispersalResponses'
"400":
description: 'error: Bad request'
schema:
Expand Down
Loading

0 comments on commit 28b3368

Please sign in to comment.