From 5e5a18ec7f60e13c7da1c3ad489ce5974386122a Mon Sep 17 00:00:00 2001 From: Siddharth More Date: Mon, 22 Apr 2024 16:07:59 -0700 Subject: [PATCH 1/4] Fix gql error --- disperser/dataapi/subgraph/api.go | 8 +++----- disperser/dataapi/subgraph/mock/api.go | 3 +-- disperser/dataapi/subgraph_client.go | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/disperser/dataapi/subgraph/api.go b/disperser/dataapi/subgraph/api.go index 900a9f1e9c..8ded7e0f71 100644 --- a/disperser/dataapi/subgraph/api.go +++ b/disperser/dataapi/subgraph/api.go @@ -2,12 +2,10 @@ package subgraph import ( "context" - "encoding/hex" "fmt" "sync" "time" - "github.com/Layr-Labs/eigenda/core" "github.com/shurcooL/graphql" ) @@ -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 []byte, blockNumber uint32) (*IndexedOperatorInfo, error) QueryOperatorAddedToQuorum(ctx context.Context, startBlock, endBlock uint32) ([]*OperatorQuorum, error) QueryOperatorRemovedFromQuorum(ctx context.Context, startBlock, endBlock uint32) ([]*OperatorQuorum, error) } @@ -196,11 +194,11 @@ 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 []byte, blockNumber uint32) (*IndexedOperatorInfo, error) { var ( query queryOperatorById variables = map[string]any{ - "id": graphql.String(fmt.Sprintf("0x%s", hex.EncodeToString(operatorId[:]))), + "id": graphql.String(fmt.Sprintf("0x%s", string(operatorId[:]))), } ) err := a.operatorStateGql.Query(context.Background(), &query, variables) diff --git a/disperser/dataapi/subgraph/mock/api.go b/disperser/dataapi/subgraph/mock/api.go index 7bb152335d..b82e66b5e7 100644 --- a/disperser/dataapi/subgraph/mock/api.go +++ b/disperser/dataapi/subgraph/mock/api.go @@ -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" ) @@ -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 []byte, blockNumber uint32) (*subgraph.IndexedOperatorInfo, error) { args := m.Called() var value *subgraph.IndexedOperatorInfo diff --git a/disperser/dataapi/subgraph_client.go b/disperser/dataapi/subgraph_client.go index 749dc44b37..7768b807bd 100644 --- a/disperser/dataapi/subgraph_client.go +++ b/disperser/dataapi/subgraph_client.go @@ -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) From 9692cb5a1c6ffb615cdfe701e0231dbb34a72183 Mon Sep 17 00:00:00 2001 From: Siddharth More Date: Tue, 23 Apr 2024 07:41:23 -0700 Subject: [PATCH 2/4] change to string as gql query is a string and avoid unncesseary conversion --- disperser/dataapi/subgraph/api.go | 8 +++++--- disperser/dataapi/subgraph/mock/api.go | 2 +- disperser/dataapi/subgraph_client.go | 16 ++++++++-------- disperser/dataapi/subgraph_client_test.go | 20 ++++++++++---------- 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/disperser/dataapi/subgraph/api.go b/disperser/dataapi/subgraph/api.go index 8ded7e0f71..8e5aab5236 100644 --- a/disperser/dataapi/subgraph/api.go +++ b/disperser/dataapi/subgraph/api.go @@ -24,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 []byte, 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) } @@ -194,11 +194,13 @@ func (a *api) QueryDeregisteredOperatorsGreaterThanBlockTimestamp(ctx context.Co return query.OperatorDeregistereds, nil } -func (a *api) QueryOperatorInfoByOperatorIdAtBlockNumber(ctx context.Context, operatorId []byte, 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", string(operatorId[:]))), + "id": graphql.String(fmt.Sprintf("0x%s", operatorId)), } ) err := a.operatorStateGql.Query(context.Background(), &query, variables) diff --git a/disperser/dataapi/subgraph/mock/api.go b/disperser/dataapi/subgraph/mock/api.go index b82e66b5e7..465c198ef1 100644 --- a/disperser/dataapi/subgraph/mock/api.go +++ b/disperser/dataapi/subgraph/mock/api.go @@ -114,7 +114,7 @@ func (m *MockSubgraphApi) QueryDeregisteredOperatorsGreaterThanBlockTimestamp(ct return value, args.Error(1) } -func (m *MockSubgraphApi) QueryOperatorInfoByOperatorIdAtBlockNumber(ctx context.Context, operatorId []byte, 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 diff --git a/disperser/dataapi/subgraph_client.go b/disperser/dataapi/subgraph_client.go index 7768b807bd..40d966feec 100644 --- a/disperser/dataapi/subgraph_client.go +++ b/disperser/dataapi/subgraph_client.go @@ -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 @@ -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 } diff --git a/disperser/dataapi/subgraph_client_test.go b/disperser/dataapi/subgraph_client_test.go index d4b2bd5be4..039f5e5537 100644 --- a/disperser/dataapi/subgraph_client_test.go +++ b/disperser/dataapi/subgraph_client_test.go @@ -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) { @@ -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)) } From 030e5e5ec6cc7b4ac5095b22424dba85044dcd31 Mon Sep 17 00:00:00 2001 From: Siddharth More Date: Tue, 23 Apr 2024 09:45:22 -0700 Subject: [PATCH 3/4] increase writetimeout --- disperser/dataapi/server.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/disperser/dataapi/server.go b/disperser/dataapi/server.go index 405138de21..c76381868d 100644 --- a/disperser/dataapi/server.go +++ b/disperser/dataapi/server.go @@ -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, } @@ -560,6 +560,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 From d793ef41cffc12014d8a88045b0d29112bdb2e5b Mon Sep 17 00:00:00 2001 From: Siddharth More Date: Tue, 23 Apr 2024 11:01:51 -0700 Subject: [PATCH 4/4] minor fix --- disperser/cmd/dataapi/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/disperser/cmd/dataapi/main.go b/disperser/cmd/dataapi/main.go index 9a6dc5dd1d..589c847890 100644 --- a/disperser/cmd/dataapi/main.go +++ b/disperser/cmd/dataapi/main.go @@ -144,5 +144,5 @@ func RunDataApi(ctx *cli.Context) error { logger.Errorf("Failed to shutdown server: %v", err) } - return server.Start() + return err }