diff --git a/eth/stagedsync/stage_headers.go b/eth/stagedsync/stage_headers.go index deee2dfd3bceca580d2f1d4907f050f690c5ed03..0f7294677b5e44dd3b5a3b3850fe2e319db32556 100644 --- a/eth/stagedsync/stage_headers.go +++ b/eth/stagedsync/stage_headers.go @@ -10,47 +10,45 @@ import ( ) func DownloadHeaders(s *StageState, d DownloaderGlue, stateDB ethdb.Database, headersFetchers []func() error, quitCh chan struct{}) error { - if false { - err := d.SpawnSync(headersFetchers) + err := d.SpawnSync(headersFetchers) + if err != nil { + return err + } + + log.Info("Checking for unwinding...") + // Check unwinds backwards and if they are outstanding, invoke corresponding functions + for stage := stages.Finish - 1; stage > stages.Headers; stage-- { + unwindPoint, err := stages.GetStageUnwind(stateDB, stage) if err != nil { return err } - log.Info("Checking for unwinding...") - // Check unwinds backwards and if they are outstanding, invoke corresponding functions - for stage := stages.Finish - 1; stage > stages.Headers; stage-- { - unwindPoint, err := stages.GetStageUnwind(stateDB, stage) - if err != nil { - return err - } - - if unwindPoint == 0 { - continue - } - - switch stage { - case stages.Bodies: - err = unwindBodyDownloadStage(stateDB, unwindPoint) - case stages.Senders: - err = unwindSendersStage(stateDB, unwindPoint) - case stages.Execution: - err = unwindExecutionStage(unwindPoint, stateDB) - case stages.HashCheck: - err = unwindHashCheckStage(unwindPoint, stateDB) - case stages.AccountHistoryIndex: - err = unwindAccountHistoryIndex(unwindPoint, stateDB, core.UsePlainStateExecution, quitCh) - case stages.StorageHistoryIndex: - err = unwindStorageHistoryIndex(unwindPoint, stateDB, core.UsePlainStateExecution, quitCh) - default: - return fmt.Errorf("unrecognized stage for unwinding: %d", stage) - } - - if err != nil { - return fmt.Errorf("error unwinding stage: %d: %w", stage, err) - } + if unwindPoint == 0 { + continue + } + + switch stage { + case stages.Bodies: + err = unwindBodyDownloadStage(stateDB, unwindPoint) + case stages.Senders: + err = unwindSendersStage(stateDB, unwindPoint) + case stages.Execution: + err = unwindExecutionStage(unwindPoint, stateDB) + case stages.HashCheck: + err = unwindHashCheckStage(unwindPoint, stateDB) + case stages.AccountHistoryIndex: + err = unwindAccountHistoryIndex(unwindPoint, stateDB, core.UsePlainStateExecution, quitCh) + case stages.StorageHistoryIndex: + err = unwindStorageHistoryIndex(unwindPoint, stateDB, core.UsePlainStateExecution, quitCh) + default: + return fmt.Errorf("unrecognized stage for unwinding: %d", stage) + } + + if err != nil { + return fmt.Errorf("error unwinding stage: %d: %w", stage, err) } - log.Info("Checking for unwinding... Complete!") } + log.Info("Checking for unwinding... Complete!") s.Done() return nil