Skip to content

Commit

Permalink
Make sure the operator quorum events are all fetched
Browse files Browse the repository at this point in the history
  • Loading branch information
jianoaix committed Mar 18, 2024
1 parent 54fce30 commit 320da93
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 22 deletions.
42 changes: 32 additions & 10 deletions disperser/dataapi/subgraph/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,23 @@ func (a *api) QueryOperatorAddedToQuorum(ctx context.Context, startBlock, endBlo
"blockNumber_gt": graphql.Int(startBlock - 1),
"blockNumber_lt": graphql.Int(endBlock + 1),
}
query := new(queryOperatorAddedToQuorum)
err := a.operatorStateGql.Query(ctx, &query, variables)
if err != nil {
return nil, err
skip := 0
result := new(queryOperatorAddedToQuorum)
addedQuorums := make([]*OperatorQuorum, 0)
for {
variables["first"] = graphql.Int(maxEntriesPerQuery)
variables["skip"] = graphql.Int(skip)
err := a.operatorStateGql.Query(ctx, &result, variables)
if err != nil {
return nil, err
}
if len(result.OperatorAddedToQuorum) == 0 {
break
}
addedQuorums = append(addedQuorums, result.OperatorAddedToQuorum...)
skip += maxEntriesPerQuery
}
return query.OperatorAddedToQuorum, nil
return addedQuorums, nil
}

// QueryOperatorRemovedFromQuorum finds operators' quorum opt-out history in range [startBlock, endBlock].
Expand All @@ -236,10 +247,21 @@ func (a *api) QueryOperatorRemovedFromQuorum(ctx context.Context, startBlock, en
"blockNumber_gt": graphql.Int(startBlock - 1),
"blockNumber_lt": graphql.Int(endBlock + 1),
}
query := new(queryOperatorRemovedFromQuorum)
err := a.operatorStateGql.Query(ctx, &query, variables)
if err != nil {
return nil, err
skip := 0
result := new(queryOperatorRemovedFromQuorum)
removedQuorums := make([]*OperatorQuorum, 0)
for {
variables["first"] = graphql.Int(maxEntriesPerQuery)
variables["skip"] = graphql.Int(skip)
err := a.operatorStateGql.Query(ctx, &result, variables)
if err != nil {
return nil, err
}
if len(result.OperatorRemovedFromQuorum) == 0 {
break
}
removedQuorums = append(removedQuorums, result.OperatorRemovedFromQuorum...)
skip += maxEntriesPerQuery
}
return query.OperatorRemovedFromQuorum, nil
return removedQuorums, nil
}
14 changes: 8 additions & 6 deletions disperser/dataapi/subgraph/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ type (
TransactionHash graphql.String
}
OperatorQuorum struct {
Id graphql.String
Operator graphql.String
QuorumNumbers graphql.String
BlockNumber graphql.String
Id graphql.String
Operator graphql.String
QuorumNumbers graphql.String
BlockNumber graphql.String
BlockTimestamp graphql.String
}
BatchNonSigningOperatorIds struct {
NonSigning struct {
Expand All @@ -54,6 +55,7 @@ type (
OperatorId graphql.String `graphql:"operatorId"`
} `graphql:"nonSigners"`
} `graphql:"nonSigning"`
BlockNumber graphql.String
}
SocketUpdates struct {
Socket graphql.String
Expand Down Expand Up @@ -102,9 +104,9 @@ type (
Operator IndexedOperatorInfo `graphql:"operator(id: $id)"`
}
queryOperatorAddedToQuorum struct {
OperatorAddedToQuorum []*OperatorQuorum `graphql:"operatorAddedToQuorums(orderBy: blockTimestamp, where: {and: [{blockNumber_gt: $blockNumber_gt}, {blockNumber_lt: $blockNumber_lt}]})"`
OperatorAddedToQuorum []*OperatorQuorum `graphql:"operatorAddedToQuorums(first: $first, skip: $skip, orderBy: blockTimestamp, where: {and: [{blockNumber_gt: $blockNumber_gt}, {blockNumber_lt: $blockNumber_lt}]})"`
}
queryOperatorRemovedFromQuorum struct {
OperatorRemovedFromQuorum []*OperatorQuorum `graphql:"operatorRemovedFromQuorums(orderBy: blockTimestamp, where: {and: [{blockNumber_gt: $blockNumber_gt}, {blockNumber_lt: $blockNumber_lt}]})"`
OperatorRemovedFromQuorum []*OperatorQuorum `graphql:"operatorRemovedFromQuorums(first: $first, skip: $skip, orderBy: blockTimestamp, where: {and: [{blockNumber_gt: $blockNumber_gt}, {blockNumber_lt: $blockNumber_lt}]})"`
}
)
34 changes: 28 additions & 6 deletions disperser/dataapi/subgraph_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ type (
TransactionHash []byte
}
OperatorQuorum struct {
Operator string
QuorumNumbers []byte
BlockNumber uint32
Operator string
QuorumNumbers []byte
BlockNumber uint32
BlockTimestamp uint64
}
OperatorQuorumEvents struct {
// AddedToQuorum is mapping from operator address to a list of sorted events
Expand All @@ -79,6 +80,7 @@ type (
Count int
}
BatchNonSigningInfo struct {
BlockNumber uint32
QuorumNumbers []uint8
ReferenceBlockNumber uint32
// The operatorIds of nonsigners for the batch.
Expand Down Expand Up @@ -358,10 +360,25 @@ func parseOperatorQuorum(operatorQuorum []*subgraph.OperatorQuorum) ([]*Operator
if err != nil {
return nil, err
}
blockTimestamp, err := strconv.ParseUint(string(opq.BlockTimestamp), 10, 64)
if err != nil {
return nil, err
}
quorumStr := string(opq.QuorumNumbers)[2:]
quorumNumbers := make([]byte, 0)
for i := 0; i < len(quorumStr); i += 2 {
pair := quorumStr[i : i+2]
quorum, err := strconv.Atoi(pair)
if err != nil {
return nil, err
}
quorumNumbers = append(quorumNumbers, uint8(quorum))
}
parsed[i] = &OperatorQuorum{
Operator: string(opq.Operator),
QuorumNumbers: []byte(opq.QuorumNumbers),
BlockNumber: uint32(blockNum),
Operator: string(opq.Operator),
QuorumNumbers: quorumNumbers,
BlockNumber: uint32(blockNum),
BlockTimestamp: blockTimestamp,
}
}
// Sort the quorum events by ascending order of block number.
Expand All @@ -387,12 +404,17 @@ func convertNonSigningInfo(infoGql *subgraph.BatchNonSigningInfo) (*BatchNonSign
if err != nil {
return nil, err
}
confirmBlockNum, err := strconv.ParseUint(string(infoGql.BlockNumber), 10, 64)
if err != nil {
return nil, err
}
nonSigners := make([]string, len(infoGql.NonSigning.NonSigners))
for i, nonSigner := range infoGql.NonSigning.NonSigners {
nonSigners[i] = string(nonSigner.OperatorId)
}

return &BatchNonSigningInfo{
BlockNumber: uint32(confirmBlockNum),
QuorumNumbers: quorums,
ReferenceBlockNumber: uint32(blockNum),
NonSigners: nonSigners,
Expand Down

0 comments on commit 320da93

Please sign in to comment.