Skip to content

Commit

Permalink
fix: duplicate operatorAddresses, operatorPubkeys caused by inclusive…
Browse files Browse the repository at this point in the history
… nature of FilterQuery(fromBlock,toBlock)
  • Loading branch information
taco-paco committed Apr 29, 2024
1 parent 954cd76 commit 7c211e1
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions chainio/clients/avsregistry/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
stakeregistry "github.com/Layr-Labs/eigensdk-go/contracts/bindings/StakeRegistry"
)

const QueryBlockRange = 10_000

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

Expand Down Expand Up @@ -363,7 +365,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, types.WrapError(errors.New("Cannot get Abi"), err)
Expand All @@ -384,8 +385,9 @@ func (r *AvsRegistryChainReader) QueryExistingRegisteredOperatorPubKeys(
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 All @@ -405,7 +407,6 @@ func (r *AvsRegistryChainReader) QueryExistingRegisteredOperatorPubKeys(
r.logger.Debug("avsRegistryChainReader.QueryExistingRegisteredOperatorPubKeys", "numTransactionLogs", len(logs), "fromBlock", i, "toBlock", toBlock)

for _, vLog := range logs {

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

operatorPubkeys = append(operatorPubkeys, operatorPubkey)

}
}

Expand All @@ -464,8 +464,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 7c211e1

Please sign in to comment.