diff --git a/storagemarket/impl/client.go b/storagemarket/impl/client.go index b04cb5df..8a764f41 100644 --- a/storagemarket/impl/client.go +++ b/storagemarket/impl/client.go @@ -235,12 +235,12 @@ func (c *Client) Start(ctx context.Context, p ClientDealProposal) (cid.Cid, erro deal := &ClientDeal{ ClientDeal: storagemarket.ClientDeal{ - ProposalCid: proposalNd.Cid(), - Proposal: *clientDealProposal, - State: storagemarket.StorageDealUnknown, - Miner: p.MinerID, - MinerWorker: p.MinerWorker, - PayloadCid: p.Data, + ProposalCid: proposalNd.Cid(), + ClientDealProposal: *clientDealProposal, + State: storagemarket.StorageDealUnknown, + Miner: p.MinerID, + MinerWorker: p.MinerWorker, + PayloadCid: p.Data, }, s: s, diff --git a/storagemarket/impl/client_states.go b/storagemarket/impl/client_states.go index f90450ed..df72d443 100644 --- a/storagemarket/impl/client_states.go +++ b/storagemarket/impl/client_states.go @@ -86,7 +86,7 @@ func (c *Client) sealing(ctx context.Context, deal ClientDeal) (func(*ClientDeal } } - err := c.node.OnDealSectorCommitted(ctx, deal.Proposal.Proposal.Provider, deal.DealID, cb) + err := c.node.OnDealSectorCommitted(ctx, deal.Proposal.Provider, deal.DealID, cb) return nil, err } diff --git a/storagemarket/impl/client_storagemarket.go b/storagemarket/impl/client_storagemarket.go index 35f0eabf..47120e2e 100644 --- a/storagemarket/impl/client_storagemarket.go +++ b/storagemarket/impl/client_storagemarket.go @@ -49,13 +49,13 @@ func (c *Client) ListInProgressDeals(ctx context.Context) ([]storagemarket.Clien out := make([]storagemarket.ClientDeal, len(deals)) for k, v := range deals { out[k] = storagemarket.ClientDeal{ - ProposalCid: v.ProposalCid, - Proposal: v.Proposal, - State: v.State, - Miner: v.Miner, - MinerWorker: v.MinerWorker, - DealID: v.DealID, - PublishMessage: v.PublishMessage, + ProposalCid: v.ProposalCid, + ClientDealProposal: v.ClientDealProposal, + State: v.State, + Miner: v.Miner, + MinerWorker: v.MinerWorker, + DealID: v.DealID, + PublishMessage: v.PublishMessage, } } diff --git a/storagemarket/impl/client_utils.go b/storagemarket/impl/client_utils.go index 1aa033ad..72c89820 100644 --- a/storagemarket/impl/client_utils.go +++ b/storagemarket/impl/client_utils.go @@ -152,7 +152,7 @@ func (c *ClientRequestValidator) ValidatePull( return xerrors.Errorf("Deal Peer %s, Data Transfer Peer %s: %w", deal.Miner.String(), receiver.String(), ErrWrongPeer) } if !deal.PayloadCid.Equals(baseCid) { - return xerrors.Errorf("Deal Payload CID %s, Data Transfer CID %s: %w", deal.Proposal.Proposal.PieceCID.String(), baseCid.String(), ErrWrongPiece) + return xerrors.Errorf("Deal Payload CID %s, Data Transfer CID %s: %w", deal.Proposal.PieceCID.String(), baseCid.String(), ErrWrongPiece) } for _, state := range DataTransferStates { if deal.State == state { diff --git a/storagemarket/impl/provider.go b/storagemarket/impl/provider.go index e6cecd0b..a4abef01 100644 --- a/storagemarket/impl/provider.go +++ b/storagemarket/impl/provider.go @@ -255,10 +255,10 @@ func (p *Provider) newDeal(s network.StorageDealStream, proposal network.Proposa return MinerDeal{ MinerDeal: storagemarket.MinerDeal{ - Client: s.RemotePeer(), - Proposal: *proposal.DealProposal, - ProposalCid: proposalNd.Cid(), - State: storagemarket.StorageDealUnknown, + Client: s.RemotePeer(), + ClientDealProposal: *proposal.DealProposal, + ProposalCid: proposalNd.Cid(), + State: storagemarket.StorageDealUnknown, Ref: proposal.Piece, }, diff --git a/storagemarket/impl/provider_states.go b/storagemarket/impl/provider_states.go index 8553c8b9..f63d599c 100644 --- a/storagemarket/impl/provider_states.go +++ b/storagemarket/impl/provider_states.go @@ -46,30 +46,30 @@ func (p *Provider) validating(ctx context.Context, deal MinerDeal) (func(*MinerD if err != nil { return nil, err } - if head.Height() >= deal.Proposal.Proposal.StartEpoch { + if head.Height() >= deal.Proposal.StartEpoch { return nil, xerrors.Errorf("deal proposal already expired") } // TODO: check StorageCollateral - minPrice := big.Div(big.Mul(p.ask.Ask.Price, abi.NewTokenAmount(int64(deal.Proposal.Proposal.PieceSize))), abi.NewTokenAmount(1<<30)) - if deal.Proposal.Proposal.StoragePricePerEpoch.LessThan(minPrice) { - return nil, xerrors.Errorf("storage price per epoch less than asking price: %s < %s", deal.Proposal.Proposal.StoragePricePerEpoch, minPrice) + minPrice := big.Div(big.Mul(p.ask.Ask.Price, abi.NewTokenAmount(int64(deal.Proposal.PieceSize))), abi.NewTokenAmount(1<<30)) + if deal.Proposal.StoragePricePerEpoch.LessThan(minPrice) { + return nil, xerrors.Errorf("storage price per epoch less than asking price: %s < %s", deal.Proposal.StoragePricePerEpoch, minPrice) } - if deal.Proposal.Proposal.PieceSize < p.ask.Ask.MinPieceSize { - return nil, xerrors.Errorf("piece size less than minimum required size: %d < %d", deal.Proposal.Proposal.PieceSize, p.ask.Ask.MinPieceSize) + if deal.Proposal.PieceSize < p.ask.Ask.MinPieceSize { + return nil, xerrors.Errorf("piece size less than minimum required size: %d < %d", deal.Proposal.PieceSize, p.ask.Ask.MinPieceSize) } // check market funds - clientMarketBalance, err := p.spn.GetBalance(ctx, deal.Proposal.Proposal.Client) + clientMarketBalance, err := p.spn.GetBalance(ctx, deal.Proposal.Client) if err != nil { return nil, xerrors.Errorf("getting client market balance failed: %w", err) } // This doesn't guarantee that the client won't withdraw / lock those funds // but it's a decent first filter - if clientMarketBalance.Available.LessThan(deal.Proposal.Proposal.TotalStorageFee()) { + if clientMarketBalance.Available.LessThan(deal.Proposal.TotalStorageFee()) { return nil, xerrors.New("clientMarketBalance.Available too small") } @@ -118,7 +118,7 @@ func (p *Provider) verifydata(ctx context.Context, deal MinerDeal) (func(*MinerD pieceCid := commcid.PieceCommitmentV1ToCID(commp) // Verify CommP matches - if !pieceCid.Equals(deal.Proposal.Proposal.PieceCID) { + if !pieceCid.Equals(deal.Proposal.PieceCID) { return nil, xerrors.Errorf("proposal CommP doesn't match calculated CommP") } @@ -129,22 +129,22 @@ func (p *Provider) verifydata(ctx context.Context, deal MinerDeal) (func(*MinerD // State: StorageDealPublishing func (p *Provider) publishing(ctx context.Context, deal MinerDeal) (func(*MinerDeal), error) { - waddr, err := p.spn.GetMinerWorker(ctx, deal.Proposal.Proposal.Provider) + waddr, err := p.spn.GetMinerWorker(ctx, deal.Proposal.Provider) if err != nil { return nil, err } // TODO: check StorageCollateral (may be too large (or too small)) - if err := p.spn.EnsureFunds(ctx, waddr, deal.Proposal.Proposal.ProviderCollateral); err != nil { + if err := p.spn.EnsureFunds(ctx, waddr, deal.Proposal.ProviderCollateral); err != nil { return nil, err } smDeal := storagemarket.MinerDeal{ - Client: deal.Client, - Proposal: deal.Proposal, - ProposalCid: deal.ProposalCid, - State: deal.State, - Ref: deal.Ref, + Client: deal.Client, + ClientDealProposal: deal.ClientDealProposal, + ProposalCid: deal.ProposalCid, + State: deal.State, + Ref: deal.Ref, } dealId, mcid, err := p.spn.PublishDeals(ctx, smDeal) @@ -181,12 +181,12 @@ func (p *Provider) staged(ctx context.Context, deal MinerDeal) (func(*MinerDeal) err = p.spn.OnDealComplete( ctx, storagemarket.MinerDeal{ - Client: deal.Client, - Proposal: deal.Proposal, - ProposalCid: deal.ProposalCid, - State: deal.State, - Ref: deal.Ref, - DealID: deal.DealID, + Client: deal.Client, + ClientDealProposal: deal.ClientDealProposal, + ProposalCid: deal.ProposalCid, + State: deal.State, + Ref: deal.Ref, + DealID: deal.DealID, }, paddedSize, paddedReader, @@ -210,7 +210,7 @@ func (p *Provider) sealing(ctx context.Context, deal MinerDeal) (func(*MinerDeal } } - err := p.spn.OnDealSectorCommitted(ctx, deal.Proposal.Proposal.Provider, deal.DealID, cb) + err := p.spn.OnDealSectorCommitted(ctx, deal.Proposal.Provider, deal.DealID, cb) return nil, err @@ -226,13 +226,13 @@ func (p *Provider) complete(ctx context.Context, deal MinerDeal) (func(*MinerDea return nil, err } // TODO: Record actual block locations for all CIDs in piece by improving car writing - err = p.pieceStore.AddPieceBlockLocations(deal.Proposal.Proposal.PieceCID, map[cid.Cid]piecestore.BlockLocation{ + err = p.pieceStore.AddPieceBlockLocations(deal.Proposal.PieceCID, map[cid.Cid]piecestore.BlockLocation{ deal.Ref: {}, }) if err != nil { return nil, err } - return nil, p.pieceStore.AddDealForPiece(deal.Proposal.Proposal.PieceCID, piecestore.DealInfo{ + return nil, p.pieceStore.AddDealForPiece(deal.Proposal.PieceCID, piecestore.DealInfo{ DealID: deal.DealID, SectorID: sectorID, Offset: offset, diff --git a/storagemarket/impl/provider_storagemarket.go b/storagemarket/impl/provider_storagemarket.go index 7a6a5d33..435be13e 100644 --- a/storagemarket/impl/provider_storagemarket.go +++ b/storagemarket/impl/provider_storagemarket.go @@ -48,12 +48,12 @@ func (p *Provider) ListIncompleteDeals() ([]storagemarket.MinerDeal, error) { for _, deal := range deals { out = append(out, storagemarket.MinerDeal{ - Client: deal.Client, - Proposal: deal.Proposal, - ProposalCid: deal.ProposalCid, - State: deal.State, - Ref: deal.Ref, - DealID: deal.DealID, + Client: deal.Client, + ClientDealProposal: deal.ClientDealProposal, + ProposalCid: deal.ProposalCid, + State: deal.State, + Ref: deal.Ref, + DealID: deal.DealID, }) } diff --git a/storagemarket/impl/provider_utils.go b/storagemarket/impl/provider_utils.go index d1808ce2..b5ab516b 100644 --- a/storagemarket/impl/provider_utils.go +++ b/storagemarket/impl/provider_utils.go @@ -168,7 +168,7 @@ func (m *ProviderRequestValidator) ValidatePush( } if !deal.Ref.Equals(baseCid) { - return xerrors.Errorf("Deal Payload CID %s, Data Transfer CID %s: %w", deal.Proposal.Proposal.PieceCID.String(), baseCid.String(), ErrWrongPiece) + return xerrors.Errorf("Deal Payload CID %s, Data Transfer CID %s: %w", deal.Proposal.PieceCID.String(), baseCid.String(), ErrWrongPiece) } for _, state := range DataTransferStates { if deal.State == state { diff --git a/storagemarket/impl/request_validation_test.go b/storagemarket/impl/request_validation_test.go index 833498a8..f267ffdd 100644 --- a/storagemarket/impl/request_validation_test.go +++ b/storagemarket/impl/request_validation_test.go @@ -77,12 +77,12 @@ func newClientDeal(minerID peer.ID, state storagemarket.StorageDealStatus) (deal return deals.ClientDeal{ ClientDeal: storagemarket.ClientDeal{ - Proposal: newProposal, - ProposalCid: proposalNd.Cid(), - PayloadCid: blockGenerator.Next().Cid(), - Miner: minerID, - MinerWorker: minerAddr, - State: state, + ClientDealProposal: newProposal, + ProposalCid: proposalNd.Cid(), + PayloadCid: blockGenerator.Next().Cid(), + Miner: minerID, + MinerWorker: minerAddr, + State: state, }, }, nil } @@ -100,11 +100,11 @@ func newMinerDeal(clientID peer.ID, state storagemarket.StorageDealStatus) (deal return deals.MinerDeal{ MinerDeal: storagemarket.MinerDeal{ - Proposal: newProposal, - ProposalCid: proposalNd.Cid(), - Client: clientID, - State: state, - Ref: ref, + ClientDealProposal: newProposal, + ProposalCid: proposalNd.Cid(), + Client: clientID, + State: state, + Ref: ref, }, }, nil } diff --git a/storagemarket/integration_test.go b/storagemarket/integration_test.go index 3cb54976..997db680 100644 --- a/storagemarket/integration_test.go +++ b/storagemarket/integration_test.go @@ -282,7 +282,7 @@ type fakeProviderNode struct { func (n *fakeProviderNode) PublishDeals(ctx context.Context, deal storagemarket.MinerDeal) (storagemarket.DealID, cid.Cid, error) { sd := storagemarket.StorageDeal{ - deal.Proposal.Proposal, + deal.Proposal, market.DealState{}, } diff --git a/storagemarket/types.go b/storagemarket/types.go index cf1cc340..573b7750 100644 --- a/storagemarket/types.go +++ b/storagemarket/types.go @@ -106,8 +106,8 @@ type StateKey interface { // Duplicated from deals package for now type MinerDeal struct { + market.ClientDealProposal ProposalCid cid.Cid - Proposal market.ClientDealProposal Miner peer.ID Client peer.ID State StorageDealStatus @@ -119,8 +119,8 @@ type MinerDeal struct { } type ClientDeal struct { + market.ClientDealProposal ProposalCid cid.Cid - Proposal market.ClientDealProposal State StorageDealStatus Miner peer.ID MinerWorker address.Address diff --git a/storagemarket/types_cbor_gen.go b/storagemarket/types_cbor_gen.go index 80b7dd48..8328b05b 100644 --- a/storagemarket/types_cbor_gen.go +++ b/storagemarket/types_cbor_gen.go @@ -25,17 +25,17 @@ func (t *ClientDeal) MarshalCBOR(w io.Writer) error { return err } + // t.ClientDealProposal (market.ClientDealProposal) (struct) + if err := t.ClientDealProposal.MarshalCBOR(w); err != nil { + return err + } + // t.ProposalCid (cid.Cid) (struct) if err := cbg.WriteCid(w, t.ProposalCid); err != nil { return xerrors.Errorf("failed to write cid field t.ProposalCid: %w", err) } - // t.Proposal (market.ClientDealProposal) (struct) - if err := t.Proposal.MarshalCBOR(w); err != nil { - return err - } - // t.State (uint64) (uint64) if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.State))); err != nil { return err @@ -99,26 +99,26 @@ func (t *ClientDeal) UnmarshalCBOR(r io.Reader) error { return fmt.Errorf("cbor input had wrong number of fields") } - // t.ProposalCid (cid.Cid) (struct) + // t.ClientDealProposal (market.ClientDealProposal) (struct) { - c, err := cbg.ReadCid(br) - if err != nil { - return xerrors.Errorf("failed to read cid field t.ProposalCid: %w", err) + if err := t.ClientDealProposal.UnmarshalCBOR(br); err != nil { + return err } - t.ProposalCid = c - } - // t.Proposal (market.ClientDealProposal) (struct) + // t.ProposalCid (cid.Cid) (struct) { - if err := t.Proposal.UnmarshalCBOR(br); err != nil { - return err + c, err := cbg.ReadCid(br) + if err != nil { + return xerrors.Errorf("failed to read cid field t.ProposalCid: %w", err) } + t.ProposalCid = c + } // t.State (uint64) (uint64) @@ -207,17 +207,17 @@ func (t *MinerDeal) MarshalCBOR(w io.Writer) error { return err } + // t.ClientDealProposal (market.ClientDealProposal) (struct) + if err := t.ClientDealProposal.MarshalCBOR(w); err != nil { + return err + } + // t.ProposalCid (cid.Cid) (struct) if err := cbg.WriteCid(w, t.ProposalCid); err != nil { return xerrors.Errorf("failed to write cid field t.ProposalCid: %w", err) } - // t.Proposal (market.ClientDealProposal) (struct) - if err := t.Proposal.MarshalCBOR(w); err != nil { - return err - } - // t.Miner (peer.ID) (string) if len(t.Miner) > cbg.MaxLength { return xerrors.Errorf("Value in field t.Miner was too long") @@ -287,26 +287,26 @@ func (t *MinerDeal) UnmarshalCBOR(r io.Reader) error { return fmt.Errorf("cbor input had wrong number of fields") } - // t.ProposalCid (cid.Cid) (struct) + // t.ClientDealProposal (market.ClientDealProposal) (struct) { - c, err := cbg.ReadCid(br) - if err != nil { - return xerrors.Errorf("failed to read cid field t.ProposalCid: %w", err) + if err := t.ClientDealProposal.UnmarshalCBOR(br); err != nil { + return err } - t.ProposalCid = c - } - // t.Proposal (market.ClientDealProposal) (struct) + // t.ProposalCid (cid.Cid) (struct) { - if err := t.Proposal.UnmarshalCBOR(br); err != nil { - return err + c, err := cbg.ReadCid(br) + if err != nil { + return xerrors.Errorf("failed to read cid field t.ProposalCid: %w", err) } + t.ProposalCid = c + } // t.Miner (peer.ID) (string)