Consolidate nullreader files

This commit is contained in:
Geoff Stuart 2022-04-12 11:45:34 -04:00
parent 88f8c7d166
commit b2a6d308ba
6 changed files with 28 additions and 24 deletions

View File

@ -5,6 +5,8 @@ import (
"sort"
"time"
"github.com/filecoin-project/lotus/extern/storage-sealing/lib/nullreader"
"github.com/filecoin-project/go-padreader"
"github.com/filecoin-project/go-statemachine"
"github.com/ipfs/go-cid"
@ -220,7 +222,7 @@ func (m *Sealing) handleAddPiece(ctx statemachine.Context, sector SectorInfo) er
m.minerSector(sector.SectorType, sector.SectorNumber),
pieceSizes,
p.Unpadded(),
NewNullReader(p.Unpadded()))
nullreader.NewNullReader(p.Unpadded()))
if err != nil {
err = xerrors.Errorf("writing padding piece: %w", err)
deal.accepted(sector.SectorNumber, offset, err)

View File

@ -1,5 +1,23 @@
package nullreader
import (
"io"
"github.com/filecoin-project/go-state-types/abi"
)
type NullReader struct {
*io.LimitedReader
}
func NewNullReader(size abi.UnpaddedPieceSize) io.Reader {
return &NullReader{(io.LimitReader(&Reader{}, int64(size))).(*io.LimitedReader)}
}
func (m NullReader) NullBytes() int64 {
return m.N
}
// TODO: extract this to someplace where it can be shared with lotus
type Reader struct{}

View File

@ -1,20 +0,0 @@
package sealing
import (
"io"
"github.com/filecoin-project/go-state-types/abi"
nr "github.com/filecoin-project/lotus/extern/storage-sealing/lib/nullreader"
)
type NullReader struct {
*io.LimitedReader
}
func NewNullReader(size abi.UnpaddedPieceSize) io.Reader {
return &NullReader{(io.LimitReader(&nr.Reader{}, int64(size))).(*io.LimitedReader)}
}
func (m NullReader) NullBytes() int64 {
return m.N
}

View File

@ -4,6 +4,8 @@ import (
"bytes"
"context"
"github.com/filecoin-project/lotus/extern/storage-sealing/lib/nullreader"
"github.com/ipfs/go-cid"
"golang.org/x/xerrors"
@ -91,7 +93,7 @@ func (m *Sealing) padSector(ctx context.Context, sectorID storage.SectorRef, exi
for i, size := range sizes {
expectCid := zerocomm.ZeroPieceCommitment(size)
ppi, err := m.sealer.AddPiece(ctx, sectorID, existingPieceSizes, size, NewNullReader(size))
ppi, err := m.sealer.AddPiece(ctx, sectorID, existingPieceSizes, size, nullreader.NewNullReader(size))
if err != nil {
return nil, xerrors.Errorf("add piece: %w", err)
}

View File

@ -15,13 +15,14 @@ import (
"sync"
"time"
sealing "github.com/filecoin-project/lotus/extern/storage-sealing/lib/nullreader"
"github.com/google/uuid"
logging "github.com/ipfs/go-log/v2"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-jsonrpc"
"github.com/filecoin-project/go-state-types/abi"
sealing "github.com/filecoin-project/lotus/extern/storage-sealing"
)
var log = logging.Logger("rpcenc")

View File

@ -9,12 +9,13 @@ import (
"strings"
"testing"
sealing "github.com/filecoin-project/lotus/extern/storage-sealing/lib/nullreader"
"github.com/gorilla/mux"
"github.com/stretchr/testify/require"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-jsonrpc"
sealing "github.com/filecoin-project/lotus/extern/storage-sealing"
)
type ReaderHandler struct {