rename pdi ("peace with deal info") -> p ("piece")

This commit is contained in:
laser 2020-04-08 07:56:35 -07:00
parent 1dfca2ff76
commit f2649af5a1
4 changed files with 26 additions and 29 deletions

View File

@ -33,32 +33,32 @@ func checkPieces(ctx context.Context, si SectorInfo, api SealingAPI) error {
return &ErrApi{xerrors.Errorf("getting chain head: %w", err)} return &ErrApi{xerrors.Errorf("getting chain head: %w", err)}
} }
for i, pdi := range si.Pieces { for i, p := range si.Pieces {
// if no deal is associated with the piece, ensure that we added it as // if no deal is associated with the piece, ensure that we added it as
// filler (i.e. ensure that it has a zero PieceCID) // filler (i.e. ensure that it has a zero PieceCID)
if pdi.DealInfo == nil { if p.DealInfo == nil {
exp := zerocomm.ZeroPieceCommitment(pdi.Piece.Size.Unpadded()) exp := zerocomm.ZeroPieceCommitment(p.Piece.Size.Unpadded())
if !pdi.Piece.PieceCID.Equals(exp) { if !p.Piece.PieceCID.Equals(exp) {
return &ErrInvalidPiece{xerrors.Errorf("sector %d piece %d had non-zero PieceCID %+v", si.SectorNumber, i, pdi.Piece.PieceCID)} return &ErrInvalidPiece{xerrors.Errorf("sector %d piece %d had non-zero PieceCID %+v", si.SectorNumber, i, p.Piece.PieceCID)}
} }
continue continue
} }
proposal, _, err := api.StateMarketStorageDeal(ctx, pdi.DealInfo.DealID, tok) proposal, _, err := api.StateMarketStorageDeal(ctx, p.DealInfo.DealID, tok)
if err != nil { if err != nil {
return &ErrApi{xerrors.Errorf("getting deal %d for piece %d: %w", pdi.DealInfo.DealID, i, err)} return &ErrApi{xerrors.Errorf("getting deal %d for piece %d: %w", p.DealInfo.DealID, i, err)}
} }
if proposal.PieceCID != pdi.Piece.PieceCID { if proposal.PieceCID != p.Piece.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)} 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, p.DealInfo.DealID, p.Piece.PieceCID, proposal.PieceCID)}
} }
if pdi.Piece.Size != proposal.PieceSize { if p.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)} 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, p.DealInfo.DealID, p.Piece.Size, proposal.PieceSize)}
} }
if height >= proposal.StartEpoch { 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.Pieces), 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, p.DealInfo.DealID, proposal.StartEpoch, height)}
} }
} }

View File

@ -69,15 +69,15 @@ func (m *Sealing) PledgeSector() error {
return return
} }
pdis := make([]Piece, len(pieces)) ps := make([]Piece, len(pieces))
for idx := range pdis { for idx := range ps {
pdis[idx] = Piece{ ps[idx] = Piece{
Piece: pieces[idx], Piece: pieces[idx],
DealInfo: nil, DealInfo: nil,
} }
} }
if err := m.newSector(sid, rt, pdis); err != nil { if err := m.newSector(sid, rt, ps); err != nil {
log.Errorf("%+v", err) log.Errorf("%+v", err)
return return
} }

View File

@ -7,7 +7,7 @@ import (
) )
type PreCommitPolicy interface { type PreCommitPolicy interface {
Expiration(ctx context.Context, pdis ...Piece) (abi.ChainEpoch, error) Expiration(ctx context.Context, ps ...Piece) (abi.ChainEpoch, error)
} }
type Chain interface { 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 // Expiration produces the pre-commit sector expiration epoch for an encoded
// replica containing the provided enumeration of pieces and deals. // replica containing the provided enumeration of pieces and deals.
func (p *BasicPreCommitPolicy) Expiration(ctx context.Context, pdis ...Piece) (abi.ChainEpoch, error) { func (p *BasicPreCommitPolicy) Expiration(ctx context.Context, ps ...Piece) (abi.ChainEpoch, error) {
_, epoch, err := p.api.ChainHead(ctx) _, epoch, err := p.api.ChainHead(ctx)
if err != nil { if err != nil {
return 0, nil return 0, nil
@ -52,7 +52,7 @@ func (p *BasicPreCommitPolicy) Expiration(ctx context.Context, pdis ...Piece) (a
var end *abi.ChainEpoch var end *abi.ChainEpoch
for _, p := range pdis { for _, p := range ps {
if p.DealInfo == nil { if p.DealInfo == nil {
continue continue
} }

View File

@ -88,30 +88,27 @@ type SectorInfo struct {
func (t *SectorInfo) pieceInfos() []abi.PieceInfo { func (t *SectorInfo) pieceInfos() []abi.PieceInfo {
out := make([]abi.PieceInfo, len(t.Pieces)) out := make([]abi.PieceInfo, len(t.Pieces))
for i, pdi := range t.Pieces { for i, p := range t.Pieces {
out[i] = abi.PieceInfo{ out[i] = p.Piece
Size: pdi.Piece.Size,
PieceCID: pdi.Piece.PieceCID,
}
} }
return out return out
} }
func (t *SectorInfo) dealIDs() []abi.DealID { func (t *SectorInfo) dealIDs() []abi.DealID {
out := make([]abi.DealID, 0, len(t.Pieces)) out := make([]abi.DealID, 0, len(t.Pieces))
for _, pdi := range t.Pieces { for _, p := range t.Pieces {
if pdi.DealInfo == nil { if p.DealInfo == nil {
continue continue
} }
out = append(out, pdi.DealInfo.DealID) out = append(out, p.DealInfo.DealID)
} }
return out return out
} }
func (t *SectorInfo) existingPieceSizes() []abi.UnpaddedPieceSize { func (t *SectorInfo) existingPieceSizes() []abi.UnpaddedPieceSize {
out := make([]abi.UnpaddedPieceSize, len(t.Pieces)) out := make([]abi.UnpaddedPieceSize, len(t.Pieces))
for i, pdi := range t.Pieces { for i, p := range t.Pieces {
out[i] = pdi.Piece.Size.Unpadded() out[i] = p.Piece.Size.Unpadded()
} }
return out return out
} }