From df8c5e30957066c65f7efb2b936af3803d749d55 Mon Sep 17 00:00:00 2001 From: Alex Sharov Date: Sat, 1 May 2021 17:08:59 +0700 Subject: [PATCH] All stages - finish fast if current progress > target (#1773) --- eth/stagedsync/stage_finish.go | 5 +++++ eth/stagedsync/stage_indexes.go | 4 ++-- eth/stagedsync/stage_txpool.go | 5 +++++ eth/stagedsync/stagebuilder.go | 23 ++--------------------- eth/stagedsync/state.go | 1 + 5 files changed, 15 insertions(+), 23 deletions(-) diff --git a/eth/stagedsync/stage_finish.go b/eth/stagedsync/stage_finish.go index f5420dfae..c75b27824 100644 --- a/eth/stagedsync/stage_finish.go +++ b/eth/stagedsync/stage_finish.go @@ -14,6 +14,11 @@ func FinishForward(s *StageState, db ethdb.Database, notifier ChainEventNotifier if executionAt, err = s.ExecutionAt(db); err != nil { return err } + if executionAt <= s.BlockNumber { + s.Done() + return nil + } + logPrefix := s.state.LogPrefix() log.Info(fmt.Sprintf("[%s] Update current block for the RPC API", logPrefix), "to", executionAt) diff --git a/eth/stagedsync/stage_indexes.go b/eth/stagedsync/stage_indexes.go index 478432299..5c99c3867 100644 --- a/eth/stagedsync/stage_indexes.go +++ b/eth/stagedsync/stage_indexes.go @@ -55,7 +55,7 @@ func SpawnAccountHistoryIndex(s *StageState, db ethdb.Database, cfg HistoryCfg, if err != nil { return fmt.Errorf("%s: getting last executed block: %w", logPrefix, err) } - if executionAt == s.BlockNumber { + if executionAt <= s.BlockNumber { s.Done() return nil } @@ -102,7 +102,7 @@ func SpawnStorageHistoryIndex(s *StageState, db ethdb.Database, cfg HistoryCfg, if err != nil { return fmt.Errorf("%s: logs index: getting last executed block: %w", logPrefix, err) } - if executionAt == s.BlockNumber { + if executionAt <= s.BlockNumber { s.Done() return nil } diff --git a/eth/stagedsync/stage_txpool.go b/eth/stagedsync/stage_txpool.go index 37684a41f..448fada14 100644 --- a/eth/stagedsync/stage_txpool.go +++ b/eth/stagedsync/stage_txpool.go @@ -42,6 +42,11 @@ func SpawnTxPool(s *StageState, db ethdb.Database, cfg TxPoolCfg, quitCh <-chan if err != nil { return err } + if to == s.BlockNumber { + s.Done() + return nil + } + logPrefix := s.state.LogPrefix() if to < s.BlockNumber { return fmt.Errorf("%s: to (%d) < from (%d)", logPrefix, to, s.BlockNumber) diff --git a/eth/stagedsync/stagebuilder.go b/eth/stagedsync/stagebuilder.go index 764bac1aa..e915005da 100644 --- a/eth/stagedsync/stagebuilder.go +++ b/eth/stagedsync/stagebuilder.go @@ -12,7 +12,6 @@ import ( "github.com/ledgerwatch/turbo-geth/core/vm" "github.com/ledgerwatch/turbo-geth/eth/stagedsync/stages" "github.com/ledgerwatch/turbo-geth/ethdb" - "github.com/ledgerwatch/turbo-geth/log" "github.com/ledgerwatch/turbo-geth/params" "github.com/ledgerwatch/turbo-geth/turbo/stages/bodydownload" ) @@ -344,28 +343,10 @@ func DefaultStages() StageBuilders { ID: stages.Finish, Description: "Final: update current block for the RPC API", ExecFunc: func(s *StageState, _ Unwinder) error { - var executionAt uint64 - var err error - if executionAt, err = s.ExecutionAt(world.DB); err != nil { - return err - } - logPrefix := s.state.LogPrefix() - log.Info(fmt.Sprintf("[%s] Update current block for the RPC API", logPrefix), "to", executionAt) - - err = NotifyNewHeaders(s.BlockNumber+1, executionAt, world.notifier, world.DB) - if err != nil { - return err - } - - return s.DoneAndUpdate(world.DB, executionAt) + return FinishForward(s, world.DB, world.notifier) }, UnwindFunc: func(u *UnwindState, s *StageState) error { - var executionAt uint64 - var err error - if executionAt, err = s.ExecutionAt(world.DB); err != nil { - return err - } - return s.DoneAndUpdate(world.DB, executionAt) + return UnwindFinish(u, s, world.DB) }, } }, diff --git a/eth/stagedsync/state.go b/eth/stagedsync/state.go index e74bc7023..585211dd0 100644 --- a/eth/stagedsync/state.go +++ b/eth/stagedsync/state.go @@ -174,6 +174,7 @@ func (s *State) Run(db ethdb.GetterPutter, tx ethdb.GetterPutter) error { return err } } + _, stage := s.CurrentStage() if hook, ok := s.beforeStageRun[string(stage.ID)]; ok { if err := hook(); err != nil {