From 12235f5c5c81c89b7e74216c1c5ff9159a9de1ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CGheisMohammadi=E2=80=9D?= <36589218+GheisMohammadi@users.noreply.github.com> Date: Mon, 10 Jul 2023 17:38:14 +0800 Subject: [PATCH] fix stages forward order for staged stream sync --- .../stagedstreamsync/staged_stream_sync.go | 3 --- api/service/stagedstreamsync/syncing.go | 18 ++++++++++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/api/service/stagedstreamsync/staged_stream_sync.go b/api/service/stagedstreamsync/staged_stream_sync.go index 5abe45b54..29832ef18 100644 --- a/api/service/stagedstreamsync/staged_stream_sync.go +++ b/api/service/stagedstreamsync/staged_stream_sync.go @@ -267,9 +267,6 @@ func New( logger zerolog.Logger, ) *StagedStreamSync { - // init stages order based on sync mode - initStagesOrder(config.SyncMode) - forwardStages := make([]*Stage, len(stagesList)) for i, stageIndex := range StagesForwardOrder { for _, s := range stagesList { diff --git a/api/service/stagedstreamsync/syncing.go b/api/service/stagedstreamsync/syncing.go index 7abf00e7a..b2c1aacdf 100644 --- a/api/service/stagedstreamsync/syncing.go +++ b/api/service/stagedstreamsync/syncing.go @@ -91,10 +91,13 @@ func CreateStagedSync(ctx context.Context, stageStatesCfg := NewStageStatesCfg(bc, mainDB, dbs, config.Concurrency, blockExecution, logger, config.LogProgress) stageStateSyncCfg := NewStageStateSyncCfg(bc, mainDB, config.Concurrency, protocol, logger, config.LogProgress) stageReceiptsCfg := NewStageReceiptsCfg(bc, mainDB, dbs, config.Concurrency, protocol, isBeaconNode, config.LogProgress) - lastMileCfg := NewStageLastMileCfg(ctx, bc, mainDB) + lastMileCfg := NewStageLastMileCfg(ctx, bc, mainDB) stageFinishCfg := NewStageFinishCfg(mainDB) - stages := DefaultStages(ctx, + // init stages order based on sync mode + initStagesOrder(config.SyncMode) + + defaultStages := DefaultStages(ctx, stageHeadsCfg, stageSyncEpochCfg, stageShortRangeCfg, @@ -115,6 +118,17 @@ func CreateStagedSync(ctx context.Context, Int("minStreams", config.MinStreams). Msg(WrapStagedSyncMsg("staged sync created successfully")) + var stages []*Stage + // if any of the default stages doesn't exist in forward order, delete it from the list of stages + for _, stg := range defaultStages { + for _, stageID := range StagesForwardOrder { + if stg.ID == stageID { + stages = append(stages, stg) + break + } + } + } + return New( bc, consensus,