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)}
}
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
// filler (i.e. ensure that it has a zero PieceCID)
if pdi.DealInfo == nil {
exp := zerocomm.ZeroPieceCommitment(pdi.Piece.Size.Unpadded())
if !pdi.Piece.PieceCID.Equals(exp) {
return &ErrInvalidPiece{xerrors.Errorf("sector %d piece %d had non-zero PieceCID %+v", si.SectorNumber, i, pdi.Piece.PieceCID)}
if p.DealInfo == nil {
exp := zerocomm.ZeroPieceCommitment(p.Piece.Size.Unpadded())
if !p.Piece.PieceCID.Equals(exp) {
return &ErrInvalidPiece{xerrors.Errorf("sector %d piece %d had non-zero PieceCID %+v", si.SectorNumber, i, p.Piece.PieceCID)}
}
continue
}
proposal, _, err := api.StateMarketStorageDeal(ctx, pdi.DealInfo.DealID, tok)
proposal, _, err := api.StateMarketStorageDeal(ctx, p.DealInfo.DealID, tok)
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 {
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 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, p.DealInfo.DealID, p.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.Pieces), si.SectorNumber, pdi.DealInfo.DealID, 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, p.DealInfo.DealID, p.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.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
}
pdis := make([]Piece, len(pieces))
for idx := range pdis {
pdis[idx] = Piece{
ps := make([]Piece, len(pieces))
for idx := range ps {
ps[idx] = Piece{
Piece: pieces[idx],
DealInfo: nil,
}
}
if err := m.newSector(sid, rt, pdis); err != nil {
if err := m.newSector(sid, rt, ps); err != nil {
log.Errorf("%+v", err)
return
}

View File

@ -7,7 +7,7 @@ import (
)
type PreCommitPolicy interface {
Expiration(ctx context.Context, pdis ...Piece) (abi.ChainEpoch, error)
Expiration(ctx context.Context, ps ...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 ...Piece) (abi.ChainEpoch, error) {
func (p *BasicPreCommitPolicy) Expiration(ctx context.Context, ps ...Piece) (abi.ChainEpoch, error) {
_, epoch, err := p.api.ChainHead(ctx)
if err != nil {
return 0, nil
@ -52,7 +52,7 @@ func (p *BasicPreCommitPolicy) Expiration(ctx context.Context, pdis ...Piece) (a
var end *abi.ChainEpoch
for _, p := range pdis {
for _, p := range ps {
if p.DealInfo == nil {
continue
}

View File

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