From d9a1ecd38778e614cdf85fbad681bc4570ef700b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Thu, 17 Mar 2022 15:40:11 +0100 Subject: [PATCH] fix: storagefsm: Fix error loop on bad event --- extern/storage-sealing/fsm.go | 2 +- extern/storage-sealing/fsm_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/extern/storage-sealing/fsm.go b/extern/storage-sealing/fsm.go index b85290f04..a02666135 100644 --- a/extern/storage-sealing/fsm.go +++ b/extern/storage-sealing/fsm.go @@ -399,7 +399,7 @@ func (m *Sealing) plan(events []statemachine.Event, state *SectorInfo) (func(sta processed, err := p(events, state) if err != nil { - return nil, 0, xerrors.Errorf("running planner for state %s failed: %w", state.State, err) + return nil, processed, xerrors.Errorf("running planner for state %s failed: %w", state.State, err) } ///// diff --git a/extern/storage-sealing/fsm_test.go b/extern/storage-sealing/fsm_test.go index 10ee17c6b..f3012a400 100644 --- a/extern/storage-sealing/fsm_test.go +++ b/extern/storage-sealing/fsm_test.go @@ -323,6 +323,33 @@ func TestBrokenState(t *testing.T) { } } +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") +} + func TestTicketExpired(t *testing.T) { var notif []struct{ before, after SectorInfo } ma, _ := address.NewIDAddress(55151)