ffiwrapper: Handle null padding in DataCid automatically
This commit is contained in:
parent
3fa2ada987
commit
7054475c00
@ -436,7 +436,7 @@ var sealingDataCidCmd = &cli.Command{
|
||||
return xerrors.Errorf("file larger than the piece")
|
||||
}
|
||||
} else {
|
||||
psize = padreader.PaddedSize(uint64(sz)).Padded()
|
||||
psize = padreader.PaddedSize(sz).Padded()
|
||||
}
|
||||
|
||||
pc, err := nodeApi.ComputeDataCid(ctx, psize.Unpadded(), r)
|
||||
|
@ -32,6 +32,7 @@ import (
|
||||
"github.com/filecoin-project/lotus/extern/sector-storage/partialfile"
|
||||
"github.com/filecoin-project/lotus/extern/sector-storage/storiface"
|
||||
nr "github.com/filecoin-project/lotus/extern/storage-sealing/lib/nullreader"
|
||||
"github.com/filecoin-project/lotus/lib/nullreader"
|
||||
)
|
||||
|
||||
var _ Storage = &Sealer{}
|
||||
@ -53,6 +54,11 @@ func (sb *Sealer) NewSector(ctx context.Context, sector storage.SectorRef) error
|
||||
}
|
||||
|
||||
func (sb *Sealer) DataCid(ctx context.Context, pieceSize abi.UnpaddedPieceSize, pieceData storage.Data) (abi.PieceInfo, error) {
|
||||
pieceData = io.LimitReader(io.MultiReader(
|
||||
pieceData,
|
||||
nullreader.Reader{},
|
||||
), int64(pieceSize))
|
||||
|
||||
// TODO: allow tuning those:
|
||||
chunk := abi.PaddedPieceSize(4 << 20)
|
||||
parallel := runtime.NumCPU()
|
||||
@ -73,6 +79,7 @@ func (sb *Sealer) DataCid(ctx context.Context, pieceSize abi.UnpaddedPieceSize,
|
||||
for {
|
||||
var read int
|
||||
for rbuf := buf; len(rbuf) > 0; {
|
||||
|
||||
n, err := pieceData.Read(rbuf)
|
||||
if err != nil && err != io.EOF {
|
||||
return abi.PieceInfo{}, xerrors.Errorf("pr read error: %w", err)
|
||||
|
@ -49,17 +49,23 @@ func TestWorkerDataCid(t *testing.T) {
|
||||
e, err := worker.Enabled(ctx)
|
||||
require.NoError(t, err)
|
||||
require.True(t, e)
|
||||
/*
|
||||
|
||||
pi, err := miner.ComputeDataCid(ctx, 1016, strings.NewReader(strings.Repeat("a", 1016)))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, abi.PaddedPieceSize(1024), pi.Size)
|
||||
require.Equal(t, "baga6ea4seaqlhznlutptgfwhffupyer6txswamerq5fc2jlwf2lys2mm5jtiaeq", pi.PieceCID.String())
|
||||
*/
|
||||
|
||||
bigPiece := abi.PaddedPieceSize(16 << 20).Unpadded()
|
||||
pi, err := miner.ComputeDataCid(ctx, bigPiece, strings.NewReader(strings.Repeat("a", int(bigPiece))))
|
||||
pi, err = miner.ComputeDataCid(ctx, bigPiece, strings.NewReader(strings.Repeat("a", int(bigPiece))))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, bigPiece.Padded(), pi.Size)
|
||||
require.Equal(t, "baga6ea4seaqmhoxl2ybw5m2wyd3pt3h4zmp7j52yumzu2rar26twns3uocq7yfa", pi.PieceCID.String())
|
||||
|
||||
nonFullPiece := abi.PaddedPieceSize(10 << 20).Unpadded()
|
||||
pi, err = miner.ComputeDataCid(ctx, bigPiece, strings.NewReader(strings.Repeat("a", int(nonFullPiece))))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, bigPiece.Padded(), pi.Size)
|
||||
require.Equal(t, "baga6ea4seaqbxib4pdxs5cqdn3fmtj4rcxk6rx6ztiqmrx7fcpo3ymuxbp2rodi", pi.PieceCID.String())
|
||||
}
|
||||
|
||||
func TestWinningPostWorker(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user