Skip to content

Commit

Permalink
[Dataapi] Fix gql error (Layr-Labs#514)
Browse files Browse the repository at this point in the history
Co-authored-by: Siddharth More <Siddhi More>
  • Loading branch information
siddimore authored Apr 24, 2024
1 parent 1001025 commit cbff1ae
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion disperser/cmd/dataapi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,5 @@ func RunDataApi(ctx *cli.Context) error {
logger.Errorf("Failed to shutdown server: %v", err)
}

return server.Start()
return err
}
3 changes: 2 additions & 1 deletion disperser/dataapi/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func (s *server) Start() error {
Handler: router,
ReadTimeout: 5 * time.Second,
ReadHeaderTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
WriteTimeout: 20 * time.Second,
IdleTimeout: 120 * time.Second,
}

Expand Down Expand Up @@ -570,6 +570,7 @@ func (s *server) FetchDeregisteredOperators(c *gin.Context) {

operatorMetadatas, err := s.getDeregisteredOperatorForDays(c.Request.Context(), int32(daysInt))
if err != nil {
s.logger.Error("Failed to fetch deregistered operators", "error", err)
s.metrics.IncrementFailedRequestNum("FetchDeregisteredOperators")
errorResponse(c, err)
return
Expand Down
10 changes: 5 additions & 5 deletions disperser/dataapi/subgraph/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ package subgraph

import (
"context"
"encoding/hex"
"fmt"
"sync"
"time"

"github.com/Layr-Labs/eigenda/core"
"github.com/shurcooL/graphql"
)

Expand All @@ -26,7 +24,7 @@ type (
QueryBatchNonSigningInfo(ctx context.Context, startTime, endTime int64) ([]*BatchNonSigningInfo, error)
QueryDeregisteredOperatorsGreaterThanBlockTimestamp(ctx context.Context, blockTimestamp uint64) ([]*Operator, error)
QueryRegisteredOperatorsGreaterThanBlockTimestamp(ctx context.Context, blockTimestamp uint64) ([]*Operator, error)
QueryOperatorInfoByOperatorIdAtBlockNumber(ctx context.Context, operatorId core.OperatorID, blockNumber uint32) (*IndexedOperatorInfo, error)
QueryOperatorInfoByOperatorIdAtBlockNumber(ctx context.Context, operatorId string, blockNumber uint32) (*IndexedOperatorInfo, error)
QueryOperatorAddedToQuorum(ctx context.Context, startBlock, endBlock uint32) ([]*OperatorQuorum, error)
QueryOperatorRemovedFromQuorum(ctx context.Context, startBlock, endBlock uint32) ([]*OperatorQuorum, error)
}
Expand Down Expand Up @@ -196,11 +194,13 @@ func (a *api) QueryDeregisteredOperatorsGreaterThanBlockTimestamp(ctx context.Co
return query.OperatorDeregistereds, nil
}

func (a *api) QueryOperatorInfoByOperatorIdAtBlockNumber(ctx context.Context, operatorId core.OperatorID, blockNumber uint32) (*IndexedOperatorInfo, error) {
func (a *api) QueryOperatorInfoByOperatorIdAtBlockNumber(ctx context.Context, operatorId string, blockNumber uint32) (*IndexedOperatorInfo, error) {
fmt.Printf("==QueryOperatorInfoByOperatorIdAtBlockNumber ==== operatorId: %v\n", operatorId)

var (
query queryOperatorById
variables = map[string]any{
"id": graphql.String(fmt.Sprintf("0x%s", hex.EncodeToString(operatorId[:]))),
"id": graphql.String(fmt.Sprintf("0x%s", operatorId)),
}
)
err := a.operatorStateGql.Query(context.Background(), &query, variables)
Expand Down
3 changes: 1 addition & 2 deletions disperser/dataapi/subgraph/mock/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"slices"

"github.com/Layr-Labs/eigenda/core"
"github.com/Layr-Labs/eigenda/disperser/dataapi/subgraph"
"github.com/stretchr/testify/mock"
)
Expand Down Expand Up @@ -115,7 +114,7 @@ func (m *MockSubgraphApi) QueryDeregisteredOperatorsGreaterThanBlockTimestamp(ct
return value, args.Error(1)
}

func (m *MockSubgraphApi) QueryOperatorInfoByOperatorIdAtBlockNumber(ctx context.Context, operatorId core.OperatorID, blockNumber uint32) (*subgraph.IndexedOperatorInfo, error) {
func (m *MockSubgraphApi) QueryOperatorInfoByOperatorIdAtBlockNumber(ctx context.Context, operatorId string, blockNumber uint32) (*subgraph.IndexedOperatorInfo, error) {
args := m.Called()

var value *subgraph.IndexedOperatorInfo
Expand Down
18 changes: 9 additions & 9 deletions disperser/dataapi/subgraph_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ type (
TxFee uint64
}
Operator struct {
Id []byte
OperatorId []byte
Operator []byte
Id string
OperatorId string
Operator string
BlockTimestamp uint64
BlockNumber uint64
TransactionHash []byte
TransactionHash string
}
OperatorQuorum struct {
Operator string
Expand Down Expand Up @@ -239,7 +239,7 @@ func (sc *subgraphClient) QueryIndexedDeregisteredOperatorsForTimeWindow(ctx con
// Copy the operator id to a 32 byte array.
copy(operatorId[:], operator.OperatorId)

operatorInfo, err := sc.api.QueryOperatorInfoByOperatorIdAtBlockNumber(ctx, operatorId, uint32(operator.BlockNumber))
operatorInfo, err := sc.api.QueryOperatorInfoByOperatorIdAtBlockNumber(ctx, operator.OperatorId, uint32(operator.BlockNumber))
if err != nil {
operatorIdString := "0x" + hex.EncodeToString(operatorId[:])
errorMessage := fmt.Sprintf("query operator info by operator id at block number failed: %d for operator %s", uint32(operator.BlockNumber), operatorIdString)
Expand Down Expand Up @@ -334,12 +334,12 @@ func convertOperator(operator *subgraph.Operator) (*Operator, error) {
}

return &Operator{
Id: []byte(operator.Id),
OperatorId: []byte(operator.OperatorId),
Operator: []byte(operator.Operator),
Id: string(operator.Id),
OperatorId: string(operator.OperatorId),
Operator: string(operator.Operator),
BlockTimestamp: timestamp,
BlockNumber: blockNum,
TransactionHash: []byte(operator.TransactionHash),
TransactionHash: string(operator.TransactionHash),
}, nil
}

Expand Down
20 changes: 10 additions & 10 deletions disperser/dataapi/subgraph_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,20 +440,20 @@ func TestQueryOperators(t *testing.T) {
assert.Equal(t, 2, len(operators))

assert.NotNil(t, operators[0])
assert.Equal(t, []byte("0x000763fb86a79eda47c891d8826474d80b6a935ad2a2b5de921933e05c67f320f211"), operators[0].Id)
assert.Equal(t, []byte("0x000563fb86a79eda47c891d8826474d80b6a935ad2a2b5de921933e05c67f320f211"), operators[0].Operator)
assert.Equal(t, []byte("0xe1cdae12a0074f20b8fc96a0489376db34075e545ef60c4845d264a732568311"), operators[0].OperatorId)
assert.Equal(t, "0x000763fb86a79eda47c891d8826474d80b6a935ad2a2b5de921933e05c67f320f211", operators[0].Id)
assert.Equal(t, "0x000563fb86a79eda47c891d8826474d80b6a935ad2a2b5de921933e05c67f320f211", operators[0].Operator)
assert.Equal(t, "0xe1cdae12a0074f20b8fc96a0489376db34075e545ef60c4845d264a732568311", operators[0].OperatorId)
assert.Equal(t, uint64(1696975449), operators[0].BlockTimestamp)
assert.Equal(t, uint64(87), operators[0].BlockNumber)
assert.Equal(t, []byte("0x000163fb86a79eda47c891d8826474d80b6a935ad2a2b5de921933e05c67f320f211"), operators[0].TransactionHash)
assert.Equal(t, "0x000163fb86a79eda47c891d8826474d80b6a935ad2a2b5de921933e05c67f320f211", operators[0].TransactionHash)

assert.NotNil(t, operators[1])
assert.Equal(t, []byte("0x000763fb86a79eda47c891d8826474d80b6a935ad2a2b5de921933e05c67f320f212"), operators[1].Id)
assert.Equal(t, []byte("0x000563fb86a79eda47c891d8826474d80b6a935ad2a2b5de921933e05c67f320f212"), operators[1].Operator)
assert.Equal(t, []byte("0xe1cdae12a0074f20b8fc96a0489376db34075e545ef60c4845d264a732568310"), operators[1].OperatorId)
assert.Equal(t, "0x000763fb86a79eda47c891d8826474d80b6a935ad2a2b5de921933e05c67f320f212", operators[1].Id)
assert.Equal(t, "0x000563fb86a79eda47c891d8826474d80b6a935ad2a2b5de921933e05c67f320f212", operators[1].Operator)
assert.Equal(t, "0xe1cdae12a0074f20b8fc96a0489376db34075e545ef60c4845d264a732568310", operators[1].OperatorId)
assert.Equal(t, uint64(1696975459), operators[1].BlockTimestamp)
assert.Equal(t, uint64(88), operators[1].BlockNumber)
assert.Equal(t, []byte("0x000163fb86a79eda47c891d8826474d80b6a935ad2a2b5de921933e05c67f320f212"), operators[1].TransactionHash)
assert.Equal(t, "0x000163fb86a79eda47c891d8826474d80b6a935ad2a2b5de921933e05c67f320f212", operators[1].TransactionHash)
}

func TestQueryIndexedDeregisteredOperatorsForTimeWindow(t *testing.T) {
Expand All @@ -480,8 +480,8 @@ func TestQueryIndexedDeregisteredOperatorsForTimeWindow(t *testing.T) {
assert.Equal(t, expectedIndexedOperatorInfo.PubkeyG2, operator.IndexedOperatorInfo.PubkeyG2)
assert.Equal(t, "localhost:32006;32007", operator.IndexedOperatorInfo.Socket)
assert.Equal(t, uint64(22), uint64(operator.BlockNumber))
assert.Equal(t, []byte("0xe22dae12a0074f20b8fc96a0489376db34075e545ef60c4845d264a732568311"), operator.Metadata.OperatorId)
assert.Equal(t, []byte("0x000223fb86a79eda47c891d8826474d80b6a935ad2a2b5de921933e05c67f320f211"), operator.Metadata.TransactionHash)
assert.Equal(t, "0xe22dae12a0074f20b8fc96a0489376db34075e545ef60c4845d264a732568311", operator.Metadata.OperatorId)
assert.Equal(t, "0x000223fb86a79eda47c891d8826474d80b6a935ad2a2b5de921933e05c67f320f211", operator.Metadata.TransactionHash)
assert.Equal(t, uint64(22), uint64(operator.Metadata.BlockNumber))
}

Expand Down

0 comments on commit cbff1ae

Please sign in to comment.