From b42171dc04d97adb70016bcd9ba2f94baf8d24e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Thu, 26 Aug 2021 16:22:43 +0200 Subject: [PATCH] sealing: Check piece CIDs after AddPiece --- extern/storage-sealing/input.go | 13 +++++++++++++ extern/storage-sealing/states_sealing.go | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/extern/storage-sealing/input.go b/extern/storage-sealing/input.go index 1a0b7bf1e..218616aea 100644 --- a/extern/storage-sealing/input.go +++ b/extern/storage-sealing/input.go @@ -9,6 +9,7 @@ import ( "github.com/ipfs/go-cid" + "github.com/filecoin-project/go-commp-utils/zerocomm" "github.com/filecoin-project/go-padreader" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-statemachine" @@ -187,6 +188,8 @@ func (m *Sealing) handleAddPiece(ctx statemachine.Context, sector SectorInfo) er offset += padLength.Unpadded() for _, p := range pads { + expectCid := zerocomm.ZeroPieceCommitment(p.Unpadded()) + ppi, err := m.sealer.AddPiece(sectorstorage.WithPriority(ctx.Context(), DealSectorPriority), m.minerSector(sector.SectorType, sector.SectorNumber), pieceSizes, @@ -197,6 +200,11 @@ func (m *Sealing) handleAddPiece(ctx statemachine.Context, sector SectorInfo) er deal.accepted(sector.SectorNumber, offset, err) return ctx.Send(SectorAddPieceFailed{err}) } + if !ppi.PieceCID.Equals(expectCid) { + err = xerrors.Errorf("got unexpected padding piece CID: expected:%s, got:%s", expectCid, ppi.PieceCID) + deal.accepted(sector.SectorNumber, offset, err) + return ctx.Send(SectorAddPieceFailed{err}) + } pieceSizes = append(pieceSizes, p.Unpadded()) res.NewPieces = append(res.NewPieces, Piece{ @@ -214,6 +222,11 @@ func (m *Sealing) handleAddPiece(ctx statemachine.Context, sector SectorInfo) er deal.accepted(sector.SectorNumber, offset, err) return ctx.Send(SectorAddPieceFailed{err}) } + if !ppi.PieceCID.Equals(deal.deal.DealProposal.PieceCID) { + err = xerrors.Errorf("got unexpected piece CID: expected:%s, got:%s", deal.deal.DealProposal.PieceCID, ppi.PieceCID) + deal.accepted(sector.SectorNumber, offset, err) + return ctx.Send(SectorAddPieceFailed{err}) + } log.Infow("deal added to a sector", "deal", deal.deal.DealID, "sector", sector.SectorNumber, "piece", ppi.PieceCID) diff --git a/extern/storage-sealing/states_sealing.go b/extern/storage-sealing/states_sealing.go index ed704d9dc..0df000eda 100644 --- a/extern/storage-sealing/states_sealing.go +++ b/extern/storage-sealing/states_sealing.go @@ -7,6 +7,7 @@ import ( "github.com/ipfs/go-cid" "golang.org/x/xerrors" + "github.com/filecoin-project/go-commp-utils/zerocomm" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/crypto" @@ -88,10 +89,15 @@ func (m *Sealing) padSector(ctx context.Context, sectorID storage.SectorRef, exi out := make([]abi.PieceInfo, len(sizes)) for i, size := range sizes { + expectCid := zerocomm.ZeroPieceCommitment(size) + ppi, err := m.sealer.AddPiece(ctx, sectorID, existingPieceSizes, size, NewNullReader(size)) if err != nil { return nil, xerrors.Errorf("add piece: %w", err) } + if !expectCid.Equals(expectCid) { + return nil, xerrors.Errorf("got unexpected padding piece CID: expected:%s, got:%s", expectCid, ppi.PieceCID) + } existingPieceSizes = append(existingPieceSizes, size)