From 007bdfaf42202e6e11f8894680481738211bacf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Sun, 13 Oct 2019 04:05:08 +0200 Subject: [PATCH] wip --- chain/deals/client.go | 10 ++++---- chain/deals/client_utils.go | 4 ++-- chain/deals/handler.go | 4 ++-- chain/deals/handler_states.go | 6 ++--- chain/deals/handler_utils.go | 10 ++++---- chain/deals/types.go | 44 +++++++++++++++++------------------ node/impl/client/client.go | 2 +- 7 files changed, 40 insertions(+), 40 deletions(-) diff --git a/chain/deals/client.go b/chain/deals/client.go index 70fe26252..fc7176715 100644 --- a/chain/deals/client.go +++ b/chain/deals/client.go @@ -40,7 +40,7 @@ var log = logging.Logger("deals") type ClientDeal struct { ProposalCid cid.Cid - Proposal StorageDealProposal + Proposal UnsignedStorageDealProposal State api.DealState Miner peer.ID @@ -189,7 +189,7 @@ func (c *Client) VerifyParams(ctx context.Context, data cid.Cid) (*actors.PieceI } func (c *Client) Start(ctx context.Context, p ClientDealProposal, vd *actors.PieceInclVoucherData) (cid.Cid, error) { - proposal := StorageDealProposal{ + proposal := UnsignedStorageDealProposal{ PieceRef: p.Data, SerializationMode: SerializationUnixFs, CommP: vd.CommP[:], @@ -197,8 +197,8 @@ func (c *Client) Start(ctx context.Context, p ClientDealProposal, vd *actors.Pie TotalPrice: p.TotalPrice, Duration: p.Duration, Payment: p.Payment, - MinerAddress: p.MinerAddress, - ClientAddress: p.ClientAddress, + Provider: p.MinerAddress, + Client: p.ClientAddress, } s, err := c.h.NewStream(ctx, p.MinerID, ProtocolID) @@ -229,7 +229,7 @@ func (c *Client) Start(ctx context.Context, p ClientDealProposal, vd *actors.Pie // TODO: start tracking after the deal is sealed return deal.ProposalCid, c.discovery.AddPeer(p.Data, discovery.RetrievalPeer{ - Address: proposal.MinerAddress, + Address: proposal.Provider, ID: deal.Miner, }) } diff --git a/chain/deals/client_utils.go b/chain/deals/client_utils.go index 159bf20e9..935694fa1 100644 --- a/chain/deals/client_utils.go +++ b/chain/deals/client_utils.go @@ -64,7 +64,7 @@ func (c *Client) commP(ctx context.Context, data cid.Cid) ([]byte, int64, error) return commP[:], size, err } -func (c *Client) sendProposal(s inet.Stream, proposal StorageDealProposal, from address.Address) error { +func (c *Client) sendProposal(s inet.Stream, proposal UnsignedStorageDealProposal, from address.Address) error { log.Info("Sending deal proposal") msg, err := cbor.DumpObject(proposal) @@ -76,7 +76,7 @@ func (c *Client) sendProposal(s inet.Stream, proposal StorageDealProposal, from return err } - signedProposal := &SignedStorageDealProposal{ + signedProposal := &StorageDealProposal{ Proposal: proposal, Signature: sig, } diff --git a/chain/deals/handler.go b/chain/deals/handler.go index 112f827f5..1e796108d 100644 --- a/chain/deals/handler.go +++ b/chain/deals/handler.go @@ -27,7 +27,7 @@ func init() { type MinerDeal struct { Client peer.ID - Proposal StorageDealProposal + Proposal UnsignedStorageDealProposal ProposalCid cid.Cid State api.DealState @@ -194,7 +194,7 @@ func (h *Handler) onUpdated(ctx context.Context, update minerDealUpdate) { } } -func (h *Handler) newDeal(s inet.Stream, proposal StorageDealProposal) (MinerDeal, error) { +func (h *Handler) newDeal(s inet.Stream, proposal UnsignedStorageDealProposal) (MinerDeal, error) { // TODO: Review: Not signed? proposalNd, err := cbor.WrapObject(proposal, math.MaxUint64, -1) if err != nil { diff --git a/chain/deals/handler_states.go b/chain/deals/handler_states.go index 573b8d202..376bcced7 100644 --- a/chain/deals/handler_states.go +++ b/chain/deals/handler_states.go @@ -52,8 +52,8 @@ func (h *Handler) checkVoucher(ctx context.Context, deal MinerDeal, voucher *typ return xerrors.New("voucher.Extra not set") } - if voucher.Extra.Actor != deal.Proposal.MinerAddress { - return xerrors.Errorf("extra params actor didn't match miner address in proposal: '%s' != '%s'", voucher.Extra.Actor, deal.Proposal.MinerAddress) + if voucher.Extra.Actor != deal.Proposal.Provider { + return xerrors.Errorf("extra params actor didn't match miner address in proposal: '%s' != '%s'", voucher.Extra.Actor, deal.Proposal.Provider) } if voucher.Extra.Method != actors.MAMethods.PaymentVerifyInclusion { @@ -294,7 +294,7 @@ func (h *Handler) sealing(ctx context.Context, deal MinerDeal) (func(*MinerDeal) } func (h *Handler) complete(ctx context.Context, deal MinerDeal) (func(*MinerDeal), error) { - mcid, err := h.commt.WaitCommit(ctx, deal.Proposal.MinerAddress, deal.SectorID) + mcid, err := h.commt.WaitCommit(ctx, deal.Proposal.Provider, deal.SectorID) if err != nil { log.Warnf("Waiting for sector commitment message: %s", err) } diff --git a/chain/deals/handler_utils.go b/chain/deals/handler_utils.go index a3a4742e9..4f20133cf 100644 --- a/chain/deals/handler_utils.go +++ b/chain/deals/handler_utils.go @@ -46,18 +46,18 @@ func (h *Handler) failDeal(id cid.Cid, cerr error) { } } -func (h *Handler) readProposal(s inet.Stream) (proposal SignedStorageDealProposal, err error) { +func (h *Handler) readProposal(s inet.Stream) (proposal StorageDealProposal, err error) { if err := cborrpc.ReadCborRPC(s, &proposal); err != nil { log.Errorw("failed to read proposal message", "error", err) - return SignedStorageDealProposal{}, err + return StorageDealProposal{}, err } // TODO: Validate proposal maybe // (and signature, obviously) - if proposal.Proposal.MinerAddress != h.actor { - log.Errorf("proposal with wrong MinerAddress: %s", proposal.Proposal.MinerAddress) - return SignedStorageDealProposal{}, err + if proposal.Proposal.Provider != h.actor { + log.Errorf("proposal with wrong Provider: %s", proposal.Proposal.Provider) + return StorageDealProposal{}, err } return diff --git a/chain/deals/types.go b/chain/deals/types.go index ddc754b7e..e3fd4c816 100644 --- a/chain/deals/types.go +++ b/chain/deals/types.go @@ -1,18 +1,17 @@ -package deals + package deals -import ( - "github.com/filecoin-project/go-lotus/api" - "github.com/ipfs/go-cid" - cbor "github.com/ipfs/go-ipld-cbor" + import ( + "github.com/filecoin-project/go-lotus/api" + "github.com/ipfs/go-cid" + cbor "github.com/ipfs/go-ipld-cbor" - "github.com/filecoin-project/go-lotus/chain/actors" - "github.com/filecoin-project/go-lotus/chain/address" - "github.com/filecoin-project/go-lotus/chain/types" -) + "github.com/filecoin-project/go-lotus/chain/address" + "github.com/filecoin-project/go-lotus/chain/types" + ) func init() { + cbor.RegisterCborType(UnsignedStorageDealProposal{}) cbor.RegisterCborType(StorageDealProposal{}) - cbor.RegisterCborType(SignedStorageDealProposal{}) cbor.RegisterCborType(PieceInclusionProof{}) @@ -34,25 +33,26 @@ const ( SerializationIPLD = "IPLD" ) -type StorageDealProposal struct { +type UnsignedStorageDealProposal struct { PieceRef cid.Cid // TODO: port to spec - SerializationMode SerializationMode - CommP []byte + PieceSize uint64 - Size uint64 - TotalPrice types.BigInt - Duration uint64 + Client address.Address + Provider address.Address - Payment actors.PaymentInfo + ProposalExpiryEpoch uint64 + DealExpiryEpoch uint64 - MinerAddress address.Address - ClientAddress address.Address + StoragePrice types.BigInt + StorageCollateral types.BigInt + + ProposerSignature *types.Signature } -type SignedStorageDealProposal struct { - Proposal StorageDealProposal +type StorageDealProposal struct { + UnsignedStorageDealProposal // TODO: check bytes - Signature *types.Signature + ProposerSignature *types.Signature } // response diff --git a/node/impl/client/client.go b/node/impl/client/client.go index 2bc8128ee..730141bfa 100644 --- a/node/impl/client/client.go +++ b/node/impl/client/client.go @@ -134,7 +134,7 @@ func (a *API) ClientListDeals(ctx context.Context) ([]api.DealInfo, error) { out[k] = api.DealInfo{ ProposalCid: v.ProposalCid, State: v.State, - Miner: v.Proposal.MinerAddress, + Miner: v.Proposal.Provider, PieceRef: v.Proposal.PieceRef, CommP: v.Proposal.CommP,