diff --git a/chainio/clients/avsregistry/reader.go b/chainio/clients/avsregistry/reader.go index f508e137..3f13d8f2 100644 --- a/chainio/clients/avsregistry/reader.go +++ b/chainio/clients/avsregistry/reader.go @@ -429,7 +429,12 @@ func (r *ChainReader) QueryExistingRegisteredOperatorPubKeys( operatorAddresses := make([]types.OperatorAddr, 0) operatorPubkeys := make([]types.OperatorPubkeys, 0) - for i := startBlock; i.Cmp(stopBlock) <= 0; i.Add(i, blockRange) { + // QueryExistingRegisteredOperatorPubKeys and QueryExistingRegisteredOperatorSockets + // both run in parallel and they read and mutate the same variable startBlock, + // so we clone it to prevent the race condition. + // TODO: we might want to eventually change the function signature to pass a uint, + // but that would be a breaking change + for i := new(big.Int).Set(startBlock); i.Cmp(stopBlock) <= 0; i.Add(i, blockRange) { // Subtract 1 since FilterQuery is inclusive toBlock := big.NewInt(0).Add(i, big.NewInt(0).Sub(blockRange, big.NewInt(1))) if toBlock.Cmp(stopBlock) > 0 { @@ -521,7 +526,12 @@ func (r *ChainReader) QueryExistingRegisteredOperatorSockets( } operatorIdToSocketMap := make(map[types.OperatorId]types.Socket) - for i := startBlock; i.Cmp(stopBlock) <= 0; i.Add(i, blockRange) { + // QueryExistingRegisteredOperatorPubKeys and QueryExistingRegisteredOperatorSockets + // both run in parallel and they read and mutate the same variable startBlock, + // so we clone it to prevent the race condition. + // TODO: we might want to eventually change the function signature to pass a uint, + // but that would be a breaking change + for i := new(big.Int).Set(startBlock); i.Cmp(stopBlock) <= 0; i.Add(i, blockRange) { // Subtract 1 since FilterQuery is inclusive toBlock := big.NewInt(0).Add(i, big.NewInt(0).Sub(blockRange, big.NewInt(1))) if toBlock.Cmp(stopBlock) > 0 {