refactor stages list initialization based on the sync mode

pull/4465/head
“GheisMohammadi” 1 year ago
parent 7006e1568d
commit 30de7c27e3
No known key found for this signature in database
GPG Key ID: 15073AED3829FE90
  1. 111
      api/service/stagedstreamsync/default_stages.go
  2. 18
      api/service/stagedstreamsync/staged_stream_sync.go

@ -8,40 +8,91 @@ type ForwardOrder []SyncStageID
type RevertOrder []SyncStageID type RevertOrder []SyncStageID
type CleanUpOrder []SyncStageID type CleanUpOrder []SyncStageID
var DefaultForwardOrder = ForwardOrder{ var (
Heads, StagesForwardOrder ForwardOrder
SyncEpoch, StagesRevertOrder RevertOrder
ShortRange, StagesCleanUpOrder CleanUpOrder
BlockBodies, )
States,
StateSync, func initStagesOrder(syncMode SyncMode) {
Receipts, switch syncMode {
LastMile, case FullSync:
Finish, initFullSyncStagesOrder()
case FastSync:
initFastSyncStagesOrder()
default:
panic("not supported sync mode")
}
} }
var DefaultRevertOrder = RevertOrder{ func initFullSyncStagesOrder() {
Finish, StagesForwardOrder = ForwardOrder{
LastMile, Heads,
Receipts, SyncEpoch,
StateSync, ShortRange,
States, BlockBodies,
BlockBodies, States,
ShortRange, LastMile,
SyncEpoch, Finish,
Heads, }
StagesRevertOrder = RevertOrder{
Finish,
LastMile,
States,
BlockBodies,
ShortRange,
SyncEpoch,
Heads,
}
StagesCleanUpOrder = CleanUpOrder{
Finish,
LastMile,
States,
BlockBodies,
ShortRange,
SyncEpoch,
Heads,
}
} }
var DefaultCleanUpOrder = CleanUpOrder{ func initFastSyncStagesOrder() {
Finish, StagesForwardOrder = ForwardOrder{
LastMile, Heads,
Receipts, SyncEpoch,
StateSync, ShortRange,
States, BlockBodies,
BlockBodies, States,
ShortRange, StateSync,
SyncEpoch, Receipts,
Heads, LastMile,
Finish,
}
StagesRevertOrder = RevertOrder{
Finish,
LastMile,
Receipts,
StateSync,
States,
BlockBodies,
ShortRange,
SyncEpoch,
Heads,
}
StagesCleanUpOrder = CleanUpOrder{
Finish,
LastMile,
Receipts,
StateSync,
States,
BlockBodies,
ShortRange,
SyncEpoch,
Heads,
}
} }
func DefaultStages(ctx context.Context, func DefaultStages(ctx context.Context,

@ -268,8 +268,21 @@ func New(
logger zerolog.Logger, logger zerolog.Logger,
) *StagedStreamSync { ) *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 {
if s.ID == stageIndex {
forwardStages[i] = s
break
}
}
}
revertStages := make([]*Stage, len(stagesList)) revertStages := make([]*Stage, len(stagesList))
for i, stageIndex := range DefaultRevertOrder { for i, stageIndex := range StagesRevertOrder {
for _, s := range stagesList { for _, s := range stagesList {
if s.ID == stageIndex { if s.ID == stageIndex {
revertStages[i] = s revertStages[i] = s
@ -277,8 +290,9 @@ func New(
} }
} }
} }
pruneStages := make([]*Stage, len(stagesList)) pruneStages := make([]*Stage, len(stagesList))
for i, stageIndex := range DefaultCleanUpOrder { for i, stageIndex := range StagesCleanUpOrder {
for _, s := range stagesList { for _, s := range stagesList {
if s.ID == stageIndex { if s.ID == stageIndex {
pruneStages[i] = s pruneStages[i] = s

Loading…
Cancel
Save