-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DataAPI V2 swagger refactor #1062
Conversation
be6d12f
to
2cb1dde
Compare
Working V2 swagger
2cb1dde
to
e0c187e
Compare
e0c187e
to
4380aca
Compare
// Copy the operator id to a 32 byte array. | ||
copy(operatorId[:], operator.OperatorId) | ||
|
||
operatorInfo, err := sc.api.QueryOperatorInfoByOperatorIdAtBlockNumber(ctx, operator.OperatorId, uint32(operator.BlockNumber)) |
Check failure
Code scanning / CodeQL
Incorrect conversion between integer types High
strconv.ParseUint
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 27 days ago
To fix the problem, we need to ensure that the value of operator.BlockNumber
is within the range of a 32-bit unsigned integer before performing the conversion. This can be done by adding an upper bound check using math.MaxUint32
. If the value exceeds this limit, we should handle the error appropriately.
-
Copy modified lines R377-R383
@@ -376,2 +376,9 @@ | ||
|
||
if operator.BlockNumber > math.MaxUint32 { | ||
operatorIdString := "0x" + hex.EncodeToString(operatorId[:]) | ||
errorMessage := fmt.Sprintf("block number exceeds uint32 limit: %d for operator %s", operator.BlockNumber, operatorIdString) | ||
addOperatorWithErrorDetail(operators, operator, operatorId, errorMessage) | ||
sc.logger.Warn(errorMessage) | ||
continue | ||
} | ||
operatorInfo, err := sc.api.QueryOperatorInfoByOperatorIdAtBlockNumber(ctx, operator.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) |
Check failure
Code scanning / CodeQL
Incorrect conversion between integer types High
strconv.ParseUint
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 27 days ago
To fix the problem, we need to add an upper bound check before converting the 64-bit unsigned integer to a 32-bit unsigned integer. This ensures that the value fits within the range of a 32-bit unsigned integer and prevents unexpected values.
- We will add a check to ensure that the value of
operator.BlockNumber
does not exceed the maximum value of a 32-bit unsigned integer (math.MaxUint32
). - If the value is within the valid range, we will proceed with the conversion. Otherwise, we will handle the error appropriately.
-
Copy modified line R10 -
Copy modified lines R378-R384
@@ -9,2 +9,3 @@ | ||
"time" | ||
"math" | ||
|
||
@@ -376,2 +377,9 @@ | ||
|
||
if operator.BlockNumber > math.MaxUint32 { | ||
operatorIdString := "0x" + hex.EncodeToString(operatorId[:]) | ||
errorMessage := fmt.Sprintf("block number exceeds uint32 range: %d for operator %s", operator.BlockNumber, operatorIdString) | ||
addOperatorWithErrorDetail(operators, operator, operatorId, errorMessage) | ||
sc.logger.Warn(errorMessage) | ||
continue | ||
} | ||
operatorInfo, err := sc.api.QueryOperatorInfoByOperatorIdAtBlockNumber(ctx, operator.OperatorId, uint32(operator.BlockNumber)) |
indexedOperatorInfo, err := dataapi.ConvertOperatorInfoGqlToIndexedOperatorInfo(operatorInfo) | ||
if err != nil { | ||
operatorIdString := "0x" + hex.EncodeToString(operatorId[:]) | ||
errorMessage := fmt.Sprintf("failed to convert operator info gql to indexed operator info at blocknumber: %d for operator %s", uint32(operator.BlockNumber), operatorIdString) |
Check failure
Code scanning / CodeQL
Incorrect conversion between integer types High
strconv.ParseUint
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 27 days ago
To fix the problem, we need to ensure that the uint64
value parsed from the BlockNumber
does not exceed the maximum value that a uint32
can hold before performing the conversion. This can be done by adding a bounds check before the conversion. If the value exceeds the maximum uint32
value, we should handle it appropriately, such as by logging an error or using a default value.
-
Copy modified line R9 -
Copy modified lines R378-R387
@@ -8,2 +8,3 @@ | ||
"strconv" | ||
"math" | ||
"time" | ||
@@ -376,3 +377,12 @@ | ||
|
||
operatorInfo, err := sc.api.QueryOperatorInfoByOperatorIdAtBlockNumber(ctx, operator.OperatorId, uint32(operator.BlockNumber)) | ||
var blockNumber uint32 | ||
if operator.BlockNumber > math.MaxUint32 { | ||
errorMessage := fmt.Sprintf("block number %d exceeds uint32 max value", operator.BlockNumber) | ||
addOperatorWithErrorDetail(operators, operator, operatorId, errorMessage) | ||
sc.logger.Warn(errorMessage) | ||
continue | ||
} else { | ||
blockNumber = uint32(operator.BlockNumber) | ||
} | ||
operatorInfo, err := sc.api.QueryOperatorInfoByOperatorIdAtBlockNumber(ctx, operator.OperatorId, blockNumber) | ||
if err != nil { |
|
||
operators[operatorId] = &QueriedOperatorInfo{ | ||
IndexedOperatorInfo: indexedOperatorInfo, | ||
BlockNumber: uint(operator.BlockNumber), |
Check failure
Code scanning / CodeQL
Incorrect conversion between integer types High
strconv.ParseUint
func addOperatorWithErrorDetail(operators map[core.OperatorID]*QueriedOperatorInfo, operator *Operator, operatorId [32]byte, errorMessage string) { | ||
operators[operatorId] = &QueriedOperatorInfo{ | ||
IndexedOperatorInfo: nil, | ||
BlockNumber: uint(operator.BlockNumber), |
Check failure
Code scanning / CodeQL
Incorrect conversion between integer types High
strconv.ParseUint
if err != nil { | ||
return nil, err | ||
} | ||
quorumNumbers = append(quorumNumbers, uint8(quorum)) |
Check failure
Code scanning / CodeQL
Incorrect conversion between integer types High
strconv.Atoi
Incorrect conversion of an integer with architecture-dependent bit size from
strconv.Atoi
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 27 days ago
To fix the problem, we need to ensure that the conversion from int
to uint8
is safe. This can be done by adding bounds checking to ensure that the value is within the valid range for uint8
before performing the conversion. Specifically, we should check that the value is between 0 and 255 inclusive.
- Modify the code to include bounds checking for the conversion from
int
touint8
. - If the value is out of bounds, handle the error appropriately (e.g., return an error).
-
Copy modified lines R510-R512
@@ -509,2 +509,5 @@ | ||
} | ||
if quorum < 0 || quorum > 255 { | ||
return nil, fmt.Errorf("quorum value out of range: %d", quorum) | ||
} | ||
quorumNumbers = append(quorumNumbers, uint8(quorum)) |
parsed[i] = &OperatorQuorum{ | ||
Operator: string(opq.Operator), | ||
QuorumNumbers: quorumNumbers, | ||
BlockNumber: uint32(blockNum), |
Check failure
Code scanning / CodeQL
Incorrect conversion between integer types High
strconv.ParseUint
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 27 days ago
To fix the problem, we need to ensure that the value of blockNum
fits within the 32-bit unsigned integer range before converting it to uint32
. This can be done by adding a check to verify that blockNum
is less than or equal to math.MaxUint32
. If the value exceeds this limit, we should handle the error appropriately.
-
Copy modified lines R7-R24 -
Copy modified lines R533-R538
@@ -6,2 +6,20 @@ | ||
"fmt" | ||
"math" | ||
"sort" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/Layr-Labs/eigenda/core" | ||
"github.com/Layr-Labs/eigenda/disperser/dataapi" | ||
"github.com/Layr-Labs/eigenda/disperser/dataapi/subgraph" | ||
|
||
"github.com/Layr-Labs/eigensdk-go/logging" | ||
|
||
"github.com/gammazero/workerpool" | ||
) | ||
|
||
import ( | ||
"context" | ||
"encoding/hex" | ||
"fmt" | ||
"sort" | ||
@@ -514,3 +532,8 @@ | ||
QuorumNumbers: quorumNumbers, | ||
BlockNumber: uint32(blockNum), | ||
BlockNumber: func() uint32 { | ||
if blockNum > math.MaxUint32 { | ||
panic(fmt.Sprintf("blockNum %d exceeds uint32 range", blockNum)) | ||
} | ||
return uint32(blockNum) | ||
}(), | ||
BlockTimestamp: blockTimestamp, |
} | ||
|
||
return &BatchNonSigningInfo{ | ||
BlockNumber: uint32(confirmBlockNum), |
Check failure
Code scanning / CodeQL
Incorrect conversion between integer types High
strconv.ParseUint
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 27 days ago
To fix the problem, we need to ensure that the value parsed as a 64-bit unsigned integer does not exceed the maximum value for a 32-bit unsigned integer before converting it. This can be done by adding an upper bound check before the conversion. If the value exceeds the maximum allowable value for a 32-bit unsigned integer, we should handle it appropriately, such as returning an error or using a default value.
-
Copy modified lines R546-R549
@@ -545,2 +545,6 @@ | ||
} | ||
// Check if confirmBlockNum exceeds the maximum value for uint32 | ||
if confirmBlockNum > math.MaxUint32 { | ||
return nil, fmt.Errorf("confirmBlockNum exceeds the maximum value for uint32: %d", confirmBlockNum) | ||
} | ||
nonSigners := make([]string, len(infoGql.NonSigning.NonSigners)) |
return &BatchNonSigningInfo{ | ||
BlockNumber: uint32(confirmBlockNum), | ||
QuorumNumbers: quorums, | ||
ReferenceBlockNumber: uint32(blockNum), |
Check failure
Code scanning / CodeQL
Incorrect conversion between integer types High
strconv.ParseUint
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 27 days ago
To fix the problem, we need to ensure that the value parsed as a uint64
does not exceed the maximum value that can be held by a uint32
before performing the conversion. This can be done by adding a bounds check to verify that the parsed value is within the acceptable range for a uint32
.
The best way to fix this issue is to add a check to ensure that the uint64
value is less than or equal to math.MaxUint32
before converting it to uint32
. If the value exceeds this limit, we should handle the error appropriately.
-
Copy modified lines R554-R559
@@ -553,3 +553,8 @@ | ||
QuorumNumbers: quorums, | ||
ReferenceBlockNumber: uint32(blockNum), | ||
ReferenceBlockNumber: func() uint32 { | ||
if blockNum > math.MaxUint32 { | ||
panic(fmt.Sprintf("blockNum %d exceeds uint32 range", blockNum)) | ||
} | ||
return uint32(blockNum) | ||
}(), | ||
NonSigners: nonSigners, |
Fix ejections cli
…sThroughputTimeseriesHandler
Why are these changes needed?
Swagger needs the server handlers defined within a subpackage v1 or v2 in order to isolate handler discovery. This is a pretty big initial refactor to make that work. Subsequent refactors will happen post landing to consolidate shared handlers.
Checks