feat: Make ClientCalcCommP multithreaded
This commit is contained in:
parent
c192637741
commit
a715fb3063
@ -47,7 +47,6 @@ import (
|
|||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
cborutil "github.com/filecoin-project/go-cbor-util"
|
cborutil "github.com/filecoin-project/go-cbor-util"
|
||||||
"github.com/filecoin-project/go-commp-utils/ffiwrapper"
|
|
||||||
"github.com/filecoin-project/go-commp-utils/writer"
|
"github.com/filecoin-project/go-commp-utils/writer"
|
||||||
datatransfer "github.com/filecoin-project/go-data-transfer"
|
datatransfer "github.com/filecoin-project/go-data-transfer"
|
||||||
|
|
||||||
@ -1263,28 +1262,12 @@ func (a *API) ClientQueryAsk(ctx context.Context, p peer.ID, miner address.Addre
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *API) ClientCalcCommP(ctx context.Context, inpath string) (*api.CommPRet, error) {
|
func (a *API) ClientCalcCommP(ctx context.Context, inpath string) (*api.CommPRet, error) {
|
||||||
|
|
||||||
// Hard-code the sector type to 32GiBV1_1, because:
|
|
||||||
// - ffiwrapper.GeneratePieceCIDFromFile requires a RegisteredSealProof
|
|
||||||
// - commP itself is sector-size independent, with rather low probability of that changing
|
|
||||||
// ( note how the final rust call is identical for every RegSP type )
|
|
||||||
// https://github.com/filecoin-project/rust-filecoin-proofs-api/blob/v5.0.0/src/seal.rs#L1040-L1050
|
|
||||||
//
|
|
||||||
// IF/WHEN this changes in the future we will have to be able to calculate
|
|
||||||
// "old style" commP, and thus will need to introduce a version switch or similar
|
|
||||||
arbitraryProofType := abi.RegisteredSealProof_StackedDrg64GiBV1_1
|
|
||||||
|
|
||||||
rdr, err := os.Open(inpath)
|
rdr, err := os.Open(inpath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer rdr.Close() //nolint:errcheck
|
defer rdr.Close() //nolint:errcheck
|
||||||
|
|
||||||
stat, err := rdr.Stat()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// check that the data is a car file; if it's not, retrieval won't work
|
// check that the data is a car file; if it's not, retrieval won't work
|
||||||
_, err = car.ReadHeader(bufio.NewReader(rdr))
|
_, err = car.ReadHeader(bufio.NewReader(rdr))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -1295,16 +1278,20 @@ func (a *API) ClientCalcCommP(ctx context.Context, inpath string) (*api.CommPRet
|
|||||||
return nil, xerrors.Errorf("seek to start: %w", err)
|
return nil, xerrors.Errorf("seek to start: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
pieceReader, pieceSize := padreader.New(rdr, uint64(stat.Size()))
|
w := &writer.Writer{}
|
||||||
commP, err := ffiwrapper.GeneratePieceCIDFromFile(arbitraryProofType, pieceReader, pieceSize)
|
_, err = io.CopyBuffer(w, rdr, make([]byte, writer.CommPBuf))
|
||||||
|
if err != nil {
|
||||||
|
return nil, xerrors.Errorf("copy inte commp writer: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
commp, err := w.Sum()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("computing commP failed: %w", err)
|
return nil, xerrors.Errorf("computing commP failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &api.CommPRet{
|
return &api.CommPRet{
|
||||||
Root: commP,
|
Root: commp.PieceCID,
|
||||||
Size: pieceSize,
|
Size: commp.PieceSize.Unpadded(),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user