renaming PieceWithOptionalDealInfo -> Piece, drop PieceWithDealInfo

This commit is contained in:
laser 2020-04-08 07:52:20 -07:00
parent 5f3990d1bc
commit 0cd4e0413f
11 changed files with 54 additions and 53 deletions

View File

@ -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)

View File

@ -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)}
}
}

View File

@ -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
})

View File

@ -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,
}

View File

@ -11,7 +11,7 @@ import (
func main() {
err := gen.WriteMapEncodersToFile("./cbor_gen.go", "sealing",
sealing.PieceWithOptionalDealInfo{},
sealing.Piece{},
sealing.DealInfo{},
sealing.DealSchedule{},
sealing.SectorInfo{},

View File

@ -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

View File

@ -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),

View File

@ -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,

View File

@ -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)})
}

View File

@ -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

View File

@ -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)