From efe2d8da8a91eaa51980d634f5ab0a00a936df33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Mon, 14 Nov 2022 18:25:47 +0100 Subject: [PATCH] sealing pipeline: Test clearing CreationTime --- storage/pipeline/fsm_events.go | 1 + storage/pipeline/fsm_test.go | 61 ++++++++++++++++++++++++++++++++++ storage/pipeline/input.go | 2 +- 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/storage/pipeline/fsm_events.go b/storage/pipeline/fsm_events.go index 6842f70425f..c60f49ac5fe 100644 --- a/storage/pipeline/fsm_events.go +++ b/storage/pipeline/fsm_events.go @@ -461,6 +461,7 @@ func (evt SectorRevertUpgradeToProving) apply(state *SectorInfo) { state.ReplicaUpdateMessage = nil state.Pieces = state.CCPieces state.CCPieces = nil + state.CreationTime = 0 } type SectorRetrySubmitReplicaUpdateWait struct{} diff --git a/storage/pipeline/fsm_test.go b/storage/pipeline/fsm_test.go index 53f85d1dc9d..f12b66f9350 100644 --- a/storage/pipeline/fsm_test.go +++ b/storage/pipeline/fsm_test.go @@ -390,3 +390,64 @@ func TestTicketExpired(t *testing.T) { } } } + +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) +} diff --git a/storage/pipeline/input.go b/storage/pipeline/input.go index 6795b687e03..3499c855cc3 100644 --- a/storage/pipeline/input.go +++ b/storage/pipeline/input.go @@ -2,11 +2,11 @@ package sealing import ( "context" - "go.uber.org/zap" "sort" "time" "github.com/ipfs/go-cid" + "go.uber.org/zap" "golang.org/x/xerrors" "github.com/filecoin-project/go-commp-utils/zerocomm"