From e9ca6c0871af7d0e6e0efeb2d1ac7e31807210e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Wed, 15 Jan 2020 21:53:14 +0100 Subject: [PATCH] sealing: More cleanup --- storage/sealing/{sector_fsm.go => fsm.go} | 43 ---------------- storage/sealing/fsm_events.go | 49 +++++++++++++++++++ .../{sectors_fsm_test.go => fsm_test.go} | 10 ++-- storage/sealing/{sectors.go => sealing.go} | 6 +-- .../sealing/{sector_states.go => states.go} | 0 storage/sealing/{sector_types.go => types.go} | 0 .../{sectors_test.go => types_test.go} | 0 storage/sealing/{sector_utils.go => utils.go} | 0 .../{sector_utils_test.go => utils_test.go} | 0 9 files changed, 57 insertions(+), 51 deletions(-) rename storage/sealing/{sector_fsm.go => fsm.go} (87%) create mode 100644 storage/sealing/fsm_events.go rename storage/sealing/{sectors_fsm_test.go => fsm_test.go} (90%) rename storage/sealing/{sectors.go => sealing.go} (97%) rename storage/sealing/{sector_states.go => states.go} (100%) rename storage/sealing/{sector_types.go => types.go} (100%) rename storage/sealing/{sectors_test.go => types_test.go} (100%) rename storage/sealing/{sector_utils.go => utils.go} (100%) rename storage/sealing/{sector_utils_test.go => utils_test.go} (100%) diff --git a/storage/sealing/sector_fsm.go b/storage/sealing/fsm.go similarity index 87% rename from storage/sealing/sector_fsm.go rename to storage/sealing/fsm.go index 50b62844a..e984b883b 100644 --- a/storage/sealing/sector_fsm.go +++ b/storage/sealing/fsm.go @@ -4,55 +4,12 @@ import ( "context" "fmt" - "github.com/ipfs/go-cid" "golang.org/x/xerrors" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/lib/statemachine" ) -type SectorStart struct { - id uint64 - pieces []Piece -} -type SectorRestart struct{} - -type SectorFatalError struct{ error } - -type SectorPacked struct{ pieces []Piece } - -type SectorSealed struct { - commR []byte - commD []byte - ticket SealTicket -} -type SectorSealFailed struct{ error } - -type SectorPreCommitFailed struct{ error } -type SectorPreCommitted struct { - message cid.Cid -} - -type SectorSeedReady struct { - seed SealSeed -} - -type SectorSealCommitFailed struct{ error } -type SectorCommitFailed struct{ error } -type SectorCommitted struct { - message cid.Cid - proof []byte -} - -type SectorProving struct{} - -type SectorFaultReported struct{ reportMsg cid.Cid } -type SectorFaultedFinal struct{} - -type SectorForceState struct { - state api.SectorState -} - func (m *Sealing) Plan(events []statemachine.Event, user interface{}) (interface{}, error) { next, err := m.plan(events, user.(*SectorInfo)) if err != nil || next == nil { diff --git a/storage/sealing/fsm_events.go b/storage/sealing/fsm_events.go new file mode 100644 index 000000000..39d0638d3 --- /dev/null +++ b/storage/sealing/fsm_events.go @@ -0,0 +1,49 @@ +package sealing + +import ( + "github.com/ipfs/go-cid" + + "github.com/filecoin-project/lotus/api" +) + +type SectorStart struct { + id uint64 + pieces []Piece +} +type SectorRestart struct{} + +type SectorFatalError struct{ error } + +type SectorPacked struct{ pieces []Piece } + +type SectorSealed struct { + commR []byte + commD []byte + ticket SealTicket +} +type SectorSealFailed struct{ error } + +type SectorPreCommitFailed struct{ error } +type SectorPreCommitted struct { + message cid.Cid +} + +type SectorSeedReady struct { + seed SealSeed +} + +type SectorSealCommitFailed struct{ error } +type SectorCommitFailed struct{ error } +type SectorCommitted struct { + message cid.Cid + proof []byte +} + +type SectorProving struct{} + +type SectorFaultReported struct{ reportMsg cid.Cid } +type SectorFaultedFinal struct{} + +type SectorForceState struct { + state api.SectorState +} diff --git a/storage/sealing/sectors_fsm_test.go b/storage/sealing/fsm_test.go similarity index 90% rename from storage/sealing/sectors_fsm_test.go rename to storage/sealing/fsm_test.go index 3eda54860..10b9723b9 100644 --- a/storage/sealing/sectors_fsm_test.go +++ b/storage/sealing/fsm_test.go @@ -10,12 +10,12 @@ import ( ) func (t *test) planSingle(evt interface{}) { - _, err := t.m.plan([]statemachine.Event{{evt}}, t.state) + _, err := t.s.plan([]statemachine.Event{{evt}}, t.state) require.NoError(t.t, err) } type test struct { - m *Miner + s *Sealing t *testing.T state *SectorInfo @@ -24,7 +24,7 @@ type test struct { func TestHappyPath(t *testing.T) { m := test{ - m: &Miner{}, + s: &Sealing{}, t: t, state: &SectorInfo{State: api.Packing}, } @@ -50,7 +50,7 @@ func TestHappyPath(t *testing.T) { func TestSeedRevert(t *testing.T) { m := test{ - m: &Miner{}, + s: &Sealing{}, t: t, state: &SectorInfo{State: api.Packing}, } @@ -67,7 +67,7 @@ func TestSeedRevert(t *testing.T) { m.planSingle(SectorSeedReady{}) require.Equal(m.t, m.state.State, api.Committing) - _, err := m.m.plan([]statemachine.Event{{SectorSeedReady{}}, {SectorCommitted{}}}, m.state) + _, err := m.s.plan([]statemachine.Event{{SectorSeedReady{}}, {SectorCommitted{}}}, m.state) require.NoError(t, err) require.Equal(m.t, m.state.State, api.Committing) diff --git a/storage/sealing/sectors.go b/storage/sealing/sealing.go similarity index 97% rename from storage/sealing/sectors.go rename to storage/sealing/sealing.go index c915c27f1..f0c2b3d50 100644 --- a/storage/sealing/sectors.go +++ b/storage/sealing/sealing.go @@ -27,7 +27,7 @@ var log = logging.Logger("sectors") type TicketFn func(context.Context) (*sectorbuilder.SealTicket, error) -type sectorsApi interface { // TODO: trim down +type sealingApi interface { // TODO: trim down // Call a read only method on actors (no interaction with the chain required) StateCall(ctx context.Context, msg *types.Message, ts *types.TipSet) (*types.MessageReceipt, error) StateMinerWorker(context.Context, address.Address, *types.TipSet) (address.Address, error) @@ -53,7 +53,7 @@ type sectorsApi interface { // TODO: trim down } type Sealing struct { - api sectorsApi + api sealingApi events *events.Events maddr address.Address @@ -64,7 +64,7 @@ type Sealing struct { tktFn TicketFn } -func New(api sectorsApi, events *events.Events, maddr address.Address, worker address.Address, ds datastore.Batching, sb sectorbuilder.Interface, tktFn TicketFn) *Sealing { +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, events: events, diff --git a/storage/sealing/sector_states.go b/storage/sealing/states.go similarity index 100% rename from storage/sealing/sector_states.go rename to storage/sealing/states.go diff --git a/storage/sealing/sector_types.go b/storage/sealing/types.go similarity index 100% rename from storage/sealing/sector_types.go rename to storage/sealing/types.go diff --git a/storage/sealing/sectors_test.go b/storage/sealing/types_test.go similarity index 100% rename from storage/sealing/sectors_test.go rename to storage/sealing/types_test.go diff --git a/storage/sealing/sector_utils.go b/storage/sealing/utils.go similarity index 100% rename from storage/sealing/sector_utils.go rename to storage/sealing/utils.go diff --git a/storage/sealing/sector_utils_test.go b/storage/sealing/utils_test.go similarity index 100% rename from storage/sealing/sector_utils_test.go rename to storage/sealing/utils_test.go