post-rebase fixes
This commit is contained in:
parent
480e7899ef
commit
74ea4d71c5
@ -4,16 +4,14 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"math/bits"
|
|
||||||
"sync"
|
|
||||||
"testing/iotest"
|
|
||||||
|
|
||||||
"github.com/filecoin-project/go-sectorbuilder/sealing_state"
|
"github.com/filecoin-project/go-sectorbuilder/sealing_state"
|
||||||
"github.com/ipfs/go-datastore"
|
"github.com/ipfs/go-datastore"
|
||||||
"github.com/ipfs/go-datastore/namespace"
|
"github.com/ipfs/go-datastore/namespace"
|
||||||
logging "github.com/ipfs/go-log"
|
logging "github.com/ipfs/go-log"
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
"io"
|
||||||
|
"math/bits"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/api"
|
"github.com/filecoin-project/lotus/api"
|
||||||
"github.com/filecoin-project/lotus/lib/cborrpc"
|
"github.com/filecoin-project/lotus/lib/cborrpc"
|
||||||
@ -59,44 +57,10 @@ func (s *Store) SectorStatus(sid uint64) (*sectorbuilder.SectorSealingStatus, er
|
|||||||
return &status, nil
|
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) {
|
func (s *Store) AddPiece(ref string, size uint64, r io.Reader, dealIDs ...uint64) (sectorID uint64, err error) {
|
||||||
padSize := computePaddedSize(size)
|
sectorID, err = s.sb.AddPiece(ref, size, r)
|
||||||
|
|
||||||
buf := make([]byte, padSize)
|
|
||||||
r = iotest.NewReadLogger("UNIX FILE", r)
|
|
||||||
n, err := io.ReadFull(r, buf)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, xerrors.Errorf("failed a bad thing: %w", err)
|
return 0, 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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s.dealsLk.Lock()
|
s.dealsLk.Lock()
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"io"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
@ -19,6 +20,7 @@ import (
|
|||||||
|
|
||||||
"github.com/filecoin-project/lotus/api"
|
"github.com/filecoin-project/lotus/api"
|
||||||
"github.com/filecoin-project/lotus/lib/cborrpc"
|
"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/lib/sectorbuilder"
|
||||||
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
||||||
"github.com/filecoin-project/lotus/storage/sector"
|
"github.com/filecoin-project/lotus/storage/sector"
|
||||||
@ -130,6 +132,9 @@ func (r *refStorer) Read(p []byte) (n int, err error) {
|
|||||||
for {
|
for {
|
||||||
data, offset, nd, err := r.blockReader.ReadBlock(context.TODO())
|
data, offset, nd, err := r.blockReader.ReadBlock(context.TODO())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if err == io.EOF {
|
||||||
|
return 0, io.EOF
|
||||||
|
}
|
||||||
return 0, xerrors.Errorf("reading block: %w", err)
|
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,
|
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) {
|
func (st *SectorBlocks) List() (map[cid.Cid][]api.SealedRef, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user