Skip to content
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

Optimize the batch operatorId to address lookup #533

Merged
merged 3 commits into from
May 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 11 additions & 29 deletions core/eth/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/Layr-Labs/eigenda/common"
"github.com/Layr-Labs/eigenda/core"
"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/gammazero/workerpool"
"github.com/pingcap/errors"

avsdir "github.com/Layr-Labs/eigenda/contracts/bindings/AVSDirectory"
Expand All @@ -33,8 +32,7 @@ import (
)

var (
maxNumberOfQuorums = 192
maxNumWorkerPoolThreads = 8
maxNumberOfQuorums = 192
)

type Transactor struct {
Expand Down Expand Up @@ -574,32 +572,16 @@ func (t *Transactor) OperatorAddressToID(ctx context.Context, address gethcommon
}

func (t *Transactor) BatchOperatorIDToAddress(ctx context.Context, operatorIds []core.OperatorID) ([]gethcommon.Address, error) {
type AddressOrError struct {
address gethcommon.Address
index int
err error
}
resultChan := make(chan AddressOrError, len(operatorIds))
pool := workerpool.New(maxNumWorkerPoolThreads)
for i, operatorId := range operatorIds {
idx := i
op := operatorId
pool.Submit(func() {
addr, err := t.Bindings.BLSApkRegistry.PubkeyHashToOperator(&bind.CallOpts{
Context: ctx,
}, op)
resultChan <- AddressOrError{address: addr, index: idx, err: err}
})
}
pool.StopWait()
close(resultChan)

addresses := make([]gethcommon.Address, len(operatorIds))
for result := range resultChan {
if result.err != nil {
return nil, result.err
}
addresses[result.index] = result.address
byteIds := make([][32]byte, len(operatorIds))
for i, id := range operatorIds {
byteIds[i] = [32]byte(id)
}
addresses, err := t.Bindings.OpStateRetriever.GetBatchOperatorFromId(&bind.CallOpts{
Context: ctx,
}, t.Bindings.RegCoordinatorAddr, byteIds)
if err != nil {
t.Logger.Error("Failed to get operator address in batch", "err", err)
return nil, err
}
return addresses, nil
}
Expand Down
Loading