From e647e5fe3b7fcc90bf8894481503a4c0dc70d684 Mon Sep 17 00:00:00 2001 From: Alex Sharov Date: Sun, 12 Feb 2023 16:24:16 +0700 Subject: [PATCH] e3: reduce buildIndex ctx scope (#889) --- state/aggregator_v3.go | 50 ++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/state/aggregator_v3.go b/state/aggregator_v3.go index 033acb0ac..c9c630185 100644 --- a/state/aggregator_v3.go +++ b/state/aggregator_v3.go @@ -215,31 +215,33 @@ func (a *AggregatorV3) BuildOptionalMissedIndices(ctx context.Context, workers i } func (a *AggregatorV3) BuildMissedIndices(ctx context.Context, sem *semaphore.Weighted) error { - g, ctx := errgroup.WithContext(ctx) - if a.accounts != nil { - g.Go(func() error { return a.accounts.BuildMissedIndices(ctx, sem) }) - } - if a.storage != nil { - g.Go(func() error { return a.storage.BuildMissedIndices(ctx, sem) }) - } - if a.code != nil { - g.Go(func() error { return a.code.BuildMissedIndices(ctx, sem) }) - } - if a.logAddrs != nil { - g.Go(func() error { return a.logAddrs.BuildMissedIndices(ctx, sem) }) - } - if a.logTopics != nil { - g.Go(func() error { return a.logTopics.BuildMissedIndices(ctx, sem) }) - } - if a.tracesFrom != nil { - g.Go(func() error { return a.tracesFrom.BuildMissedIndices(ctx, sem) }) - } - if a.tracesTo != nil { - g.Go(func() error { return a.tracesTo.BuildMissedIndices(ctx, sem) }) - } + { + g, ctx := errgroup.WithContext(ctx) + if a.accounts != nil { + g.Go(func() error { return a.accounts.BuildMissedIndices(ctx, sem) }) + } + if a.storage != nil { + g.Go(func() error { return a.storage.BuildMissedIndices(ctx, sem) }) + } + if a.code != nil { + g.Go(func() error { return a.code.BuildMissedIndices(ctx, sem) }) + } + if a.logAddrs != nil { + g.Go(func() error { return a.logAddrs.BuildMissedIndices(ctx, sem) }) + } + if a.logTopics != nil { + g.Go(func() error { return a.logTopics.BuildMissedIndices(ctx, sem) }) + } + if a.tracesFrom != nil { + g.Go(func() error { return a.tracesFrom.BuildMissedIndices(ctx, sem) }) + } + if a.tracesTo != nil { + g.Go(func() error { return a.tracesTo.BuildMissedIndices(ctx, sem) }) + } - if err := g.Wait(); err != nil { - return err + if err := g.Wait(); err != nil { + return err + } } return a.BuildOptionalMissedIndices(ctx, 4) }