Skip to content

Commit

Permalink
fest: support start/stop blocks for querying operator info(pubkey and…
Browse files Browse the repository at this point in the history
… socket) (#334)

* feat: support start/stop block number for querying operator info

* refactor: use Opts struct

* refactor: use struct instead of pointer to avoid panic
  • Loading branch information
renlulu authored Sep 5, 2024
1 parent 6f4461d commit a1011f6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
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,
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

0 comments on commit a1011f6

Please sign in to comment.