sealing: More cleanup
This commit is contained in:
parent
604bf64ef6
commit
e9ca6c0871
@ -4,55 +4,12 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/ipfs/go-cid"
|
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/api"
|
"github.com/filecoin-project/lotus/api"
|
||||||
"github.com/filecoin-project/lotus/lib/statemachine"
|
"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) {
|
func (m *Sealing) Plan(events []statemachine.Event, user interface{}) (interface{}, error) {
|
||||||
next, err := m.plan(events, user.(*SectorInfo))
|
next, err := m.plan(events, user.(*SectorInfo))
|
||||||
if err != nil || next == nil {
|
if err != nil || next == nil {
|
49
storage/sealing/fsm_events.go
Normal file
49
storage/sealing/fsm_events.go
Normal 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
|
||||||
|
}
|
@ -10,12 +10,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (t *test) planSingle(evt interface{}) {
|
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)
|
require.NoError(t.t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
type test struct {
|
type test struct {
|
||||||
m *Miner
|
s *Sealing
|
||||||
t *testing.T
|
t *testing.T
|
||||||
state *SectorInfo
|
state *SectorInfo
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ type test struct {
|
|||||||
|
|
||||||
func TestHappyPath(t *testing.T) {
|
func TestHappyPath(t *testing.T) {
|
||||||
m := test{
|
m := test{
|
||||||
m: &Miner{},
|
s: &Sealing{},
|
||||||
t: t,
|
t: t,
|
||||||
state: &SectorInfo{State: api.Packing},
|
state: &SectorInfo{State: api.Packing},
|
||||||
}
|
}
|
||||||
@ -50,7 +50,7 @@ func TestHappyPath(t *testing.T) {
|
|||||||
|
|
||||||
func TestSeedRevert(t *testing.T) {
|
func TestSeedRevert(t *testing.T) {
|
||||||
m := test{
|
m := test{
|
||||||
m: &Miner{},
|
s: &Sealing{},
|
||||||
t: t,
|
t: t,
|
||||||
state: &SectorInfo{State: api.Packing},
|
state: &SectorInfo{State: api.Packing},
|
||||||
}
|
}
|
||||||
@ -67,7 +67,7 @@ func TestSeedRevert(t *testing.T) {
|
|||||||
m.planSingle(SectorSeedReady{})
|
m.planSingle(SectorSeedReady{})
|
||||||
require.Equal(m.t, m.state.State, api.Committing)
|
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.NoError(t, err)
|
||||||
require.Equal(m.t, m.state.State, api.Committing)
|
require.Equal(m.t, m.state.State, api.Committing)
|
||||||
|
|
@ -27,7 +27,7 @@ var log = logging.Logger("sectors")
|
|||||||
|
|
||||||
type TicketFn func(context.Context) (*sectorbuilder.SealTicket, error)
|
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)
|
// 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)
|
StateCall(ctx context.Context, msg *types.Message, ts *types.TipSet) (*types.MessageReceipt, error)
|
||||||
StateMinerWorker(context.Context, address.Address, *types.TipSet) (address.Address, error)
|
StateMinerWorker(context.Context, address.Address, *types.TipSet) (address.Address, error)
|
||||||
@ -53,7 +53,7 @@ type sectorsApi interface { // TODO: trim down
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Sealing struct {
|
type Sealing struct {
|
||||||
api sectorsApi
|
api sealingApi
|
||||||
events *events.Events
|
events *events.Events
|
||||||
|
|
||||||
maddr address.Address
|
maddr address.Address
|
||||||
@ -64,7 +64,7 @@ type Sealing struct {
|
|||||||
tktFn TicketFn
|
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{
|
s := &Sealing{
|
||||||
api: api,
|
api: api,
|
||||||
events: events,
|
events: events,
|
Loading…
Reference in New Issue
Block a user