Skip to content

Commit

Permalink
fix: duplicate operatorAddresses, operatorPubkeys caused by inclusive…
Browse files Browse the repository at this point in the history
… FilterQuery (#221)

* fix: duplicate operatorAddresses, operatorPubkeys caused by inclusive nature of FilterQuery(fromBlock,toBlock)

* refactor: moved comment for QueryBlockRange
  • Loading branch information
taco-paco authored Apr 30, 2024
1 parent e0f394a commit feeb72b
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions chainio/clients/avsregistry/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import (
stakeregistry "github.com/Layr-Labs/eigensdk-go/contracts/bindings/StakeRegistry"
)

// eth_getLogs is limited to a 10,000 range, so we need to iterate over the range
const QueryBlockRange = 10_000

type AvsRegistryReader interface {
GetQuorumCount(opts *bind.CallOpts) (uint8, error)

Expand Down Expand Up @@ -366,7 +369,6 @@ func (r *AvsRegistryChainReader) QueryExistingRegisteredOperatorPubKeys(
startBlock *big.Int,
stopBlock *big.Int,
) ([]types.OperatorAddr, []types.OperatorPubkeys, error) {

blsApkRegistryAbi, err := apkreg.ContractBLSApkRegistryMetaData.GetAbi()
if err != nil {
return nil, nil, utils.WrapError("Cannot get Abi", err)
Expand All @@ -385,10 +387,9 @@ func (r *AvsRegistryChainReader) QueryExistingRegisteredOperatorPubKeys(

operatorAddresses := make([]types.OperatorAddr, 0)
operatorPubkeys := make([]types.OperatorPubkeys, 0)

// eth_getLogs is limited to a 10,000 range, so we need to iterate over the range
for i := startBlock; i.Cmp(stopBlock) <= 0; i.Add(i, big.NewInt(10_000)) {
toBlock := big.NewInt(0).Add(i, big.NewInt(10_000))
for i := startBlock; i.Cmp(stopBlock) <= 0; i.Add(i, big.NewInt(QueryBlockRange)) {
// Subtract 1 since FilterQuery is inclusive
toBlock := big.NewInt(0).Add(i, big.NewInt(QueryBlockRange-1))
if toBlock.Cmp(stopBlock) > 0 {
toBlock = stopBlock
}
Expand Down Expand Up @@ -416,7 +417,6 @@ func (r *AvsRegistryChainReader) QueryExistingRegisteredOperatorPubKeys(
)

for _, vLog := range logs {

// get the operator address
operatorAddr := gethcommon.HexToAddress(vLog.Topics[1].Hex())
operatorAddresses = append(operatorAddresses, operatorAddr)
Expand Down Expand Up @@ -448,7 +448,6 @@ func (r *AvsRegistryChainReader) QueryExistingRegisteredOperatorPubKeys(
}

operatorPubkeys = append(operatorPubkeys, operatorPubkey)

}
}

Expand All @@ -473,10 +472,9 @@ func (r *AvsRegistryChainReader) QueryExistingRegisteredOperatorSockets(
}

operatorIdToSocketMap := make(map[types.OperatorId]types.Socket)

// eth_getLogs is limited to a 10,000 range, so we need to iterate over the range
for i := startBlock; i.Cmp(stopBlock) <= 0; i.Add(i, big.NewInt(10_000)) {
toBlock := big.NewInt(0).Add(i, big.NewInt(10_000))
for i := startBlock; i.Cmp(stopBlock) <= 0; i.Add(i, big.NewInt(QueryBlockRange)) {
// Subtract 1 since FilterQuery is inclusive
toBlock := big.NewInt(0).Add(i, big.NewInt(QueryBlockRange-1))
if toBlock.Cmp(stopBlock) > 0 {
toBlock = stopBlock
}
Expand Down

0 comments on commit feeb72b

Please sign in to comment.