2020-01-15 20:49:11 +00:00
|
|
|
package sealing
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-08-18 16:27:18 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
|
|
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
2020-01-16 01:25:49 +00:00
|
|
|
logging "github.com/ipfs/go-log/v2"
|
2020-01-15 20:49:11 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2020-03-06 18:59:08 +00:00
|
|
|
"github.com/filecoin-project/go-statemachine"
|
2020-01-15 20:49:11 +00:00
|
|
|
)
|
|
|
|
|
2020-01-16 01:25:49 +00:00
|
|
|
func init() {
|
|
|
|
_ = logging.SetLogLevel("*", "INFO")
|
|
|
|
}
|
|
|
|
|
2020-01-15 20:49:11 +00:00
|
|
|
func (t *test) planSingle(evt interface{}) {
|
2020-04-07 00:29:52 +00:00
|
|
|
_, err := t.s.plan([]statemachine.Event{{User: evt}}, t.state)
|
2020-01-15 20:49:11 +00:00
|
|
|
require.NoError(t.t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
type test struct {
|
2020-01-15 20:53:14 +00:00
|
|
|
s *Sealing
|
2020-01-15 20:49:11 +00:00
|
|
|
t *testing.T
|
|
|
|
state *SectorInfo
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHappyPath(t *testing.T) {
|
2020-08-11 12:22:35 +00:00
|
|
|
var notif []struct{ before, after SectorInfo }
|
2020-08-18 16:27:18 +00:00
|
|
|
ma, _ := address.NewIDAddress(55151)
|
2020-01-15 20:49:11 +00:00
|
|
|
m := test{
|
2020-08-11 12:22:35 +00:00
|
|
|
s: &Sealing{
|
2020-08-18 16:27:18 +00:00
|
|
|
maddr: ma,
|
|
|
|
stats: SectorStats{
|
|
|
|
bySector: map[abi.SectorID]statSectorState{},
|
|
|
|
},
|
2020-08-11 12:22:35 +00:00
|
|
|
notifee: func(before, after SectorInfo) {
|
|
|
|
notif = append(notif, struct{ before, after SectorInfo }{before, after})
|
|
|
|
},
|
|
|
|
},
|
2020-01-15 20:49:11 +00:00
|
|
|
t: t,
|
2020-04-06 18:07:26 +00:00
|
|
|
state: &SectorInfo{State: Packing},
|
2020-01-15 20:49:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m.planSingle(SectorPacked{})
|
2020-04-06 20:23:37 +00:00
|
|
|
require.Equal(m.t, m.state.State, PreCommit1)
|
2020-01-15 20:49:11 +00:00
|
|
|
|
2020-04-04 02:55:19 +00:00
|
|
|
m.planSingle(SectorPreCommit1{})
|
2020-04-06 20:23:37 +00:00
|
|
|
require.Equal(m.t, m.state.State, PreCommit2)
|
2020-04-04 02:55:19 +00:00
|
|
|
|
2020-04-03 16:54:01 +00:00
|
|
|
m.planSingle(SectorPreCommit2{})
|
2020-04-06 20:23:37 +00:00
|
|
|
require.Equal(m.t, m.state.State, PreCommitting)
|
2020-01-15 20:49:11 +00:00
|
|
|
|
|
|
|
m.planSingle(SectorPreCommitted{})
|
2020-05-18 22:49:21 +00:00
|
|
|
require.Equal(m.t, m.state.State, PreCommitWait)
|
|
|
|
|
|
|
|
m.planSingle(SectorPreCommitLanded{})
|
2020-04-06 18:07:26 +00:00
|
|
|
require.Equal(m.t, m.state.State, WaitSeed)
|
2020-01-15 20:49:11 +00:00
|
|
|
|
|
|
|
m.planSingle(SectorSeedReady{})
|
2020-04-06 18:07:26 +00:00
|
|
|
require.Equal(m.t, m.state.State, Committing)
|
2020-01-15 20:49:11 +00:00
|
|
|
|
|
|
|
m.planSingle(SectorCommitted{})
|
2020-04-06 18:07:26 +00:00
|
|
|
require.Equal(m.t, m.state.State, CommitWait)
|
2020-01-15 20:49:11 +00:00
|
|
|
|
|
|
|
m.planSingle(SectorProving{})
|
2020-04-06 18:07:26 +00:00
|
|
|
require.Equal(m.t, m.state.State, FinalizeSector)
|
2020-01-31 01:27:38 +00:00
|
|
|
|
|
|
|
m.planSingle(SectorFinalized{})
|
2020-04-06 18:07:26 +00:00
|
|
|
require.Equal(m.t, m.state.State, Proving)
|
2020-08-11 12:22:35 +00:00
|
|
|
|
|
|
|
expected := []SectorState{Packing, PreCommit1, PreCommit2, PreCommitting, PreCommitWait, WaitSeed, Committing, CommitWait, FinalizeSector, Proving}
|
|
|
|
for i, n := range notif {
|
|
|
|
if n.before.State != expected[i] {
|
|
|
|
t.Fatalf("expected before state: %s, got: %s", expected[i], n.before.State)
|
|
|
|
}
|
|
|
|
if n.after.State != expected[i+1] {
|
|
|
|
t.Fatalf("expected after state: %s, got: %s", expected[i+1], n.after.State)
|
|
|
|
}
|
|
|
|
}
|
2020-01-15 20:49:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSeedRevert(t *testing.T) {
|
2020-08-18 16:27:18 +00:00
|
|
|
ma, _ := address.NewIDAddress(55151)
|
2020-01-15 20:49:11 +00:00
|
|
|
m := test{
|
2020-08-18 16:27:28 +00:00
|
|
|
s: &Sealing{
|
|
|
|
maddr: ma,
|
|
|
|
stats: SectorStats{
|
|
|
|
bySector: map[abi.SectorID]statSectorState{},
|
|
|
|
},
|
|
|
|
},
|
2020-01-15 20:49:11 +00:00
|
|
|
t: t,
|
2020-04-06 18:07:26 +00:00
|
|
|
state: &SectorInfo{State: Packing},
|
2020-01-15 20:49:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m.planSingle(SectorPacked{})
|
2020-04-06 20:23:37 +00:00
|
|
|
require.Equal(m.t, m.state.State, PreCommit1)
|
2020-01-15 20:49:11 +00:00
|
|
|
|
2020-04-04 02:55:19 +00:00
|
|
|
m.planSingle(SectorPreCommit1{})
|
2020-04-06 20:23:37 +00:00
|
|
|
require.Equal(m.t, m.state.State, PreCommit2)
|
2020-04-04 02:55:19 +00:00
|
|
|
|
2020-04-03 16:54:01 +00:00
|
|
|
m.planSingle(SectorPreCommit2{})
|
2020-04-06 20:23:37 +00:00
|
|
|
require.Equal(m.t, m.state.State, PreCommitting)
|
2020-01-15 20:49:11 +00:00
|
|
|
|
|
|
|
m.planSingle(SectorPreCommitted{})
|
2020-05-18 22:49:21 +00:00
|
|
|
require.Equal(m.t, m.state.State, PreCommitWait)
|
|
|
|
|
|
|
|
m.planSingle(SectorPreCommitLanded{})
|
2020-04-06 18:07:26 +00:00
|
|
|
require.Equal(m.t, m.state.State, WaitSeed)
|
2020-01-15 20:49:11 +00:00
|
|
|
|
|
|
|
m.planSingle(SectorSeedReady{})
|
2020-04-06 18:07:26 +00:00
|
|
|
require.Equal(m.t, m.state.State, Committing)
|
2020-01-15 20:49:11 +00:00
|
|
|
|
2020-04-07 00:29:52 +00:00
|
|
|
_, err := m.s.plan([]statemachine.Event{{User: SectorSeedReady{SeedValue: nil, SeedEpoch: 5}}, {User: SectorCommitted{}}}, m.state)
|
2020-01-15 20:49:11 +00:00
|
|
|
require.NoError(t, err)
|
2020-04-06 18:07:26 +00:00
|
|
|
require.Equal(m.t, m.state.State, Committing)
|
2020-01-15 20:49:11 +00:00
|
|
|
|
2020-01-16 01:25:49 +00:00
|
|
|
// not changing the seed this time
|
2020-04-07 00:29:52 +00:00
|
|
|
_, err = m.s.plan([]statemachine.Event{{User: SectorSeedReady{SeedValue: nil, SeedEpoch: 5}}, {User: SectorCommitted{}}}, m.state)
|
|
|
|
require.NoError(t, err)
|
2020-04-06 18:07:26 +00:00
|
|
|
require.Equal(m.t, m.state.State, CommitWait)
|
2020-01-15 20:49:11 +00:00
|
|
|
|
|
|
|
m.planSingle(SectorProving{})
|
2020-04-06 18:07:26 +00:00
|
|
|
require.Equal(m.t, m.state.State, FinalizeSector)
|
2020-01-31 01:27:38 +00:00
|
|
|
|
|
|
|
m.planSingle(SectorFinalized{})
|
2020-04-06 18:07:26 +00:00
|
|
|
require.Equal(m.t, m.state.State, Proving)
|
2020-01-15 20:49:11 +00:00
|
|
|
}
|
2020-01-28 20:39:07 +00:00
|
|
|
|
|
|
|
func TestPlanCommittingHandlesSectorCommitFailed(t *testing.T) {
|
2020-08-18 16:27:18 +00:00
|
|
|
ma, _ := address.NewIDAddress(55151)
|
2020-01-28 20:39:07 +00:00
|
|
|
m := test{
|
2020-08-18 16:27:28 +00:00
|
|
|
s: &Sealing{
|
|
|
|
maddr: ma,
|
|
|
|
stats: SectorStats{
|
|
|
|
bySector: map[abi.SectorID]statSectorState{},
|
|
|
|
},
|
|
|
|
},
|
2020-01-28 20:39:07 +00:00
|
|
|
t: t,
|
2020-04-06 18:07:26 +00:00
|
|
|
state: &SectorInfo{State: Committing},
|
2020-01-28 20:39:07 +00:00
|
|
|
}
|
|
|
|
|
2020-04-07 00:29:52 +00:00
|
|
|
events := []statemachine.Event{{User: SectorCommitFailed{}}}
|
2020-01-28 20:39:07 +00:00
|
|
|
|
|
|
|
require.NoError(t, planCommitting(events, m.state))
|
|
|
|
|
2020-04-06 20:23:37 +00:00
|
|
|
require.Equal(t, CommitFailed, m.state.State)
|
2020-01-28 20:39:07 +00:00
|
|
|
}
|