From 21629d005bc653c7ade2ec9dbc963de1c4bc0731 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 3 Dec 2019 23:57:47 +0100 Subject: [PATCH] storageminer: separate sectorstore types --- storage/sector_types.go | 107 ++++++++++++++++++ storage/{sealing_utils.go => sector_utils.go} | 0 ...ing_utils_test.go => sector_utils_test.go} | 0 storage/{sealing.go => sectors.go} | 98 ---------------- 4 files changed, 107 insertions(+), 98 deletions(-) create mode 100644 storage/sector_types.go rename storage/{sealing_utils.go => sector_utils.go} (100%) rename storage/{sealing_utils_test.go => sector_utils_test.go} (100%) rename storage/{sealing.go => sectors.go} (72%) diff --git a/storage/sector_types.go b/storage/sector_types.go new file mode 100644 index 000000000..67b394732 --- /dev/null +++ b/storage/sector_types.go @@ -0,0 +1,107 @@ +package storage + +import ( + "context" + + "github.com/ipfs/go-cid" + + "github.com/filecoin-project/lotus/api" + "github.com/filecoin-project/lotus/lib/sectorbuilder" +) + +type TicketFn func(context.Context) (*sectorbuilder.SealTicket, error) + +type SealTicket struct { + BlockHeight uint64 + TicketBytes []byte +} + +func (t *SealTicket) SB() sectorbuilder.SealTicket { + out := sectorbuilder.SealTicket{BlockHeight: t.BlockHeight} + copy(out.TicketBytes[:], t.TicketBytes) + return out +} + +type SealSeed struct { + BlockHeight uint64 + TicketBytes []byte +} + +func (t *SealSeed) SB() sectorbuilder.SealSeed { + out := sectorbuilder.SealSeed{BlockHeight: t.BlockHeight} + copy(out.TicketBytes[:], t.TicketBytes) + return out +} + +type Piece struct { + DealID uint64 + + Size uint64 + CommP []byte +} + +func (p *Piece) ppi() (out sectorbuilder.PublicPieceInfo) { + out.Size = p.Size + copy(out.CommP[:], p.CommP) + return out +} + +type SectorInfo struct { + State api.SectorState + SectorID uint64 + + // Packing + + Pieces []Piece + + // PreCommit + CommC []byte + CommD []byte + CommR []byte + CommRLast []byte + Proof []byte + Ticket SealTicket + + PreCommitMessage *cid.Cid + + // PreCommitted + Seed SealSeed + + // Committing + CommitMessage *cid.Cid +} + +func (t *SectorInfo) pieceInfos() []sectorbuilder.PublicPieceInfo { + out := make([]sectorbuilder.PublicPieceInfo, len(t.Pieces)) + for i, piece := range t.Pieces { + out[i] = piece.ppi() + } + return out +} + +func (t *SectorInfo) deals() []uint64 { + out := make([]uint64, len(t.Pieces)) + for i, piece := range t.Pieces { + out[i] = piece.DealID + } + return out +} + +func (t *SectorInfo) existingPieces() []uint64 { + out := make([]uint64, len(t.Pieces)) + for i, piece := range t.Pieces { + out[i] = piece.Size + } + return out +} + +func (t *SectorInfo) rspco() sectorbuilder.RawSealPreCommitOutput { + var out sectorbuilder.RawSealPreCommitOutput + + copy(out.CommC[:], t.CommC) + copy(out.CommD[:], t.CommD) + copy(out.CommR[:], t.CommR) + copy(out.CommRLast[:], t.CommRLast) + + return out +} diff --git a/storage/sealing_utils.go b/storage/sector_utils.go similarity index 100% rename from storage/sealing_utils.go rename to storage/sector_utils.go diff --git a/storage/sealing_utils_test.go b/storage/sector_utils_test.go similarity index 100% rename from storage/sealing_utils_test.go rename to storage/sector_utils_test.go diff --git a/storage/sealing.go b/storage/sectors.go similarity index 72% rename from storage/sealing.go rename to storage/sectors.go index 7628fabd8..583fdc71d 100644 --- a/storage/sealing.go +++ b/storage/sectors.go @@ -4,7 +4,6 @@ import ( "context" "io" - cid "github.com/ipfs/go-cid" xerrors "golang.org/x/xerrors" "github.com/filecoin-project/lotus/api" @@ -12,68 +11,6 @@ import ( "github.com/filecoin-project/lotus/lib/sectorbuilder" ) -type TicketFn func(context.Context) (*sectorbuilder.SealTicket, error) - -type SealTicket struct { - BlockHeight uint64 - TicketBytes []byte -} - -func (t *SealTicket) SB() sectorbuilder.SealTicket { - out := sectorbuilder.SealTicket{BlockHeight: t.BlockHeight} - copy(out.TicketBytes[:], t.TicketBytes) - return out -} - -type SealSeed struct { - BlockHeight uint64 - TicketBytes []byte -} - -func (t *SealSeed) SB() sectorbuilder.SealSeed { - out := sectorbuilder.SealSeed{BlockHeight: t.BlockHeight} - copy(out.TicketBytes[:], t.TicketBytes) - return out -} - -type Piece struct { - DealID uint64 - - Size uint64 - CommP []byte -} - -func (p *Piece) ppi() (out sectorbuilder.PublicPieceInfo) { - out.Size = p.Size - copy(out.CommP[:], p.CommP) - return out -} - -type SectorInfo struct { - State api.SectorState - SectorID uint64 - - // Packing - - Pieces []Piece - - // PreCommit - CommC []byte - CommD []byte - CommR []byte - CommRLast []byte - Proof []byte - Ticket SealTicket - - PreCommitMessage *cid.Cid - - // PreCommitted - Seed SealSeed - - // Committing - CommitMessage *cid.Cid -} - type sectorUpdate struct { newState api.SectorState id uint64 @@ -81,41 +18,6 @@ type sectorUpdate struct { mut func(*SectorInfo) } -func (t *SectorInfo) pieceInfos() []sectorbuilder.PublicPieceInfo { - out := make([]sectorbuilder.PublicPieceInfo, len(t.Pieces)) - for i, piece := range t.Pieces { - out[i] = piece.ppi() - } - return out -} - -func (t *SectorInfo) deals() []uint64 { - out := make([]uint64, len(t.Pieces)) - for i, piece := range t.Pieces { - out[i] = piece.DealID - } - return out -} - -func (t *SectorInfo) existingPieces() []uint64 { - out := make([]uint64, len(t.Pieces)) - for i, piece := range t.Pieces { - out[i] = piece.Size - } - return out -} - -func (t *SectorInfo) rspco() sectorbuilder.RawSealPreCommitOutput { - var out sectorbuilder.RawSealPreCommitOutput - - copy(out.CommC[:], t.CommC) - copy(out.CommD[:], t.CommD) - copy(out.CommR[:], t.CommR) - copy(out.CommRLast[:], t.CommRLast) - - return out -} - func (m *Miner) sectorStateLoop(ctx context.Context) error { trackedSectors, err := m.ListSectors() if err != nil {