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 Base *types.TipSet
Target *types.TipSet Target *types.TipSet
Stage int Stage SyncStateStage
Height uint64 Height uint64
} }
type SyncStateStage int
const (
StageIdle = SyncStateStage(iota)
StageHeaders
StagePersistHeaders
StageMessages
StageSyncComplete
)

View File

@ -6,6 +6,7 @@ import (
"sync" "sync"
"time" "time"
"github.com/filecoin-project/go-lotus/api"
"github.com/filecoin-project/go-lotus/build" "github.com/filecoin-project/go-lotus/build"
"github.com/filecoin-project/go-lotus/chain/actors" "github.com/filecoin-project/go-lotus/chain/actors"
"github.com/filecoin-project/go-lotus/chain/address" "github.com/filecoin-project/go-lotus/chain/address"
@ -683,7 +684,7 @@ func (syncer *Syncer) collectChain(fts *store.FullTipSet) error {
return err return err
} }
syncer.syncState.SetStage(StagePersistHeaders) syncer.syncState.SetStage(api.StagePersistHeaders)
for _, ts := range headers { for _, ts := range headers {
for _, b := range ts.Blocks() { 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 { if err := syncer.syncMessagesAndCheckState(headers); err != nil {
return xerrors.Errorf("collectChain syncMessages: %w", err) return xerrors.Errorf("collectChain syncMessages: %w", err)
} }
syncer.syncState.SetStage(StageSyncComplete) syncer.syncState.SetStage(api.StageSyncComplete)
return nil return nil
} }

View File

@ -4,26 +4,19 @@ import (
"fmt" "fmt"
"sync" "sync"
"github.com/filecoin-project/go-lotus/api"
"github.com/filecoin-project/go-lotus/chain/types" "github.com/filecoin-project/go-lotus/chain/types"
) )
const ( func SyncStageString(v api.SyncStateStage) string {
StageIdle = iota
StageHeaders
StagePersistHeaders
StageMessages
StageSyncComplete
)
func SyncStageString(v int) string {
switch v { switch v {
case StageHeaders: case api.StageHeaders:
return "header sync" return "header sync"
case StagePersistHeaders: case api.StagePersistHeaders:
return "persisting headers" return "persisting headers"
case StageMessages: case api.StageMessages:
return "message sync" return "message sync"
case StageSyncComplete: case api.StageSyncComplete:
return "complete" return "complete"
default: default:
return fmt.Sprintf("<unknown: %d>", v) return fmt.Sprintf("<unknown: %d>", v)
@ -34,11 +27,11 @@ type SyncerState struct {
lk sync.Mutex lk sync.Mutex
Target *types.TipSet Target *types.TipSet
Base *types.TipSet Base *types.TipSet
Stage int Stage api.SyncStateStage
Height uint64 Height uint64
} }
func (ss *SyncerState) SetStage(v int) { func (ss *SyncerState) SetStage(v api.SyncStateStage) {
ss.lk.Lock() ss.lk.Lock()
defer ss.lk.Unlock() defer ss.lk.Unlock()
ss.Stage = v ss.Stage = v
@ -49,7 +42,7 @@ func (ss *SyncerState) Init(base, target *types.TipSet) {
defer ss.lk.Unlock() defer ss.lk.Unlock()
ss.Target = target ss.Target = target
ss.Base = base ss.Base = base
ss.Stage = StageHeaders ss.Stage = api.StageHeaders
ss.Height = 0 ss.Height = 0
} }