diff --git a/node/modules/storageminer.go b/node/modules/storageminer.go index 1d2b1d7ce..533946696 100644 --- a/node/modules/storageminer.go +++ b/node/modules/storageminer.go @@ -41,8 +41,8 @@ import ( "github.com/filecoin-project/lotus/node/modules/helpers" "github.com/filecoin-project/lotus/node/repo" "github.com/filecoin-project/lotus/storage" - "github.com/filecoin-project/lotus/storage/sectorblocks" "github.com/filecoin-project/lotus/storage/sealing" + "github.com/filecoin-project/lotus/storage/sectorblocks" ) func minerAddrFromDS(ds dtypes.MetadataDS) (address.Address, error) { diff --git a/storage/miner.go b/storage/miner.go index 01cb26b51..fbd06cdae 100644 --- a/storage/miner.go +++ b/storage/miner.go @@ -36,8 +36,8 @@ type Miner struct { sealing *sealing.Sealing - stop chan struct{} - stopped chan struct{} + stop chan struct{} + stopped chan struct{} } type storageMinerApi interface { @@ -67,16 +67,16 @@ type storageMinerApi interface { func NewMiner(api storageMinerApi, addr address.Address, h host.Host, ds datastore.Batching, sb sectorbuilder.Interface, tktFn sealing.TicketFn) (*Miner, error) { m := &Miner{ - api: api, + api: api, h: h, sb: sb, - ds: ds, + ds: ds, tktFn: tktFn, maddr: addr, - stop: make(chan struct{}), - stopped: make(chan struct{}), + stop: make(chan struct{}), + stopped: make(chan struct{}), } return m, nil @@ -88,8 +88,8 @@ func (m *Miner) Run(ctx context.Context) error { } fps := &fpostScheduler{ - api: m.api, - sb: m.sb, + api: m.api, + sb: m.sb, actor: m.maddr, worker: m.worker, diff --git a/storage/sealing/fsm.go b/storage/sealing/fsm.go index 163e0eccd..5c37020d2 100644 --- a/storage/sealing/fsm.go +++ b/storage/sealing/fsm.go @@ -28,9 +28,9 @@ func (m *Sealing) Plan(events []statemachine.Event, user interface{}) (interface }, nil } -var fsmPlanners = []func(events []statemachine.Event, state *SectorInfo) error { +var fsmPlanners = []func(events []statemachine.Event, state *SectorInfo) error{ api.UndefinedSectorState: planOne(on(SectorStart{}, api.Packing)), - api.Packing: planOne(on(SectorPacked{}, api.Unsealed)), + api.Packing: planOne(on(SectorPacked{}, api.Unsealed)), api.Unsealed: planOne( on(SectorSealed{}, api.PreCommitting), on(SectorSealFailed{}, api.SealFailed), diff --git a/storage/sealing/fsm_events.go b/storage/sealing/fsm_events.go index a33861d42..ddab56451 100644 --- a/storage/sealing/fsm_events.go +++ b/storage/sealing/fsm_events.go @@ -19,9 +19,11 @@ type globalMutator interface { // Global events type SectorRestart struct{} + func (evt SectorRestart) applyGlobal(*SectorInfo) bool { return false } type SectorFatalError struct{ error } + func (evt SectorFatalError) applyGlobal(state *SectorInfo) bool { log.Errorf("Fatal error on sector %d: %+v", state.SectorID, evt.error) // TODO: Do we want to mark the state as unrecoverable? @@ -33,6 +35,7 @@ func (evt SectorFatalError) applyGlobal(state *SectorInfo) bool { type SectorForceState struct { state api.SectorState } + func (evt SectorForceState) applyGlobal(state *SectorInfo) bool { state.State = evt.state return true @@ -44,12 +47,14 @@ type SectorStart struct { id uint64 pieces []Piece } + func (evt SectorStart) apply(state *SectorInfo) { state.SectorID = evt.id state.Pieces = evt.pieces } type SectorPacked struct{ pieces []Piece } + func (evt SectorPacked) apply(state *SectorInfo) { state.Pieces = append(state.Pieces, evt.pieces...) } @@ -59,6 +64,7 @@ type SectorSealed struct { commD []byte ticket SealTicket } + func (evt SectorSealed) apply(state *SectorInfo) { state.CommD = evt.commD state.CommR = evt.commR @@ -66,14 +72,17 @@ func (evt SectorSealed) apply(state *SectorInfo) { } type SectorSealFailed struct{ error } + func (evt SectorSealFailed) apply(*SectorInfo) {} type SectorPreCommitFailed struct{ error } + func (evt SectorPreCommitFailed) apply(*SectorInfo) {} type SectorPreCommitted struct { message cid.Cid } + func (evt SectorPreCommitted) apply(state *SectorInfo) { state.PreCommitMessage = &evt.message } @@ -81,6 +90,7 @@ func (evt SectorPreCommitted) apply(state *SectorInfo) { type SectorSeedReady struct { seed SealSeed } + func (evt SectorSeedReady) apply(state *SectorInfo) { state.Seed = evt.seed } @@ -91,18 +101,22 @@ type SectorCommitted struct { message cid.Cid proof []byte } + func (evt SectorCommitted) apply(state *SectorInfo) { state.Proof = evt.proof state.CommitMessage = &evt.message } type SectorProving struct{} + func (evt SectorProving) apply(*SectorInfo) {} type SectorFaulty struct{} + func (evt SectorFaulty) apply(state *SectorInfo) {} type SectorFaultReported struct{ reportMsg cid.Cid } + func (evt SectorFaultReported) apply(state *SectorInfo) { state.FaultReportMsg = &evt.reportMsg } diff --git a/storage/sealing/fsm_test.go b/storage/sealing/fsm_test.go index fb31f5192..a76a547dc 100644 --- a/storage/sealing/fsm_test.go +++ b/storage/sealing/fsm_test.go @@ -72,12 +72,12 @@ func TestSeedRevert(t *testing.T) { m.planSingle(SectorSeedReady{}) require.Equal(m.t, m.state.State, api.Committing) - _, err := m.s.plan([]statemachine.Event{{SectorSeedReady{seed:SealSeed{BlockHeight: 5,}}}, {SectorCommitted{}}}, m.state) + _, err := m.s.plan([]statemachine.Event{{SectorSeedReady{seed: SealSeed{BlockHeight: 5}}}, {SectorCommitted{}}}, m.state) require.NoError(t, err) require.Equal(m.t, m.state.State, api.Committing) // not changing the seed this time - _, err = m.s.plan([]statemachine.Event{{SectorSeedReady{seed:SealSeed{BlockHeight: 5,}}}, {SectorCommitted{}}}, m.state) + _, err = m.s.plan([]statemachine.Event{{SectorSeedReady{seed: SealSeed{BlockHeight: 5}}}, {SectorCommitted{}}}, m.state) require.Equal(m.t, m.state.State, api.CommitWait) m.planSingle(SectorProving{}) diff --git a/storage/sealing/sealing.go b/storage/sealing/sealing.go index f0c2b3d50..45e3d6451 100644 --- a/storage/sealing/sealing.go +++ b/storage/sealing/sealing.go @@ -66,13 +66,13 @@ type Sealing struct { func New(api sealingApi, events *events.Events, maddr address.Address, worker address.Address, ds datastore.Batching, sb sectorbuilder.Interface, tktFn TicketFn) *Sealing { s := &Sealing{ - api: api, + api: api, events: events, - maddr: maddr, - worker: worker, - sb: sb, - tktFn: tktFn, + maddr: maddr, + worker: worker, + sb: sb, + tktFn: tktFn, } s.sectors = statemachine.New(namespace.Wrap(ds, datastore.NewKey(SectorStorePrefix)), s, SectorInfo{}) @@ -133,4 +133,3 @@ func (m *Sealing) newSector(ctx context.Context, sid uint64, dealID uint64, ppi }, }) } -