Skip to content
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions go/worker/storage/statesync/diff_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ func (w *Worker) syncDiffs(
fetchPool := workerpool.New("storage_fetch/" + w.commonNode.Runtime.ID().String())
fetchPool.Resize(config.GlobalConfig.Storage.FetcherCount)
defer fetchPool.Stop()
fetchCtx, cancel := context.WithCancel(ctx)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we just do this on the top ctx, cancel := context.WithCancel(ctx)?

defer cancel()

heartbeat := heartbeat{}
heartbeat.reset()
Expand Down Expand Up @@ -179,7 +181,7 @@ func (w *Worker) syncDiffs(
return fmt.Errorf("failed to fetch missing block headers: %w", err) // Suggestion: databases can fail, consider retrying.
}

w.triggerRoundFetches(ctx, &wg, fetchPool, diffCh, syncingRounds, summaryCache, lastFullyAppliedRound+1, latestBlockRound)
w.triggerRoundFetches(fetchCtx, &wg, fetchPool, diffCh, syncingRounds, summaryCache, lastFullyAppliedRound+1, latestBlockRound)
case item := <-diffCh:
if item.err != nil {
w.logger.Error("error calling getdiff",
Expand All @@ -197,12 +199,12 @@ func (w *Worker) syncDiffs(
// Item was successfully processed, trigger more round fetches.
// This ensures that new rounds are processed as fast as possible
// when we're syncing and are far behind.
w.triggerRoundFetches(ctx, &wg, fetchPool, diffCh, syncingRounds, summaryCache, lastFullyAppliedRound+1, latestBlockRound)
w.triggerRoundFetches(fetchCtx, &wg, fetchPool, diffCh, syncingRounds, summaryCache, lastFullyAppliedRound+1, latestBlockRound)
heartbeat.reset()
case <-heartbeat.C:
if latestBlockRound != w.undefinedRound {
w.logger.Debug("heartbeat", "in_flight_rounds", len(syncingRounds))
w.triggerRoundFetches(ctx, &wg, fetchPool, diffCh, syncingRounds, summaryCache, lastFullyAppliedRound+1, latestBlockRound)
w.triggerRoundFetches(fetchCtx, &wg, fetchPool, diffCh, syncingRounds, summaryCache, lastFullyAppliedRound+1, latestBlockRound)
}
case finalized := <-finalizedCh:
if finalized.err != nil {
Expand Down