make it a type in api

This commit is contained in:
whyrusleeping 2019-09-30 16:29:40 -06:00
parent af18cbac53
commit 0d628516ed
3 changed files with 24 additions and 20 deletions

View File

@ -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
)

View File

@ -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
}

View File

@ -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("<unknown: %d>", 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
}