From 74ea4d71c5a9f48c1655a213f52e2044808285ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Thu, 7 Nov 2019 00:47:48 +0100 Subject: [PATCH] post-rebase fixes --- storage/sector/store.go | 46 ++++------------------------------ storage/sectorblocks/blocks.go | 9 ++++++- 2 files changed, 13 insertions(+), 42 deletions(-) diff --git a/storage/sector/store.go b/storage/sector/store.go index a3ae60544..7f1159090 100644 --- a/storage/sector/store.go +++ b/storage/sector/store.go @@ -4,16 +4,14 @@ import ( "bytes" "context" "fmt" - "io" - "math/bits" - "sync" - "testing/iotest" - "github.com/filecoin-project/go-sectorbuilder/sealing_state" "github.com/ipfs/go-datastore" "github.com/ipfs/go-datastore/namespace" logging "github.com/ipfs/go-log" "golang.org/x/xerrors" + "io" + "math/bits" + "sync" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/lib/cborrpc" @@ -59,44 +57,10 @@ func (s *Store) SectorStatus(sid uint64) (*sectorbuilder.SectorSealingStatus, er return &status, nil } -func computePaddedSize(size uint64) uint64 { - logv := 64 - bits.LeadingZeros64(size) - sectSize := uint64(1 << logv) - bound := sectorbuilder.UserBytesForSectorSize(sectSize) - if size <= bound { - return bound - } - return sectorbuilder.UserBytesForSectorSize(1 << (logv + 1)) -} - -type nullReader struct{} - -func (nr nullReader) Read(b []byte) (int, error) { - for i := range b { - b[i] = 0 - } - return len(b), nil -} - func (s *Store) AddPiece(ref string, size uint64, r io.Reader, dealIDs ...uint64) (sectorID uint64, err error) { - padSize := computePaddedSize(size) - - buf := make([]byte, padSize) - r = iotest.NewReadLogger("UNIX FILE", r) - n, err := io.ReadFull(r, buf) + sectorID, err = s.sb.AddPiece(ref, size, r) if err != nil { - return 0, xerrors.Errorf("failed a bad thing: %w", err) - } - if uint64(n) != size { - panic("bad bad") - } - - bufr := bytes.NewReader(buf) - //r = io.MultiReader(r, io.LimitReader(nullReader{}, int64(padSize-size))) - - sectorID, err = s.sb.AddPiece(ref, padSize, bufr) - if err != nil { - return 0, xerrors.Errorf("sector store AddPiece call failed: %w", err) + return 0, err } s.dealsLk.Lock() diff --git a/storage/sectorblocks/blocks.go b/storage/sectorblocks/blocks.go index d8666b41c..1d1289def 100644 --- a/storage/sectorblocks/blocks.go +++ b/storage/sectorblocks/blocks.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "errors" + "io" "sync" "github.com/ipfs/go-cid" @@ -19,6 +20,7 @@ import ( "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/lib/cborrpc" + "github.com/filecoin-project/lotus/lib/padreader" "github.com/filecoin-project/lotus/lib/sectorbuilder" "github.com/filecoin-project/lotus/node/modules/dtypes" "github.com/filecoin-project/lotus/storage/sector" @@ -130,6 +132,9 @@ func (r *refStorer) Read(p []byte) (n int, err error) { for { data, offset, nd, err := r.blockReader.ReadBlock(context.TODO()) if err != nil { + if err == io.EOF { + return 0, io.EOF + } return 0, xerrors.Errorf("reading block: %w", err) } @@ -168,7 +173,9 @@ func (st *SectorBlocks) AddUnixfsPiece(ref cid.Cid, r UnixfsReader, dealID uint6 intermediate: st.intermediate, } - return st.Store.AddPiece(refst.pieceRef, uint64(size), refst, dealID) + pr, psize := padreader.New(r, uint64(size)) + + return st.Store.AddPiece(refst.pieceRef, psize, pr, dealID) } func (st *SectorBlocks) List() (map[cid.Cid][]api.SealedRef, error) {