Skip to content

Commit d76fa6b

Browse files
committed
revert go routines
1 parent 1ea89ba commit d76fa6b

File tree

1 file changed

+7
-79
lines changed

1 file changed

+7
-79
lines changed

cmd/monitor/monitor.go

+7-79
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"math/big"
88
"os"
99
"os/signal"
10+
"strings"
1011
"sync"
1112
"syscall"
1213
"time"
@@ -350,9 +351,12 @@ func (ms *monitorStatus) processBatchesConcurrently(ctx context.Context, rpc *et
350351
b := backoff.NewExponentialBackOff()
351352
b.MaxElapsedTime = 3 * time.Minute
352353
retryable := func() error {
353-
if err := rpc.BatchCallContext(ctx, subBatch); err != nil {
354-
log.Error().Err(err).Msg("Error when performing batch calls")
355-
return backoff.Permanent(err)
354+
err := rpc.BatchCallContext(ctx, subBatch)
355+
if err != nil {
356+
log.Error().Err(err).Msg("BatchCallContext error - retry loop")
357+
if strings.Contains(err.Error(), "limit") {
358+
return backoff.Permanent(err)
359+
}
356360
}
357361
return nil
358362
}
@@ -383,82 +387,6 @@ func (ms *monitorStatus) processBatchesConcurrently(ctx context.Context, rpc *et
383387
return errors.Join(errs...)
384388
}
385389

386-
func (ms *monitorStatus) processBatchesConcurrently(ctx context.Context, rpc *ethrpc.Client, blms []ethrpc.BatchElem) error {
387-
var wg sync.WaitGroup
388-
var errs []error = make([]error, 0)
389-
var errorsMutex sync.Mutex
390-
391-
for i := 0; i < len(blms); i += subBatchSize {
392-
semaphore <- struct{}{}
393-
wg.Add(1)
394-
go func(i int) {
395-
defer func() {
396-
<-semaphore
397-
wg.Done()
398-
}()
399-
end := i + subBatchSize
400-
if end > len(blms) {
401-
end = len(blms)
402-
}
403-
subBatch := blms[i:end]
404-
405-
doneCh := make(chan error, 1)
406-
407-
go func() {
408-
b := backoff.NewExponentialBackOff()
409-
b.MaxElapsedTime = 3 * time.Minute
410-
retryable := func() error {
411-
select {
412-
case <-ctx.Done():
413-
log.Error().Err(ctx.Err()).Msg("WE ARE HERE")
414-
return ctx.Err()
415-
default:
416-
err := rpc.BatchCallContext(ctx, subBatch)
417-
if err != nil {
418-
log.Error().Err(err).Msg("BatchCallContext error - retry loop")
419-
// if strings.Contains(err.Error(), "limit") {
420-
// return backoff.Permanent(err)
421-
// }
422-
}
423-
return err
424-
}
425-
}
426-
err := backoff.Retry(retryable, b)
427-
doneCh <- err
428-
}()
429-
430-
select {
431-
case <-ctx.Done():
432-
return
433-
case err := <-doneCh:
434-
if err != nil {
435-
log.Error().Err(err).Msg("unable to retry")
436-
errorsMutex.Lock()
437-
errs = append(errs, err)
438-
errorsMutex.Unlock()
439-
return
440-
}
441-
442-
for _, elem := range subBatch {
443-
if elem.Error != nil {
444-
log.Error().Str("Method", elem.Method).Interface("Args", elem.Args).Err(elem.Error).Msg("Failed batch element")
445-
} else {
446-
pb := rpctypes.NewPolyBlock(elem.Result.(*rpctypes.RawBlockResponse))
447-
ms.BlocksLock.Lock()
448-
ms.BlockCache.Add(pb.Number().String(), pb)
449-
ms.BlocksLock.Unlock()
450-
}
451-
}
452-
}
453-
454-
}(i)
455-
}
456-
457-
wg.Wait()
458-
459-
return errors.Join(errs...)
460-
}
461-
462390
func renderMonitorUI(ctx context.Context, ec *ethclient.Client, ms *monitorStatus, rpc *ethrpc.Client) error {
463391
if err := termui.Init(); err != nil {
464392
log.Error().Err(err).Msg("Failed to initialize UI")

0 commit comments

Comments
 (0)