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

fest: support start/stop blocks for querying operator info(pubkey and socket) #334

Merged
merged 4 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions services/bls_aggregation/blsagg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,7 @@ func TestIntegrationBlsAgg(t *testing.T) {
avsClients.AvsRegistryChainSubscriber,
avsClients.AvsRegistryChainReader,
nil,
operatorsinfo.Opts{},
logger,
)
avsRegistryService := avsregistry.NewAvsRegistryServiceChainCaller(
Expand Down
26 changes: 18 additions & 8 deletions services/operatorsinfo/operatorsinfo_inmemory.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ type resp struct {
operatorExists bool
}

type Opts struct {
StartBlock *big.Int
StopBlock *big.Int
}

var _ OperatorsInfoService = (*OperatorsInfoServiceInMemory)(nil)

// NewOperatorsInfoServiceInMemory constructs a OperatorsInfoServiceInMemory and starts it in a goroutine.
Expand All @@ -92,6 +97,7 @@ func NewOperatorsInfoServiceInMemory(
avsRegistrySubscriber avsRegistrySubscriber,
avsRegistryReader avsRegistryReader,
logFilterQueryBlockRange *big.Int,
opts Opts,
logger logging.Logger,
) *OperatorsInfoServiceInMemory {
queryC := make(chan query)
Expand All @@ -112,7 +118,7 @@ func NewOperatorsInfoServiceInMemory(
// which requires querying the past events of the pubkey registration contract
wg := sync.WaitGroup{}
wg.Add(1)
pkcs.startServiceInGoroutine(ctx, queryC, &wg)
pkcs.startServiceInGoroutine(ctx, queryC, &wg, opts)
wg.Wait()
return pkcs
}
Expand All @@ -121,6 +127,7 @@ func (ops *OperatorsInfoServiceInMemory) startServiceInGoroutine(
ctx context.Context,
queryC <-chan query,
wg *sync.WaitGroup,
opts Opts,
) {
go func() {

Expand Down Expand Up @@ -153,7 +160,7 @@ func (ops *OperatorsInfoServiceInMemory) startServiceInGoroutine(
)
panic(err)
}
err = ops.queryPastRegisteredOperatorEventsAndFillDb(ctx)
err = ops.queryPastRegisteredOperatorEventsAndFillDb(ctx, opts)
if err != nil {
ops.logger.Error(
"Fatal error querying past registered operator events and filling db",
Expand Down Expand Up @@ -275,7 +282,10 @@ func (ops *OperatorsInfoServiceInMemory) startServiceInGoroutine(
}()
}

func (ops *OperatorsInfoServiceInMemory) queryPastRegisteredOperatorEventsAndFillDb(ctx context.Context) error {
func (ops *OperatorsInfoServiceInMemory) queryPastRegisteredOperatorEventsAndFillDb(
ctx context.Context,
opts Opts,
) error {
// Querying with nil startBlock and stopBlock will return all events. It doesn't matter if we query some events that
// we will receive again in the websocket,
// since we will just overwrite the pubkey dict with the same values.
Expand All @@ -290,8 +300,8 @@ func (ops *OperatorsInfoServiceInMemory) queryPastRegisteredOperatorEventsAndFil
go func() {
alreadyRegisteredOperatorAddrs, alreadyRegisteredOperatorPubkeys, pubkeysErr = ops.avsRegistryReader.QueryExistingRegisteredOperatorPubKeys(
ctx,
nil,
nil,
opts.StartBlock,
opts.StopBlock,
Comment on lines +303 to +304
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will panic if nil is passed as opts. Can we change opts to be Opts instead of *Opts?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in every function

ops.logFilterQueryBlockRange,
)
wg.Done()
Expand All @@ -301,8 +311,8 @@ func (ops *OperatorsInfoServiceInMemory) queryPastRegisteredOperatorEventsAndFil
go func() {
socketsMap, socketsErr = ops.avsRegistryReader.QueryExistingRegisteredOperatorSockets(
ctx,
nil,
nil,
opts.StartBlock,
opts.StopBlock,
ops.logFilterQueryBlockRange,
)
wg.Done()
Expand All @@ -328,7 +338,7 @@ func (ops *OperatorsInfoServiceInMemory) queryPastRegisteredOperatorEventsAndFil
// we print each socket info on a separate line because slog for some reason doesn't pass map keys via their
// LogValue() function, so operatorId (of custom type Bytes32) prints as a byte array instead of its hex
// representation from LogValue()
// passing the Bytes32 directly to an slog log statements does call LogValue() and prints the hex representation
// passing the Bytes32 directly to a slog log statements does call LogValue() and prints the hex representation
ops.logger.Debug(
"operator socket returned from registration events query",
"operatorId",
Expand Down
1 change: 1 addition & 0 deletions services/operatorsinfo/operatorsinfo_inmemory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ func TestGetOperatorInfo(t *testing.T) {
mockAvsRegistrySubscriber,
mockAvsReader,
nil,
Opts{},
logger,
)
time.Sleep(
Expand Down