Skip to content

Commit

Permalink
Merge pull request #29 from samcm/subscription-checks
Browse files Browse the repository at this point in the history
feat(consensus): Slow down resubscribes
  • Loading branch information
samcm committed Jun 23, 2022
2 parents 353eeaa + 60ac770 commit e44c953
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions pkg/exporter/consensus/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ func (m *metrics) subscriptionLoop(ctx context.Context) {
subscribed := false

for {
if subscribed && (time.Since(m.eventMetrics.LastEventTime) > (5 * time.Minute)) {
m.log.
WithField("last_event_time", m.eventMetrics.LastEventTime.Local().String()).
Info("Haven't received any events for 5 minutes, re-subscribing")

subscribed = false
}

if !subscribed && m.client != nil {
if err := m.startSubscriptions(ctx); err != nil {
m.log.Errorf("Failed to subscribe to eth2 node: %v", err)
Expand All @@ -125,11 +133,7 @@ func (m *metrics) subscriptionLoop(ctx context.Context) {
}
}

if subscribed && time.Since(m.eventMetrics.LastEventTime) > (2*time.Minute) {
subscribed = false
}

time.Sleep(5 * time.Second)
time.Sleep(60 * time.Second)
}
}

Expand All @@ -144,6 +148,10 @@ func (m *metrics) startSubscriptions(ctx context.Context) error {
topics := []string{}

for key, supported := range v1.SupportedEventTopics {
if key == "contribution_and_proof" {
continue
}

if supported {
topics = append(topics, key)
}
Expand Down

0 comments on commit e44c953

Please sign in to comment.