2020-01-15 20:49:11 +00:00
|
|
|
package sealing
|
|
|
|
|
|
|
|
import (
|
2023-09-21 15:37:02 +00:00
|
|
|
"context"
|
2020-01-15 20:49:11 +00:00
|
|
|
"testing"
|
|
|
|
|
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"
|
2023-09-21 15:37:02 +00:00
|
|
|
"golang.org/x/xerrors"
|
2020-01-15 20:49:11 +00:00
|
|
|
|
2022-06-14 15:00:51 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2020-03-06 18:59:08 +00:00
|
|
|
"github.com/filecoin-project/go-statemachine"
|
2023-09-21 15:37:02 +00:00
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/storage/sealer/storiface"
|
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-08-27 19:34:45 +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{
|
2021-10-19 16:52:54 +00:00
|
|
|
bySector: map[abi.SectorID]SectorState{},
|
|
|
|
byState: map[SectorState]int64{},
|
2020-08-18 16:27:18 +00:00
|
|
|
},
|
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-09-30 17:11:58 +00:00
|
|
|
require.Equal(m.t, m.state.State, GetTicket)
|
|
|
|
|
|
|
|
m.planSingle(SectorTicket{})
|
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{})
|
2023-09-21 15:37:02 +00:00
|
|
|
require.Equal(m.t, m.state.State, SubmitPreCommitBatch)
|
2020-01-15 20:49:11 +00:00
|
|
|
|
2023-09-21 15:37:02 +00:00
|
|
|
m.planSingle(SectorPreCommitBatchSent{})
|
|
|
|
require.Equal(m.t, m.state.State, PreCommitBatchWait)
|
2020-05-18 22:49:21 +00:00
|
|
|
|
|
|
|
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-08-27 20:41:35 +00:00
|
|
|
require.Equal(m.t, m.state.State, SubmitCommit)
|
|
|
|
|
|
|
|
m.planSingle(SectorCommitSubmitted{})
|
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
|
|
|
|
2023-09-21 15:37:02 +00:00
|
|
|
expected := []SectorState{Packing, GetTicket, PreCommit1, PreCommit2, SubmitPreCommitBatch, PreCommitBatchWait, WaitSeed, Committing, SubmitCommit, CommitWait, FinalizeSector, Proving}
|
2020-08-11 12:22:35 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-06-11 09:52:00 +00:00
|
|
|
func TestHappyPathFinalizeEarly(t *testing.T) {
|
|
|
|
var notif []struct{ before, after SectorInfo }
|
|
|
|
ma, _ := address.NewIDAddress(55151)
|
|
|
|
m := test{
|
|
|
|
s: &Sealing{
|
|
|
|
maddr: ma,
|
|
|
|
stats: SectorStats{
|
2021-10-19 16:52:54 +00:00
|
|
|
bySector: map[abi.SectorID]SectorState{},
|
|
|
|
byState: map[SectorState]int64{},
|
2021-06-11 09:52:00 +00:00
|
|
|
},
|
|
|
|
notifee: func(before, after SectorInfo) {
|
|
|
|
notif = append(notif, struct{ before, after SectorInfo }{before, after})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
t: t,
|
|
|
|
state: &SectorInfo{State: Packing},
|
|
|
|
}
|
|
|
|
|
|
|
|
m.planSingle(SectorPacked{})
|
|
|
|
require.Equal(m.t, m.state.State, GetTicket)
|
|
|
|
|
|
|
|
m.planSingle(SectorTicket{})
|
|
|
|
require.Equal(m.t, m.state.State, PreCommit1)
|
|
|
|
|
|
|
|
m.planSingle(SectorPreCommit1{})
|
|
|
|
require.Equal(m.t, m.state.State, PreCommit2)
|
|
|
|
|
|
|
|
m.planSingle(SectorPreCommit2{})
|
2023-09-21 15:37:02 +00:00
|
|
|
require.Equal(m.t, m.state.State, SubmitPreCommitBatch)
|
2021-06-11 09:52:00 +00:00
|
|
|
|
2023-09-21 15:37:02 +00:00
|
|
|
m.planSingle(SectorPreCommitBatchSent{})
|
|
|
|
require.Equal(m.t, m.state.State, PreCommitBatchWait)
|
2021-06-11 09:52:00 +00:00
|
|
|
|
|
|
|
m.planSingle(SectorPreCommitLanded{})
|
|
|
|
require.Equal(m.t, m.state.State, WaitSeed)
|
|
|
|
|
|
|
|
m.planSingle(SectorSeedReady{})
|
|
|
|
require.Equal(m.t, m.state.State, Committing)
|
|
|
|
|
|
|
|
m.planSingle(SectorProofReady{})
|
|
|
|
require.Equal(m.t, m.state.State, CommitFinalize)
|
|
|
|
|
|
|
|
m.planSingle(SectorFinalized{})
|
|
|
|
require.Equal(m.t, m.state.State, SubmitCommit)
|
|
|
|
|
|
|
|
m.planSingle(SectorSubmitCommitAggregate{})
|
|
|
|
require.Equal(m.t, m.state.State, SubmitCommitAggregate)
|
|
|
|
|
|
|
|
m.planSingle(SectorCommitAggregateSent{})
|
2021-09-01 09:31:49 +00:00
|
|
|
require.Equal(m.t, m.state.State, CommitAggregateWait)
|
2021-06-11 09:52:00 +00:00
|
|
|
|
|
|
|
m.planSingle(SectorProving{})
|
|
|
|
require.Equal(m.t, m.state.State, FinalizeSector)
|
|
|
|
|
|
|
|
m.planSingle(SectorFinalized{})
|
|
|
|
require.Equal(m.t, m.state.State, Proving)
|
|
|
|
|
2023-09-21 15:37:02 +00:00
|
|
|
expected := []SectorState{Packing, GetTicket, PreCommit1, PreCommit2, SubmitPreCommitBatch, PreCommitBatchWait, WaitSeed, Committing, CommitFinalize, SubmitCommit, SubmitCommitAggregate, CommitAggregateWait, FinalizeSector, Proving}
|
2021-06-11 09:52:00 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-18 04:09:02 +00:00
|
|
|
func TestCommitFinalizeFailed(t *testing.T) {
|
|
|
|
var notif []struct{ before, after SectorInfo }
|
|
|
|
ma, _ := address.NewIDAddress(55151)
|
|
|
|
m := test{
|
|
|
|
s: &Sealing{
|
|
|
|
maddr: ma,
|
|
|
|
stats: SectorStats{
|
2021-10-19 16:52:54 +00:00
|
|
|
bySector: map[abi.SectorID]SectorState{},
|
|
|
|
byState: map[SectorState]int64{},
|
2021-06-18 04:09:02 +00:00
|
|
|
},
|
|
|
|
notifee: func(before, after SectorInfo) {
|
|
|
|
notif = append(notif, struct{ before, after SectorInfo }{before, after})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
t: t,
|
|
|
|
state: &SectorInfo{State: Committing},
|
|
|
|
}
|
|
|
|
|
|
|
|
m.planSingle(SectorProofReady{})
|
|
|
|
require.Equal(m.t, m.state.State, CommitFinalize)
|
|
|
|
|
|
|
|
m.planSingle(SectorFinalizeFailed{})
|
|
|
|
require.Equal(m.t, m.state.State, CommitFinalizeFailed)
|
|
|
|
|
|
|
|
m.planSingle(SectorRetryFinalize{})
|
|
|
|
require.Equal(m.t, m.state.State, CommitFinalize)
|
|
|
|
|
|
|
|
m.planSingle(SectorFinalized{})
|
|
|
|
require.Equal(m.t, m.state.State, SubmitCommit)
|
|
|
|
|
|
|
|
expected := []SectorState{Committing, CommitFinalize, CommitFinalizeFailed, CommitFinalize, SubmitCommit}
|
|
|
|
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{
|
2021-10-19 16:52:54 +00:00
|
|
|
bySector: map[abi.SectorID]SectorState{},
|
|
|
|
byState: map[SectorState]int64{},
|
2020-08-18 16:27:28 +00:00
|
|
|
},
|
|
|
|
},
|
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-09-30 17:11:58 +00:00
|
|
|
require.Equal(m.t, m.state.State, GetTicket)
|
|
|
|
|
|
|
|
m.planSingle(SectorTicket{})
|
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{})
|
2023-09-21 15:37:02 +00:00
|
|
|
require.Equal(m.t, m.state.State, SubmitPreCommitBatch)
|
2020-01-15 20:49:11 +00:00
|
|
|
|
2023-09-21 15:37:02 +00:00
|
|
|
m.planSingle(SectorPreCommitBatchSent{})
|
|
|
|
require.Equal(m.t, m.state.State, PreCommitBatchWait)
|
2020-05-18 22:49:21 +00:00
|
|
|
|
|
|
|
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-08-27 19:34:45 +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-08-27 19:34:45 +00:00
|
|
|
_, _, err = m.s.plan([]statemachine.Event{{User: SectorSeedReady{SeedValue: nil, SeedEpoch: 5}}, {User: SectorCommitted{}}}, m.state)
|
2020-04-07 00:29:52 +00:00
|
|
|
require.NoError(t, err)
|
2020-08-27 20:41:35 +00:00
|
|
|
require.Equal(m.t, m.state.State, SubmitCommit)
|
|
|
|
|
|
|
|
m.planSingle(SectorCommitSubmitted{})
|
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{
|
2021-10-19 16:52:54 +00:00
|
|
|
bySector: map[abi.SectorID]SectorState{},
|
|
|
|
byState: map[SectorState]int64{},
|
2020-08-18 16:27:28 +00:00
|
|
|
},
|
|
|
|
},
|
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
|
|
|
|
2020-08-27 19:34:45 +00:00
|
|
|
_, err := planCommitting(events, m.state)
|
|
|
|
require.NoError(t, err)
|
2020-01-28 20:39:07 +00:00
|
|
|
|
2020-04-06 20:23:37 +00:00
|
|
|
require.Equal(t, CommitFailed, m.state.State)
|
2020-01-28 20:39:07 +00:00
|
|
|
}
|
2020-11-26 09:58:07 +00:00
|
|
|
|
|
|
|
func TestPlannerList(t *testing.T) {
|
|
|
|
for state := range ExistSectorStateList {
|
|
|
|
_, ok := fsmPlanners[state]
|
|
|
|
require.True(t, ok, "state %s", state)
|
|
|
|
}
|
|
|
|
|
|
|
|
for state := range fsmPlanners {
|
|
|
|
if state == UndefinedSectorState {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
_, ok := ExistSectorStateList[state]
|
|
|
|
require.True(t, ok, "state %s", state)
|
|
|
|
}
|
|
|
|
}
|
2021-04-06 13:38:13 +00:00
|
|
|
|
|
|
|
func TestBrokenState(t *testing.T) {
|
|
|
|
var notif []struct{ before, after SectorInfo }
|
|
|
|
ma, _ := address.NewIDAddress(55151)
|
|
|
|
m := test{
|
|
|
|
s: &Sealing{
|
|
|
|
maddr: ma,
|
|
|
|
stats: SectorStats{
|
2021-10-19 16:52:54 +00:00
|
|
|
bySector: map[abi.SectorID]SectorState{},
|
|
|
|
byState: map[SectorState]int64{},
|
2021-04-06 13:38:13 +00:00
|
|
|
},
|
|
|
|
notifee: func(before, after SectorInfo) {
|
|
|
|
notif = append(notif, struct{ before, after SectorInfo }{before, after})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
t: t,
|
|
|
|
state: &SectorInfo{State: "not a state"},
|
|
|
|
}
|
|
|
|
|
|
|
|
_, _, err := m.s.plan([]statemachine.Event{{User: SectorPacked{}}}, m.state)
|
|
|
|
require.Error(t, err)
|
|
|
|
require.Equal(m.t, m.state.State, SectorState("not a state"))
|
|
|
|
|
|
|
|
m.planSingle(SectorRemove{})
|
|
|
|
require.Equal(m.t, m.state.State, Removing)
|
|
|
|
|
|
|
|
expected := []SectorState{"not a state", "not a state", Removing}
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-05-21 03:45:57 +00:00
|
|
|
|
2022-03-17 14:40:11 +00:00
|
|
|
func TestBadEvent(t *testing.T) {
|
|
|
|
var notif []struct{ before, after SectorInfo }
|
|
|
|
ma, _ := address.NewIDAddress(55151)
|
|
|
|
m := test{
|
|
|
|
s: &Sealing{
|
|
|
|
maddr: ma,
|
|
|
|
stats: SectorStats{
|
|
|
|
bySector: map[abi.SectorID]SectorState{},
|
|
|
|
byState: map[SectorState]int64{},
|
|
|
|
},
|
|
|
|
notifee: func(before, after SectorInfo) {
|
|
|
|
notif = append(notif, struct{ before, after SectorInfo }{before, after})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
t: t,
|
|
|
|
state: &SectorInfo{State: Proving},
|
|
|
|
}
|
|
|
|
|
|
|
|
_, processed, err := m.s.Plan([]statemachine.Event{{User: SectorPacked{}}}, m.state)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, uint64(1), processed)
|
|
|
|
require.Equal(m.t, m.state.State, Proving)
|
|
|
|
|
|
|
|
require.Len(t, m.state.Log, 2)
|
|
|
|
require.Contains(t, m.state.Log[1].Message, "received unexpected event")
|
|
|
|
}
|
|
|
|
|
2021-05-21 03:45:57 +00:00
|
|
|
func TestTicketExpired(t *testing.T) {
|
|
|
|
var notif []struct{ before, after SectorInfo }
|
|
|
|
ma, _ := address.NewIDAddress(55151)
|
|
|
|
m := test{
|
|
|
|
s: &Sealing{
|
|
|
|
maddr: ma,
|
|
|
|
stats: SectorStats{
|
2021-10-19 16:52:54 +00:00
|
|
|
bySector: map[abi.SectorID]SectorState{},
|
|
|
|
byState: map[SectorState]int64{},
|
2021-05-21 03:45:57 +00:00
|
|
|
},
|
|
|
|
notifee: func(before, after SectorInfo) {
|
|
|
|
notif = append(notif, struct{ before, after SectorInfo }{before, after})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
t: t,
|
|
|
|
state: &SectorInfo{State: Packing},
|
|
|
|
}
|
|
|
|
|
|
|
|
m.planSingle(SectorPacked{})
|
|
|
|
require.Equal(m.t, m.state.State, GetTicket)
|
|
|
|
|
|
|
|
m.planSingle(SectorTicket{})
|
|
|
|
require.Equal(m.t, m.state.State, PreCommit1)
|
|
|
|
|
|
|
|
expired := checkTicketExpired(0, MaxTicketAge+1)
|
|
|
|
require.True(t, expired)
|
|
|
|
|
|
|
|
m.planSingle(SectorOldTicket{})
|
|
|
|
require.Equal(m.t, m.state.State, GetTicket)
|
|
|
|
|
|
|
|
expected := []SectorState{Packing, GetTicket, PreCommit1, GetTicket}
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-11-14 17:25:47 +00:00
|
|
|
|
|
|
|
func TestCreationTimeCleared(t *testing.T) {
|
|
|
|
var notif []struct{ before, after SectorInfo }
|
|
|
|
ma, _ := address.NewIDAddress(55151)
|
|
|
|
m := test{
|
|
|
|
s: &Sealing{
|
|
|
|
maddr: ma,
|
|
|
|
stats: SectorStats{
|
|
|
|
bySector: map[abi.SectorID]SectorState{},
|
|
|
|
byState: map[SectorState]int64{},
|
|
|
|
},
|
|
|
|
notifee: func(before, after SectorInfo) {
|
|
|
|
notif = append(notif, struct{ before, after SectorInfo }{before, after})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
t: t,
|
|
|
|
state: &SectorInfo{State: Available},
|
|
|
|
}
|
|
|
|
|
|
|
|
// sector starts with zero CreationTime
|
|
|
|
m.planSingle(SectorStartCCUpdate{})
|
|
|
|
require.Equal(m.t, m.state.State, SnapDealsWaitDeals)
|
|
|
|
|
|
|
|
require.Equal(t, int64(0), m.state.CreationTime)
|
|
|
|
|
|
|
|
// First AddPiece will set CreationTime
|
|
|
|
m.planSingle(SectorAddPiece{})
|
|
|
|
require.Equal(m.t, m.state.State, SnapDealsAddPiece)
|
|
|
|
|
|
|
|
require.NotEqual(t, int64(0), m.state.CreationTime)
|
|
|
|
|
|
|
|
m.planSingle(SectorPieceAdded{})
|
|
|
|
require.Equal(m.t, m.state.State, SnapDealsWaitDeals)
|
|
|
|
|
|
|
|
// abort shoult clean up CreationTime
|
|
|
|
m.planSingle(SectorAbortUpgrade{})
|
|
|
|
require.Equal(m.t, m.state.State, AbortUpgrade)
|
|
|
|
|
|
|
|
require.NotEqual(t, int64(0), m.state.CreationTime)
|
|
|
|
|
|
|
|
m.planSingle(SectorRevertUpgradeToProving{})
|
|
|
|
require.Equal(m.t, m.state.State, Proving)
|
|
|
|
|
|
|
|
require.Equal(t, int64(0), m.state.CreationTime)
|
|
|
|
|
|
|
|
m.planSingle(SectorMarkForUpdate{})
|
|
|
|
|
|
|
|
// in case CreationTime was set for whatever reason (lotus bug / manual sector state change)
|
|
|
|
// make sure we clean it up when starting upgrade
|
|
|
|
m.state.CreationTime = 325
|
|
|
|
m.planSingle(SectorStartCCUpdate{})
|
|
|
|
require.Equal(m.t, m.state.State, SnapDealsWaitDeals)
|
|
|
|
|
|
|
|
require.Equal(t, int64(0), m.state.CreationTime)
|
|
|
|
|
|
|
|
// "First" AddPiece will set CreationTime
|
|
|
|
m.planSingle(SectorAddPiece{})
|
|
|
|
require.Equal(m.t, m.state.State, SnapDealsAddPiece)
|
|
|
|
|
|
|
|
require.NotEqual(t, int64(0), m.state.CreationTime)
|
|
|
|
}
|
2023-09-21 15:37:02 +00:00
|
|
|
|
|
|
|
func TestRetrySoftErr(t *testing.T) {
|
|
|
|
i := 0
|
|
|
|
|
|
|
|
tf := func() error {
|
|
|
|
i++
|
|
|
|
switch i {
|
|
|
|
case 1:
|
|
|
|
return storiface.Err(storiface.ErrTempAllocateSpace, xerrors.New("foo"))
|
|
|
|
case 2:
|
|
|
|
return nil
|
|
|
|
default:
|
|
|
|
t.Fatalf("what")
|
|
|
|
return xerrors.Errorf("this error didn't ever happen, and will never happen")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
err := retrySoftErr(context.Background(), tf)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, 2, i)
|
|
|
|
}
|