diff --git a/api/api.go b/api/api.go index 99e40f31c..330920bf0 100644 --- a/api/api.go +++ b/api/api.go @@ -300,6 +300,16 @@ type SyncState struct { Base *types.TipSet Target *types.TipSet - Stage int + Stage SyncStateStage Height uint64 } + +type SyncStateStage int + +const ( + StageIdle = SyncStateStage(iota) + StageHeaders + StagePersistHeaders + StageMessages + StageSyncComplete +) diff --git a/chain/sync.go b/chain/sync.go index 2645d9270..b83709387 100644 --- a/chain/sync.go +++ b/chain/sync.go @@ -6,6 +6,7 @@ import ( "sync" "time" + "github.com/filecoin-project/go-lotus/api" "github.com/filecoin-project/go-lotus/build" "github.com/filecoin-project/go-lotus/chain/actors" "github.com/filecoin-project/go-lotus/chain/address" @@ -683,7 +684,7 @@ func (syncer *Syncer) collectChain(fts *store.FullTipSet) error { return err } - syncer.syncState.SetStage(StagePersistHeaders) + syncer.syncState.SetStage(api.StagePersistHeaders) for _, ts := range headers { for _, b := range ts.Blocks() { @@ -693,13 +694,13 @@ func (syncer *Syncer) collectChain(fts *store.FullTipSet) error { } } - syncer.syncState.SetStage(StageMessages) + syncer.syncState.SetStage(api.StageMessages) if err := syncer.syncMessagesAndCheckState(headers); err != nil { return xerrors.Errorf("collectChain syncMessages: %w", err) } - syncer.syncState.SetStage(StageSyncComplete) + syncer.syncState.SetStage(api.StageSyncComplete) return nil } diff --git a/chain/syncstate.go b/chain/syncstate.go index 8f2db6314..e7452dd8e 100644 --- a/chain/syncstate.go +++ b/chain/syncstate.go @@ -4,26 +4,19 @@ import ( "fmt" "sync" + "github.com/filecoin-project/go-lotus/api" "github.com/filecoin-project/go-lotus/chain/types" ) -const ( - StageIdle = iota - StageHeaders - StagePersistHeaders - StageMessages - StageSyncComplete -) - -func SyncStageString(v int) string { +func SyncStageString(v api.SyncStateStage) string { switch v { - case StageHeaders: + case api.StageHeaders: return "header sync" - case StagePersistHeaders: + case api.StagePersistHeaders: return "persisting headers" - case StageMessages: + case api.StageMessages: return "message sync" - case StageSyncComplete: + case api.StageSyncComplete: return "complete" default: return fmt.Sprintf("", v) @@ -34,11 +27,11 @@ type SyncerState struct { lk sync.Mutex Target *types.TipSet Base *types.TipSet - Stage int + Stage api.SyncStateStage Height uint64 } -func (ss *SyncerState) SetStage(v int) { +func (ss *SyncerState) SetStage(v api.SyncStateStage) { ss.lk.Lock() defer ss.lk.Unlock() ss.Stage = v @@ -49,7 +42,7 @@ func (ss *SyncerState) Init(base, target *types.TipSet) { defer ss.lk.Unlock() ss.Target = target ss.Base = base - ss.Stage = StageHeaders + ss.Stage = api.StageHeaders ss.Height = 0 }