Skip to content

Commit

Permalink
refactor(storagemarket): simplify deal access
Browse files Browse the repository at this point in the history
use embedded struct to simplify property access
  • Loading branch information
hannahhoward committed Feb 11, 2020
1 parent c327a27 commit 0e52ddf
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 93 deletions.
12 changes: 6 additions & 6 deletions storagemarket/impl/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion storagemarket/impl/client_states.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
14 changes: 7 additions & 7 deletions storagemarket/impl/client_storagemarket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
2 changes: 1 addition & 1 deletion storagemarket/impl/client_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions storagemarket/impl/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
50 changes: 25 additions & 25 deletions storagemarket/impl/provider_states.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down Expand Up @@ -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")
}

Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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

Expand All @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions storagemarket/impl/provider_storagemarket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}

Expand Down
2 changes: 1 addition & 1 deletion storagemarket/impl/provider_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 11 additions & 11 deletions storagemarket/impl/request_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion storagemarket/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
}

Expand Down
4 changes: 2 additions & 2 deletions storagemarket/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading

0 comments on commit 0e52ddf

Please sign in to comment.