make it a type in api
This commit is contained in:
parent
af18cbac53
commit
0d628516ed
12
api/api.go
12
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
|
||||
)
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user