sealing: More cleanup

This commit is contained in:
Łukasz Magiera 2020-01-15 21:53:14 +01:00
parent 03f31d74f1
commit 72ca563a1d
9 changed files with 57 additions and 51 deletions

View File

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

49
fsm_events.go Normal file
View File

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

View File

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

View File

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