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 CleanUpOrder []SyncStageID
var DefaultForwardOrder = ForwardOrder{
Heads,
SyncEpoch,
ShortRange,
BlockBodies,
States,
StateSync,
Receipts,
LastMile,
Finish,
var (
StagesForwardOrder ForwardOrder
StagesRevertOrder RevertOrder
StagesCleanUpOrder CleanUpOrder
)
func initStagesOrder(syncMode SyncMode) {
switch syncMode {
case FullSync:
initFullSyncStagesOrder()
case FastSync:
initFastSyncStagesOrder()
default:
panic("not supported sync mode")
}
}
var DefaultRevertOrder = RevertOrder{
Finish,
LastMile,
Receipts,
StateSync,
States,
BlockBodies,
ShortRange,
SyncEpoch,
Heads,
func initFullSyncStagesOrder() {
StagesForwardOrder = ForwardOrder{
Heads,
SyncEpoch,
ShortRange,
BlockBodies,
States,
LastMile,
Finish,
}
StagesRevertOrder = RevertOrder{
Finish,
LastMile,
States,
BlockBodies,
ShortRange,
SyncEpoch,
Heads,
}
StagesCleanUpOrder = CleanUpOrder{
Finish,
LastMile,
States,
BlockBodies,
ShortRange,
SyncEpoch,
Heads,
}
}
var DefaultCleanUpOrder = CleanUpOrder{
Finish,
LastMile,
Receipts,
StateSync,
States,
BlockBodies,
ShortRange,
SyncEpoch,
Heads,
func initFastSyncStagesOrder() {
StagesForwardOrder = ForwardOrder{
Heads,
SyncEpoch,
ShortRange,
BlockBodies,
States,
StateSync,
Receipts,
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,

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

Loading…
Cancel
Save