11package chainio
22
33import (
4+ "fmt"
5+ "time"
6+
47 "github.com/ethereum/go-ethereum/accounts/abi/bind"
58 "github.com/ethereum/go-ethereum/event"
69 servicemanager "github.com/yetanotherco/aligned_layer/contracts/bindings/AlignedLayerServiceManager"
@@ -9,6 +12,11 @@ import (
912 sdklogging "github.com/Layr-Labs/eigensdk-go/logging"
1013)
1114
15+ const (
16+ MaxRetries = 100
17+ RetryInterval = 1 * time .Second
18+ )
19+
1220// NOTE(marian): Leaving this commented code here as it may be useful in the short term.
1321// type AvsSubscriberer interface {
1422// SubscribeToNewTasks(newTaskCreatedChan chan *cstaskmanager.ContractAlignedLayerTaskManagerNewTaskCreated) event.Subscription
@@ -42,15 +50,22 @@ func NewAvsSubscriberFromConfig(baseConfig *config.BaseConfig) (*AvsSubscriber,
4250 }, nil
4351}
4452
45- func (s * AvsSubscriber ) SubscribeToNewTasks (newTaskCreatedChan chan * servicemanager.ContractAlignedLayerServiceManagerNewBatch ) event.Subscription {
46- sub , err := s .AvsContractBindings .ServiceManager .WatchNewBatch (
47- & bind.WatchOpts {}, newTaskCreatedChan , nil ,
48- )
49- if err != nil {
50- s .logger .Error ("Failed to subscribe to new AlignedLayer tasks" , "err" , err )
53+ func (s * AvsSubscriber ) SubscribeToNewTasks (newTaskCreatedChan chan * servicemanager.ContractAlignedLayerServiceManagerNewBatch ) (event.Subscription , error ) {
54+ for i := 0 ; i < MaxRetries ; i ++ {
55+ sub , err := s .AvsContractBindings .ServiceManager .WatchNewBatch (
56+ & bind.WatchOpts {}, newTaskCreatedChan , nil ,
57+ )
58+ if err != nil {
59+ s .logger .Warn ("Failed to subscribe to new AlignedLayer tasks" , "err" , err )
60+ time .Sleep (RetryInterval )
61+ continue
62+ }
63+
64+ s .logger .Info ("Subscribed to new AlignedLayer tasks" )
65+ return sub , nil
5166 }
52- s . logger . Infof ( "Subscribed to new AlignedLayer tasks" )
53- return sub
67+
68+ return nil , fmt . Errorf ( "Failed to subscribe to new AlignedLayer tasks after %d retries" , MaxRetries )
5469}
5570
5671// func (s *AvsSubscriber) SubscribeToTaskResponses(taskResponseChan chan *cstaskmanager.ContractAlignedLayerTaskManagerTaskResponded) event.Subscription {
0 commit comments