All stages - finish fast if current progress > target (#1773)

This commit is contained in:
Alex Sharov 2021-05-01 17:08:59 +07:00 committed by GitHub
parent aacc457ea8
commit df8c5e3095
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 23 deletions

View File

@ -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)

View File

@ -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
}

View File

@ -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)

View File

@ -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)
},
}
},

View File

@ -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 {