From 0cd4e0413f1bcf37ed0867a9bbd9185475e4ee36 Mon Sep 17 00:00:00 2001 From: laser Date: Wed, 8 Apr 2020 07:52:20 -0700 Subject: [PATCH] renaming PieceWithOptionalDealInfo -> Piece, drop PieceWithDealInfo --- cbor_gen.go | 36 ++++++++++++++++++------------------ checks.go | 8 ++++---- fsm_events.go | 6 +++--- garbage.go | 4 ++-- gen/main.go | 2 +- precommit_policy.go | 4 ++-- precommit_policy_test.go | 6 +++--- sealing.go | 11 ++++++----- states.go | 4 ++-- types.go | 22 +++++++++++----------- types_test.go | 4 ++-- 11 files changed, 54 insertions(+), 53 deletions(-) diff --git a/cbor_gen.go b/cbor_gen.go index 37a75a662..b2bd03971 100644 --- a/cbor_gen.go +++ b/cbor_gen.go @@ -13,7 +13,7 @@ import ( var _ = xerrors.Errorf -func (t *PieceWithOptionalDealInfo) MarshalCBOR(w io.Writer) error { +func (t *Piece) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err @@ -56,7 +56,7 @@ func (t *PieceWithOptionalDealInfo) MarshalCBOR(w io.Writer) error { return nil } -func (t *PieceWithOptionalDealInfo) UnmarshalCBOR(r io.Reader) error { +func (t *Piece) UnmarshalCBOR(r io.Reader) error { br := cbg.GetPeeker(r) maj, extra, err := cbg.CborReadHeader(br) @@ -68,7 +68,7 @@ func (t *PieceWithOptionalDealInfo) UnmarshalCBOR(r io.Reader) error { } if extra > cbg.MaxLength { - return fmt.Errorf("PieceWithOptionalDealInfo: map struct too large (%d)", extra) + return fmt.Errorf("Piece: map struct too large (%d)", extra) } var name string @@ -463,26 +463,26 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { } } - // t.PiecesWithOptionalDealInfo ([]sealing.PieceWithOptionalDealInfo) (slice) - if len("PiecesWithOptionalDealInfo") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"PiecesWithOptionalDealInfo\" was too long") + // t.Pieces ([]sealing.Piece) (slice) + if len("Pieces") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"Pieces\" was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("PiecesWithOptionalDealInfo")))); err != nil { + if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Pieces")))); err != nil { return err } - if _, err := w.Write([]byte("PiecesWithOptionalDealInfo")); err != nil { + if _, err := w.Write([]byte("Pieces")); err != nil { return err } - if len(t.PiecesWithOptionalDealInfo) > cbg.MaxLength { - return xerrors.Errorf("Slice value in field t.PiecesWithOptionalDealInfo was too long") + if len(t.Pieces) > cbg.MaxLength { + return xerrors.Errorf("Slice value in field t.Pieces was too long") } - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.PiecesWithOptionalDealInfo)))); err != nil { + if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Pieces)))); err != nil { return err } - for _, v := range t.PiecesWithOptionalDealInfo { + for _, v := range t.Pieces { if err := v.MarshalCBOR(w); err != nil { return err } @@ -897,8 +897,8 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { t.SectorType = abi.RegisteredProof(extraI) } - // t.PiecesWithOptionalDealInfo ([]sealing.PieceWithOptionalDealInfo) (slice) - case "PiecesWithOptionalDealInfo": + // t.Pieces ([]sealing.Piece) (slice) + case "Pieces": maj, extra, err = cbg.CborReadHeader(br) if err != nil { @@ -906,23 +906,23 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { } if extra > cbg.MaxLength { - return fmt.Errorf("t.PiecesWithOptionalDealInfo: array too large (%d)", extra) + return fmt.Errorf("t.Pieces: array too large (%d)", extra) } if maj != cbg.MajArray { return fmt.Errorf("expected cbor array") } if extra > 0 { - t.PiecesWithOptionalDealInfo = make([]PieceWithOptionalDealInfo, extra) + t.Pieces = make([]Piece, extra) } for i := 0; i < int(extra); i++ { - var v PieceWithOptionalDealInfo + var v Piece if err := v.UnmarshalCBOR(br); err != nil { return err } - t.PiecesWithOptionalDealInfo[i] = v + t.Pieces[i] = v } // t.TicketValue (abi.SealRandomness) (slice) diff --git a/checks.go b/checks.go index 8e0e10881..bdd6b5761 100644 --- a/checks.go +++ b/checks.go @@ -33,7 +33,7 @@ func checkPieces(ctx context.Context, si SectorInfo, api SealingAPI) error { return &ErrApi{xerrors.Errorf("getting chain head: %w", err)} } - for i, pdi := range si.PiecesWithOptionalDealInfo { + for i, pdi := range si.Pieces { // if no deal is associated with the piece, ensure that we added it as // filler (i.e. ensure that it has a zero PieceCID) if pdi.DealInfo == nil { @@ -50,15 +50,15 @@ func checkPieces(ctx context.Context, si SectorInfo, api SealingAPI) error { } if proposal.PieceCID != pdi.Piece.PieceCID { - return &ErrInvalidDeals{xerrors.Errorf("piece %d (of %d) of sector %d refers deal %d with wrong PieceCID: %x != %x", i, len(si.PiecesWithOptionalDealInfo), si.SectorNumber, pdi.DealInfo.DealID, pdi.Piece.PieceCID, proposal.PieceCID)} + return &ErrInvalidDeals{xerrors.Errorf("piece %d (of %d) of sector %d refers deal %d with wrong PieceCID: %x != %x", i, len(si.Pieces), si.SectorNumber, pdi.DealInfo.DealID, pdi.Piece.PieceCID, proposal.PieceCID)} } if pdi.Piece.Size != proposal.PieceSize { - return &ErrInvalidDeals{xerrors.Errorf("piece %d (of %d) of sector %d refers deal %d with different size: %d != %d", i, len(si.PiecesWithOptionalDealInfo), si.SectorNumber, pdi.DealInfo.DealID, pdi.Piece.Size, proposal.PieceSize)} + return &ErrInvalidDeals{xerrors.Errorf("piece %d (of %d) of sector %d refers deal %d with different size: %d != %d", i, len(si.Pieces), si.SectorNumber, pdi.DealInfo.DealID, pdi.Piece.Size, proposal.PieceSize)} } if height >= proposal.StartEpoch { - return &ErrExpiredDeals{xerrors.Errorf("piece %d (of %d) of sector %d refers expired deal %d - should start at %d, head %d", i, len(si.PiecesWithOptionalDealInfo), si.SectorNumber, pdi.DealInfo.DealID, proposal.StartEpoch, height)} + return &ErrExpiredDeals{xerrors.Errorf("piece %d (of %d) of sector %d refers expired deal %d - should start at %d, head %d", i, len(si.Pieces), si.SectorNumber, pdi.DealInfo.DealID, proposal.StartEpoch, height)} } } diff --git a/fsm_events.go b/fsm_events.go index d7d79c42d..a0f6c6368 100644 --- a/fsm_events.go +++ b/fsm_events.go @@ -50,12 +50,12 @@ func (evt SectorForceState) applyGlobal(state *SectorInfo) bool { type SectorStart struct { ID abi.SectorNumber SectorType abi.RegisteredProof - Pieces []PieceWithOptionalDealInfo + Pieces []Piece } func (evt SectorStart) apply(state *SectorInfo) { state.SectorNumber = evt.ID - state.PiecesWithOptionalDealInfo = evt.Pieces + state.Pieces = evt.Pieces state.SectorType = evt.SectorType } @@ -63,7 +63,7 @@ type SectorPacked struct{ FillerPieces []abi.PieceInfo } func (evt SectorPacked) apply(state *SectorInfo) { for idx := range evt.FillerPieces { - state.PiecesWithOptionalDealInfo = append(state.PiecesWithOptionalDealInfo, PieceWithOptionalDealInfo{ + state.Pieces = append(state.Pieces, Piece{ Piece: evt.FillerPieces[idx], DealInfo: nil, // filler pieces don't have deals associated with them }) diff --git a/garbage.go b/garbage.go index 797989fad..694f6aea1 100644 --- a/garbage.go +++ b/garbage.go @@ -69,9 +69,9 @@ func (m *Sealing) PledgeSector() error { return } - pdis := make([]PieceWithOptionalDealInfo, len(pieces)) + pdis := make([]Piece, len(pieces)) for idx := range pdis { - pdis[idx] = PieceWithOptionalDealInfo{ + pdis[idx] = Piece{ Piece: pieces[idx], DealInfo: nil, } diff --git a/gen/main.go b/gen/main.go index e9a68425a..0d5f7507b 100644 --- a/gen/main.go +++ b/gen/main.go @@ -11,7 +11,7 @@ import ( func main() { err := gen.WriteMapEncodersToFile("./cbor_gen.go", "sealing", - sealing.PieceWithOptionalDealInfo{}, + sealing.Piece{}, sealing.DealInfo{}, sealing.DealSchedule{}, sealing.SectorInfo{}, diff --git a/precommit_policy.go b/precommit_policy.go index 58ddcb492..c0c855f73 100644 --- a/precommit_policy.go +++ b/precommit_policy.go @@ -7,7 +7,7 @@ import ( ) type PreCommitPolicy interface { - Expiration(ctx context.Context, pdis ...PieceWithOptionalDealInfo) (abi.ChainEpoch, error) + Expiration(ctx context.Context, pdis ...Piece) (abi.ChainEpoch, error) } type Chain interface { @@ -44,7 +44,7 @@ func NewBasicPreCommitPolicy(api Chain, duration abi.ChainEpoch) BasicPreCommitP // Expiration produces the pre-commit sector expiration epoch for an encoded // replica containing the provided enumeration of pieces and deals. -func (p *BasicPreCommitPolicy) Expiration(ctx context.Context, pdis ...PieceWithOptionalDealInfo) (abi.ChainEpoch, error) { +func (p *BasicPreCommitPolicy) Expiration(ctx context.Context, pdis ...Piece) (abi.ChainEpoch, error) { _, epoch, err := p.api.ChainHead(ctx) if err != nil { return 0, nil diff --git a/precommit_policy_test.go b/precommit_policy_test.go index d28f71825..762e34685 100644 --- a/precommit_policy_test.go +++ b/precommit_policy_test.go @@ -37,7 +37,7 @@ func TestBasicPolicyMostConstrictiveSchedule(t *testing.T) { h: abi.ChainEpoch(55), }, 100) - pieces := []sealing.PieceWithOptionalDealInfo{ + pieces := []sealing.Piece{ { Piece: abi.PieceInfo{ Size: abi.PaddedPieceSize(1024), @@ -77,7 +77,7 @@ func TestBasicPolicyIgnoresExistingScheduleIfExpired(t *testing.T) { h: abi.ChainEpoch(55), }, 100) - pieces := []sealing.PieceWithOptionalDealInfo{ + pieces := []sealing.Piece{ { Piece: abi.PieceInfo{ Size: abi.PaddedPieceSize(1024), @@ -104,7 +104,7 @@ func TestMissingDealIsIgnored(t *testing.T) { h: abi.ChainEpoch(55), }, 100) - pieces := []sealing.PieceWithOptionalDealInfo{ + pieces := []sealing.Piece{ { Piece: abi.PieceInfo{ Size: abi.PaddedPieceSize(1024), diff --git a/sealing.go b/sealing.go index 99fafa549..837ba279d 100644 --- a/sealing.go +++ b/sealing.go @@ -35,6 +35,7 @@ type SealingAPI interface { SendMsg(ctx context.Context, from, to address.Address, method abi.MethodNum, value, gasPrice big.Int, gasLimit int64, params []byte) (cid.Cid, error) ChainHead(ctx context.Context) (TipSetToken, abi.ChainEpoch, error) ChainGetRandomness(ctx context.Context, tok TipSetToken, personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte) (abi.Randomness, error) + ChainReadObj(context.Context, cid.Cid) ([]byte, error) } type Sealing struct { @@ -104,8 +105,8 @@ func (m *Sealing) AllocatePiece(size abi.UnpaddedPieceSize) (sectorID abi.Sector return sid, 0, nil } -func (m *Sealing) SealPiece(ctx context.Context, size abi.UnpaddedPieceSize, r io.Reader, sectorID abi.SectorNumber, pdi PieceWithDealInfo) error { - log.Infof("Seal piece for deal %d", pdi.DealInfo.DealID) +func (m *Sealing) SealPiece(ctx context.Context, size abi.UnpaddedPieceSize, r io.Reader, sectorID abi.SectorNumber, d DealInfo) error { + log.Infof("Seal piece for deal %d", d.DealID) ppi, err := m.sealer.AddPiece(ctx, m.minerSector(sectorID), []abi.UnpaddedPieceSize{}, size, r) if err != nil { @@ -117,10 +118,10 @@ func (m *Sealing) SealPiece(ctx context.Context, size abi.UnpaddedPieceSize, r i return xerrors.Errorf("bad sector size: %w", err) } - return m.newSector(sectorID, rt, []PieceWithOptionalDealInfo{ + return m.newSector(sectorID, rt, []Piece{ { Piece: ppi, - DealInfo: &pdi.DealInfo, + DealInfo: &d, }, }) } @@ -128,7 +129,7 @@ func (m *Sealing) SealPiece(ctx context.Context, size abi.UnpaddedPieceSize, r i // newSector accepts a slice of pieces which will have a deal associated with // them (in the event of a storage deal) or no deal (in the event of sealing // garbage data) -func (m *Sealing) newSector(sid abi.SectorNumber, rt abi.RegisteredProof, pieces []PieceWithOptionalDealInfo) error { +func (m *Sealing) newSector(sid abi.SectorNumber, rt abi.RegisteredProof, pieces []Piece) error { log.Infof("Start sealing %d", sid) return m.sectors.Send(uint64(sid), SectorStart{ ID: sid, diff --git a/states.go b/states.go index d6b057606..aca00f4b3 100644 --- a/states.go +++ b/states.go @@ -19,7 +19,7 @@ func (m *Sealing) handlePacking(ctx statemachine.Context, sector SectorInfo) err log.Infow("performing filling up rest of the sector...", "sector", sector.SectorNumber) var allocated abi.UnpaddedPieceSize - for _, piece := range sector.PiecesWithOptionalDealInfo { + for _, piece := range sector.Pieces { allocated += piece.Piece.Size.Unpadded() } @@ -112,7 +112,7 @@ func (m *Sealing) handlePreCommitting(ctx statemachine.Context, sector SectorInf } } - expiration, err := m.pcp.Expiration(ctx.Context(), sector.PiecesWithOptionalDealInfo...) + expiration, err := m.pcp.Expiration(ctx.Context(), sector.Pieces...) if err != nil { return ctx.Send(SectorSealPreCommitFailed{xerrors.Errorf("handlePreCommitting: failed to compute pre-commit expiry: %w", err)}) } diff --git a/types.go b/types.go index a6d6a2b5f..5d8019721 100644 --- a/types.go +++ b/types.go @@ -11,16 +11,16 @@ import ( "github.com/filecoin-project/specs-storage/storage" ) -// PieceWithOptionalDealInfo is a tuple of piece and deal info +// Piece is a tuple of piece and deal info type PieceWithDealInfo struct { Piece abi.PieceInfo DealInfo DealInfo } -// PieceWithOptionalDealInfo is a tuple of piece info and optional deal -type PieceWithOptionalDealInfo struct { +// Piece is a tuple of piece info and optional deal +type Piece struct { Piece abi.PieceInfo - DealInfo *DealInfo // nil for pieces which do not yet appear in self-deals + DealInfo *DealInfo // nil for pieces which do not appear in deals (e.g. filler pieces) } // DealInfo is a tuple of deal identity and its schedule @@ -55,7 +55,7 @@ type SectorInfo struct { SectorType abi.RegisteredProof // Packing - PiecesWithOptionalDealInfo []PieceWithOptionalDealInfo + Pieces []Piece // PreCommit1 TicketValue abi.SealRandomness @@ -87,8 +87,8 @@ type SectorInfo struct { } func (t *SectorInfo) pieceInfos() []abi.PieceInfo { - out := make([]abi.PieceInfo, len(t.PiecesWithOptionalDealInfo)) - for i, pdi := range t.PiecesWithOptionalDealInfo { + out := make([]abi.PieceInfo, len(t.Pieces)) + for i, pdi := range t.Pieces { out[i] = abi.PieceInfo{ Size: pdi.Piece.Size, PieceCID: pdi.Piece.PieceCID, @@ -98,8 +98,8 @@ func (t *SectorInfo) pieceInfos() []abi.PieceInfo { } func (t *SectorInfo) dealIDs() []abi.DealID { - out := make([]abi.DealID, 0, len(t.PiecesWithOptionalDealInfo)) - for _, pdi := range t.PiecesWithOptionalDealInfo { + out := make([]abi.DealID, 0, len(t.Pieces)) + for _, pdi := range t.Pieces { if pdi.DealInfo == nil { continue } @@ -109,8 +109,8 @@ func (t *SectorInfo) dealIDs() []abi.DealID { } func (t *SectorInfo) existingPieceSizes() []abi.UnpaddedPieceSize { - out := make([]abi.UnpaddedPieceSize, len(t.PiecesWithOptionalDealInfo)) - for i, pdi := range t.PiecesWithOptionalDealInfo { + out := make([]abi.UnpaddedPieceSize, len(t.Pieces)) + for i, pdi := range t.Pieces { out[i] = pdi.Piece.Size.Unpadded() } return out diff --git a/types_test.go b/types_test.go index 379c59564..9bb1df8cf 100644 --- a/types_test.go +++ b/types_test.go @@ -28,7 +28,7 @@ func TestSectorInfoSelialization(t *testing.T) { State: "stateful", SectorNumber: 234, Nonce: 345, - PiecesWithOptionalDealInfo: []PieceWithOptionalDealInfo{{ + Pieces: []Piece{{ Piece: abi.PieceInfo{ Size: 5, PieceCID: dummyCid, @@ -62,7 +62,7 @@ func TestSectorInfoSelialization(t *testing.T) { assert.Equal(t, si.Nonce, si2.Nonce) assert.Equal(t, si.SectorNumber, si2.SectorNumber) - assert.Equal(t, si.PiecesWithOptionalDealInfo, si2.PiecesWithOptionalDealInfo) + assert.Equal(t, si.Pieces, si2.Pieces) assert.Equal(t, si.CommD, si2.CommD) assert.Equal(t, si.TicketValue, si2.TicketValue) assert.Equal(t, si.TicketEpoch, si2.TicketEpoch)