diff --git a/api/service/stagedstreamsync/adapter.go b/api/service/stagedstreamsync/adapter.go index 9988ccc51..ca9c6a678 100644 --- a/api/service/stagedstreamsync/adapter.go +++ b/api/service/stagedstreamsync/adapter.go @@ -31,6 +31,6 @@ type blockChain interface { engine.ChainReader Engine() engine.Engine - InsertChain(chain types.Blocks, verifyHeaders bool, blockExecution bool) (int, error) + InsertChain(chain types.Blocks, verifyHeaders bool) (int, error) WriteCommitSig(blockNum uint64, lastCommits []byte) error } diff --git a/api/service/stagedstreamsync/sig_verify.go b/api/service/stagedstreamsync/sig_verify.go index bc204fb1a..bdf5a2107 100644 --- a/api/service/stagedstreamsync/sig_verify.go +++ b/api/service/stagedstreamsync/sig_verify.go @@ -20,9 +20,9 @@ func (e *sigVerifyErr) Error() string { return fmt.Sprintf("[VerifyHeaderSignature] %v", e.err.Error()) } -func verifyAndInsertBlocks(bc blockChain, blocks types.Blocks, blockExecution bool) (int, error) { +func verifyAndInsertBlocks(bc blockChain, blocks types.Blocks) (int, error) { for i, block := range blocks { - if err := verifyAndInsertBlock(bc, block, blockExecution, blocks[i+1:]...); err != nil { + if err := verifyAndInsertBlock(bc, block, blocks[i+1:]...); err != nil { return i, err } } @@ -65,13 +65,13 @@ func verifyBlock(bc blockChain, block *types.Block, nextBlocks ...*types.Block) return nil } -func verifyAndInsertBlock(bc blockChain, block *types.Block, blockExecution bool, nextBlocks ...*types.Block) error { +func verifyAndInsertBlock(bc blockChain, block *types.Block, nextBlocks ...*types.Block) error { //verify block if err := verifyBlock(bc, block, nextBlocks...); err != nil { return err } // insert block - if _, err := bc.InsertChain(types.Blocks{block}, false, blockExecution); err != nil { + if _, err := bc.InsertChain(types.Blocks{block}, false); err != nil { return errors.Wrap(err, "[InsertChain]") } return nil diff --git a/api/service/stagedstreamsync/stage_short_range.go b/api/service/stagedstreamsync/stage_short_range.go index a651490eb..d771cd660 100644 --- a/api/service/stagedstreamsync/stage_short_range.go +++ b/api/service/stagedstreamsync/stage_short_range.go @@ -138,7 +138,7 @@ func (sr *StageShortRange) doShortRangeSync(ctx context.Context, s *StageState) utils.Logger().Info().Int("num blocks", len(blocks)).Msg("getBlockByHashes result") - n, err := verifyAndInsertBlocks(sr.configs.bc, blocks, true) + n, err := verifyAndInsertBlocks(sr.configs.bc, blocks) numBlocksInsertedShortRangeHistogramVec.With(s.state.promLabels()).Observe(float64(n)) if err != nil { utils.Logger().Warn().Err(err).Int("blocks inserted", n).Msg("Insert block failed") diff --git a/api/service/stagedstreamsync/stage_state.go b/api/service/stagedstreamsync/stage_state.go index f579019f6..1294edf70 100644 --- a/api/service/stagedstreamsync/stage_state.go +++ b/api/service/stagedstreamsync/stage_state.go @@ -23,7 +23,6 @@ type StageStatesCfg struct { db kv.RwDB blockDBs []kv.RwDB concurrency int - blockExecution bool logger zerolog.Logger logProgress bool } @@ -39,7 +38,6 @@ func NewStageStatesCfg( db kv.RwDB, blockDBs []kv.RwDB, concurrency int, - blockExecution bool, logger zerolog.Logger, logProgress bool) StageStatesCfg { @@ -48,7 +46,6 @@ func NewStageStatesCfg( db: db, blockDBs: blockDBs, concurrency: concurrency, - blockExecution: blockExecution, logger: logger, logProgress: logProgress, } @@ -56,6 +53,13 @@ func NewStageStatesCfg( // Exec progresses States stage in the forward direction func (stg *StageStates) Exec(ctx context.Context, firstCycle bool, invalidBlockRevert bool, s *StageState, reverter Reverter, tx kv.RwTx) (err error) { + // only execute this stage in full sync mode + if s.state.config.SyncMode != FullSync { + if s.state.status.pivotBlock != nil && s.state.bc.CurrentBlock().NumberU64() <= s.state.status.pivotBlock.NumberU64() { + return nil + } + } + // for short range sync, skip this step if !s.state.initSync { return nil @@ -160,7 +164,7 @@ func (stg *StageStates) Exec(ctx context.Context, firstCycle bool, invalidBlockR return ErrInvalidBlockNumber } - if err := verifyAndInsertBlock(stg.configs.bc, block, stg.configs.blockExecution); err != nil { + if err := verifyAndInsertBlock(stg.configs.bc, block); err != nil { stg.configs.logger.Warn().Err(err).Uint64("cycle target block", targetHeight). Uint64("block number", block.NumberU64()). Msg(WrapStagedSyncMsg("insert blocks failed in long range"))