From d449a980d4bde72bc0773f3d304afd25b134cd10 Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Tue, 3 Mar 2020 16:30:55 -0800 Subject: [PATCH] allow manual piece commitment --- storagemarket/impl/client.go | 2 +- storagemarket/impl/client_utils.go | 9 +++++++-- storagemarket/types.go | 3 +++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/storagemarket/impl/client.go b/storagemarket/impl/client.go index bd567f9f..7bc2a629 100644 --- a/storagemarket/impl/client.go +++ b/storagemarket/impl/client.go @@ -192,7 +192,7 @@ type ClientDealProposal struct { } func (c *Client) Start(ctx context.Context, p ClientDealProposal) (cid.Cid, error) { - commP, pieceSize, err := c.commP(ctx, p.ProofType, p.Data.Root) + commP, pieceSize, err := c.commP(ctx, p.ProofType, p.Data) if err != nil { return cid.Undef, xerrors.Errorf("computing commP failed: %w", err) } diff --git a/storagemarket/impl/client_utils.go b/storagemarket/impl/client_utils.go index fa958cb0..d156483b 100644 --- a/storagemarket/impl/client_utils.go +++ b/storagemarket/impl/client_utils.go @@ -18,6 +18,7 @@ import ( "github.com/filecoin-project/go-address" cborutil "github.com/filecoin-project/go-cbor-util" datatransfer "github.com/filecoin-project/go-data-transfer" + "github.com/filecoin-project/go-fil-markets/storagemarket" "github.com/filecoin-project/go-fil-markets/storagemarket/network" "github.com/filecoin-project/go-statestore" ) @@ -38,14 +39,18 @@ func (c *Client) failDeal(id cid.Cid, cerr error) { log.Errorf("deal %s failed: %+v", id, cerr) } -func (c *Client) commP(ctx context.Context, rt abi.RegisteredProof, root cid.Cid) (cid.Cid, abi.UnpaddedPieceSize, error) { +func (c *Client) commP(ctx context.Context, rt abi.RegisteredProof, data *storagemarket.DataRef) (cid.Cid, abi.UnpaddedPieceSize, error) { + if data.PieceCid != nil { + return *data.PieceCid, data.PieceSize, nil + } + ssb := builder.NewSelectorSpecBuilder(ipldfree.NodeBuilder()) // entire DAG selector allSelector := ssb.ExploreRecursive(selector.RecursionLimitNone(), ssb.ExploreAll(ssb.ExploreRecursiveEdge())).Node() - commp, paddedSize, err := c.pio.GeneratePieceCommitment(rt, root, allSelector) + commp, paddedSize, err := c.pio.GeneratePieceCommitment(rt, data.Root, allSelector) if err != nil { return cid.Undef, 0, xerrors.Errorf("generating CommP: %w", err) } diff --git a/storagemarket/types.go b/storagemarket/types.go index b31155a1..89d7c243 100644 --- a/storagemarket/types.go +++ b/storagemarket/types.go @@ -269,6 +269,9 @@ const ( type DataRef struct { TransferType string Root cid.Cid + + PieceCid *cid.Cid // Optional, will be recomputed from the data if not given + PieceSize abi.UnpaddedPieceSize } // The interface provided by the module to the outside world for storage clients.