From a1011f69357a51655752ea809753c4612b73a6cc Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Thu, 5 Sep 2024 09:32:22 +0800 Subject: [PATCH] fest: support start/stop blocks for querying operator info(pubkey and 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 --- services/bls_aggregation/blsagg_test.go | 1 + .../operatorsinfo/operatorsinfo_inmemory.go | 26 +++++++++++++------ .../operatorsinfo_inmemory_test.go | 1 + 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/services/bls_aggregation/blsagg_test.go b/services/bls_aggregation/blsagg_test.go index 40fa992f..b247c91d 100644 --- a/services/bls_aggregation/blsagg_test.go +++ b/services/bls_aggregation/blsagg_test.go @@ -1150,6 +1150,7 @@ func TestIntegrationBlsAgg(t *testing.T) { avsClients.AvsRegistryChainSubscriber, avsClients.AvsRegistryChainReader, nil, + operatorsinfo.Opts{}, logger, ) avsRegistryService := avsregistry.NewAvsRegistryServiceChainCaller( diff --git a/services/operatorsinfo/operatorsinfo_inmemory.go b/services/operatorsinfo/operatorsinfo_inmemory.go index b5b43deb..c2874b92 100644 --- a/services/operatorsinfo/operatorsinfo_inmemory.go +++ b/services/operatorsinfo/operatorsinfo_inmemory.go @@ -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. @@ -92,6 +97,7 @@ func NewOperatorsInfoServiceInMemory( avsRegistrySubscriber avsRegistrySubscriber, avsRegistryReader avsRegistryReader, logFilterQueryBlockRange *big.Int, + opts Opts, logger logging.Logger, ) *OperatorsInfoServiceInMemory { queryC := make(chan query) @@ -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 } @@ -121,6 +127,7 @@ func (ops *OperatorsInfoServiceInMemory) startServiceInGoroutine( ctx context.Context, queryC <-chan query, wg *sync.WaitGroup, + opts Opts, ) { go func() { @@ -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", @@ -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. @@ -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() @@ -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() @@ -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", diff --git a/services/operatorsinfo/operatorsinfo_inmemory_test.go b/services/operatorsinfo/operatorsinfo_inmemory_test.go index c3e473a0..041b5af9 100644 --- a/services/operatorsinfo/operatorsinfo_inmemory_test.go +++ b/services/operatorsinfo/operatorsinfo_inmemory_test.go @@ -153,6 +153,7 @@ func TestGetOperatorInfo(t *testing.T) { mockAvsRegistrySubscriber, mockAvsReader, nil, + Opts{}, logger, ) time.Sleep(