From 081b055553e43384653fac79e839cf21d580cde0 Mon Sep 17 00:00:00 2001 From: Marcin Gorzynski Date: Mon, 15 Apr 2024 17:02:34 +0200 Subject: [PATCH] do not retry streaming is streaming is not enabled --- ethmonitor/ethmonitor.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/ethmonitor/ethmonitor.go b/ethmonitor/ethmonitor.go index 8a325582..0d82db5a 100644 --- a/ethmonitor/ethmonitor.go +++ b/ethmonitor/ethmonitor.go @@ -377,17 +377,25 @@ func (m *Monitor) listenNewHead() <-chan uint64 { retryStreamingTimer := time.NewTimer(m.options.StreamingRetryAfter) for { + // if streaming is enabled, we'll retry streaming + if m.provider.IsStreamingEnabled() { + select { + case <-retryStreamingTimer.C: + // retry streaming + m.log.Info("ethmonitor: retrying streaming...") + goto reconnect + default: + // non-blocking + } + } + + // Polling mode, where we poll for the latest block number select { case <-m.ctx.Done(): // if we're done, we'll close the nextBlock channel close(nextBlock) return - case <-retryStreamingTimer.C: - // retry streaming - m.log.Info("ethmonitor: retrying streaming...") - goto reconnect - case <-time.After(time.Duration(m.pollInterval.Load())): nextBlock <- 0 }