Skip to content

Commit

Permalink
allow to gracefully exit from CL downloading stage (#10887) (#11020)
Browse files Browse the repository at this point in the history
Duplicating #10887

Co-authored-by: awskii <[email protected]>
  • Loading branch information
VBulikov and awskii authored Jul 4, 2024
1 parent 1a050db commit eb7db79
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
8 changes: 3 additions & 5 deletions cl/clstages/clstages.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,12 @@ func (s *StageGraph[CONFIG, ARGUMENTS]) StartWithStage(ctx context.Context, star
errch := make(chan error)
start := time.Now()
go func() {
sctx, cn := context.WithCancel(ctx)
defer cn()
// we run this is a goroutine so that the process can exit in the middle of a stage
// since caplin is designed to always be able to recover regardless of db state, this should be safe
select {
case errch <- currentStage.ActionFunc(sctx, lg, cfg, args):
case <-sctx.Done():
errch <- sctx.Err()
case errch <- currentStage.ActionFunc(ctx, lg, cfg, args):
case <-ctx.Done(): // we are not sure if actionFunc exits on ctx
errch <- ctx.Err()
}
}()
err := <-errch
Expand Down
2 changes: 1 addition & 1 deletion cl/phase1/stages/clstages.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func ConsensusClStages(ctx context.Context,
}
// This stage is special so use context.Background() TODO(Giulio2002): make the context be passed in
startingSlot := cfg.state.LatestBlockHeader().Slot
downloader := network2.NewBackwardBeaconDownloader(context.Background(), cfg.rpc, cfg.executionClient, cfg.indiciesDB)
downloader := network2.NewBackwardBeaconDownloader(ctx, cfg.rpc, cfg.executionClient, cfg.indiciesDB)

if err := SpawnStageHistoryDownload(StageHistoryReconstruction(downloader, cfg.antiquary, cfg.sn, cfg.indiciesDB, cfg.executionClient, cfg.beaconCfg, cfg.backfilling, cfg.blobBackfilling, false, startingRoot, startingSlot, cfg.tmpdir, 600*time.Millisecond, cfg.blockCollector, cfg.blockReader, cfg.blobStore, logger), context.Background(), logger); err != nil {
cfg.hasDownloaded = false
Expand Down

0 comments on commit eb7db79

Please sign in to comment.