From b20cdbe399ec33266dba1757ead924010342ce30 Mon Sep 17 00:00:00 2001 From: ledgerwatch <akhounov@gmail.com> Date: Thu, 4 Jun 2020 12:34:22 +0100 Subject: [PATCH] Enable staged sync (#618) --- eth/stagedsync/stage_headers.go | 68 ++++++++++++++++----------------- 1 file changed, 33 insertions(+), 35 deletions(-) diff --git a/eth/stagedsync/stage_headers.go b/eth/stagedsync/stage_headers.go index deee2dfd3b..0f7294677b 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 -- GitLab