Clean up storage deal structures

This commit is contained in:
whyrusleeping 2019-12-07 15:12:10 +01:00
parent 8127676f73
commit f0653decf3
15 changed files with 247 additions and 266 deletions

View File

@ -3,6 +3,7 @@ package actors
import (
"bytes"
"context"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-amt-ipld"
@ -131,36 +132,20 @@ func (sdp *StorageDealProposal) Verify() error {
return sdp.ProposerSignature.Verify(sdp.Client, buf.Bytes())
}
func (d *StorageDeal) Sign(ctx context.Context, sign SignFunc) error {
var buf bytes.Buffer
if err := d.Proposal.MarshalCBOR(&buf); err != nil {
return err
}
sig, err := sign(ctx, buf.Bytes())
if err != nil {
return err
}
d.CounterSignature = sig
return nil
}
func (d *StorageDeal) Verify(proposerWorker address.Address) error {
var buf bytes.Buffer
if err := d.Proposal.MarshalCBOR(&buf); err != nil {
return err
}
return d.CounterSignature.Verify(proposerWorker, buf.Bytes())
}
type StorageDeal struct {
Proposal StorageDealProposal
CounterSignature *types.Signature
}
type OnChainDeal struct {
Deal StorageDeal
ActivationEpoch uint64 // 0 = inactive
PieceRef []byte // cid bytes // TODO: spec says to use cid.Cid, probably not a good idea
PieceSize uint64
PieceSerialization SerializationMode // Needs to be here as it tells how data in the sector maps to PieceRef cid
Client address.Address
Provider address.Address
ProposalExpiration uint64
Duration uint64 // TODO: spec
StoragePricePerEpoch types.BigInt
StorageCollateral types.BigInt
ActivationEpoch uint64 // 0 = inactive
}
type WithdrawBalanceParams struct {
@ -245,6 +230,7 @@ func (sma StorageMarketActor) AddBalance(act *types.Actor, vmctx types.VMContext
}
func setMarketBalances(vmctx types.VMContext, nd *hamt.Node, set map[address.Address]StorageParticipantBalance) (cid.Cid, ActorError) {
// TODO: iterating over a map might happen in the wrong order, this could have gas implications
for addr, b := range set {
balance := b // to stop linter complaining
if err := nd.Set(vmctx.Context(), string(addr.Bytes()), &balance); err != nil {
@ -297,7 +283,7 @@ func (sma StorageMarketActor) CheckLockedBalance(act *types.Actor, vmctx types.V
*/
type PublishStorageDealsParams struct {
Deals []StorageDeal
Deals []StorageDealProposal
}
type PublishStorageDealResponse struct {
@ -326,7 +312,7 @@ func (sma StorageMarketActor) PublishStorageDeals(act *types.Actor, vmctx types.
DealIDs: make([]uint64, len(params.Deals)),
}
workerBytes, aerr := vmctx.Send(params.Deals[0].Proposal.Provider, MAMethods.GetWorkerAddr, types.NewInt(0), nil)
workerBytes, aerr := vmctx.Send(params.Deals[0].Provider, MAMethods.GetWorkerAddr, types.NewInt(0), nil)
if aerr != nil {
return nil, aerr
}
@ -342,7 +328,21 @@ func (sma StorageMarketActor) PublishStorageDeals(act *types.Actor, vmctx types.
return nil, err
}
err := deals.Set(self.NextDealID, &OnChainDeal{Deal: deal})
err := deals.Set(self.NextDealID, &OnChainDeal{
PieceRef: deal.PieceRef,
PieceSize: deal.PieceSize,
PieceSerialization: deal.PieceSerialization, // TODO: this isnt needed anymore, right?
Client: deal.Client,
Provider: deal.Provider,
ProposalExpiration: deal.ProposalExpiration,
Duration: deal.Duration,
StoragePricePerEpoch: deal.StoragePricePerEpoch,
StorageCollateral: deal.StorageCollateral,
ActivationEpoch: 0,
})
if err != nil {
return nil, aerrors.HandleExternalError(err, "setting deal in deal AMT")
}
@ -376,34 +376,28 @@ func (sma StorageMarketActor) PublishStorageDeals(act *types.Actor, vmctx types.
return outBuf.Bytes(), nil
}
func (st *StorageMarketState) validateDeal(vmctx types.VMContext, deal StorageDeal, providerWorker address.Address) aerrors.ActorError {
if vmctx.BlockHeight() > deal.Proposal.ProposalExpiration {
func (st *StorageMarketState) validateDeal(vmctx types.VMContext, deal StorageDealProposal, providerWorker address.Address) aerrors.ActorError {
if vmctx.BlockHeight() > deal.ProposalExpiration {
return aerrors.New(1, "deal proposal already expired")
}
if err := deal.Proposal.Verify(); err != nil {
return aerrors.Absorb(err, 2, "verifying proposer signature")
if vmctx.Message().From != providerWorker {
return aerrors.New(2, "Deals must be submitted by the miner worker")
}
err := deal.Verify(providerWorker)
if err != nil {
return aerrors.Absorb(err, 2, "verifying provider signature")
}
// TODO: maybe this is actually fine
if vmctx.Message().From != providerWorker && vmctx.Message().From != deal.Proposal.Client {
return aerrors.New(4, "message not sent by deal participant")
if err := deal.Verify(); err != nil {
return aerrors.Absorb(err, 3, "verifying proposer signature")
}
// TODO: do some caching (changes gas so needs to be in spec too)
b, bnd, aerr := GetMarketBalances(vmctx.Context(), vmctx.Ipld(), st.Balances, deal.Proposal.Client, providerWorker)
b, bnd, aerr := GetMarketBalances(vmctx.Context(), vmctx.Ipld(), st.Balances, deal.Client, providerWorker)
if aerr != nil {
return aerrors.Wrap(aerr, "getting client, and provider balances")
}
clientBalance := b[0]
providerBalance := b[1]
totalPrice := deal.Proposal.TotalStoragePrice()
totalPrice := deal.TotalStoragePrice()
if clientBalance.Available.LessThan(totalPrice) {
return aerrors.Newf(5, "client doesn't have enough available funds to cover storage price; %d < %d", clientBalance.Available, totalPrice)
@ -412,17 +406,17 @@ func (st *StorageMarketState) validateDeal(vmctx types.VMContext, deal StorageDe
clientBalance = lockFunds(clientBalance, totalPrice)
// TODO: REVIEW: Not clear who pays for this
if providerBalance.Available.LessThan(deal.Proposal.StorageCollateral) {
return aerrors.Newf(6, "provider doesn't have enough available funds to cover StorageCollateral; %d < %d", providerBalance.Available, deal.Proposal.StorageCollateral)
if providerBalance.Available.LessThan(deal.StorageCollateral) {
return aerrors.Newf(6, "provider doesn't have enough available funds to cover StorageCollateral; %d < %d", providerBalance.Available, deal.StorageCollateral)
}
providerBalance = lockFunds(providerBalance, deal.Proposal.StorageCollateral)
providerBalance = lockFunds(providerBalance, deal.StorageCollateral)
// TODO: piece checks (e.g. size > sectorSize)?
bcid, aerr := setMarketBalances(vmctx, bnd, map[address.Address]StorageParticipantBalance{
deal.Proposal.Client: clientBalance,
providerWorker: providerBalance,
deal.Client: clientBalance,
providerWorker: providerBalance,
})
if aerr != nil {
return aerr
@ -458,11 +452,11 @@ func (sma StorageMarketActor) ActivateStorageDeals(act *types.Actor, vmctx types
return nil, aerrors.HandleExternalError(err, "getting deal info failed")
}
if vmctx.Message().From != dealInfo.Deal.Proposal.Provider {
if vmctx.Message().From != dealInfo.Provider {
return nil, aerrors.New(1, "ActivateStorageDeals can only be called by the deal provider")
}
if vmctx.BlockHeight() > dealInfo.Deal.Proposal.ProposalExpiration {
if vmctx.BlockHeight() > dealInfo.ProposalExpiration {
return nil, aerrors.New(2, "deal cannot be activated: proposal expired")
}
@ -533,7 +527,7 @@ func (sma StorageMarketActor) ProcessStorageDealsPayment(act *types.Actor, vmctx
return nil, aerrors.HandleExternalError(err, "getting deal info failed")
}
if dealInfo.Deal.Proposal.Provider != vmctx.Message().From {
if dealInfo.Provider != vmctx.Message().From {
return nil, aerrors.New(3, "ProcessStorageDealsPayment can only be called by deal provider")
}
@ -542,15 +536,15 @@ func (sma StorageMarketActor) ProcessStorageDealsPayment(act *types.Actor, vmctx
return nil, aerrors.New(4, "ActivationEpoch lower than block height")
}
if vmctx.BlockHeight() > dealInfo.ActivationEpoch+dealInfo.Deal.Proposal.Duration {
if vmctx.BlockHeight() > dealInfo.ActivationEpoch+dealInfo.Duration {
// Deal expired, miner should drop it
// TODO: process payment for the remainder of last proving period
return nil, nil
}
toPay := types.BigMul(dealInfo.Deal.Proposal.StoragePricePerEpoch, types.NewInt(build.SlashablePowerDelay))
toPay := types.BigMul(dealInfo.StoragePricePerEpoch, types.NewInt(build.SlashablePowerDelay))
b, bnd, aerr := GetMarketBalances(vmctx.Context(), vmctx.Ipld(), self.Balances, dealInfo.Deal.Proposal.Client, providerWorker)
b, bnd, aerr := GetMarketBalances(vmctx.Context(), vmctx.Ipld(), self.Balances, dealInfo.Client, providerWorker)
if aerr != nil {
return nil, aerr
}
@ -561,8 +555,8 @@ func (sma StorageMarketActor) ProcessStorageDealsPayment(act *types.Actor, vmctx
// TODO: call set once
bcid, aerr := setMarketBalances(vmctx, bnd, map[address.Address]StorageParticipantBalance{
dealInfo.Deal.Proposal.Client: clientBal,
providerWorker: providerBal,
dealInfo.Client: clientBal,
providerWorker: providerBal,
})
if aerr != nil {
return nil, aerr
@ -625,15 +619,15 @@ func (sma StorageMarketActor) ComputeDataCommitment(act *types.Actor, vmctx type
return nil, aerrors.HandleExternalError(err, "getting deal info failed")
}
if dealInfo.Deal.Proposal.Provider != vmctx.Message().From {
if dealInfo.Provider != vmctx.Message().From {
return nil, aerrors.New(5, "referenced deal was not from caller")
}
var commP [32]byte
copy(commP[:], dealInfo.Deal.Proposal.PieceRef)
copy(commP[:], dealInfo.PieceRef)
pieces = append(pieces, sectorbuilder.PublicPieceInfo{
Size: dealInfo.Deal.Proposal.PieceSize,
Size: dealInfo.PieceSize,
CommP: commP,
})
}

View File

@ -3350,75 +3350,6 @@ func (t *StorageDealProposal) UnmarshalCBOR(r io.Reader) error {
return nil
}
func (t *StorageDeal) MarshalCBOR(w io.Writer) error {
if t == nil {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{130}); err != nil {
return err
}
// t.t.Proposal (actors.StorageDealProposal) (struct)
if err := t.Proposal.MarshalCBOR(w); err != nil {
return err
}
// t.t.CounterSignature (types.Signature) (struct)
if err := t.CounterSignature.MarshalCBOR(w); err != nil {
return err
}
return nil
}
func (t *StorageDeal) UnmarshalCBOR(r io.Reader) error {
br := cbg.GetPeeker(r)
maj, extra, err := cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajArray {
return fmt.Errorf("cbor input should be of type array")
}
if extra != 2 {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Proposal (actors.StorageDealProposal) (struct)
{
if err := t.Proposal.UnmarshalCBOR(br); err != nil {
return err
}
}
// t.t.CounterSignature (types.Signature) (struct)
{
pb, err := br.PeekByte()
if err != nil {
return err
}
if pb == cbg.CborNull[0] {
var nbuf [1]byte
if _, err := br.Read(nbuf[:]); err != nil {
return err
}
} else {
t.CounterSignature = new(types.Signature)
if err := t.CounterSignature.UnmarshalCBOR(br); err != nil {
return err
}
}
}
return nil
}
func (t *PublishStorageDealsParams) MarshalCBOR(w io.Writer) error {
if t == nil {
_, err := w.Write(cbg.CborNull)
@ -3428,7 +3359,7 @@ func (t *PublishStorageDealsParams) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.Deals ([]actors.StorageDeal) (slice)
// t.t.Deals ([]actors.StorageDealProposal) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Deals)))); err != nil {
return err
}
@ -3455,7 +3386,7 @@ func (t *PublishStorageDealsParams) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Deals ([]actors.StorageDeal) (slice)
// t.t.Deals ([]actors.StorageDealProposal) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -3469,11 +3400,11 @@ func (t *PublishStorageDealsParams) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("expected cbor array")
}
if extra > 0 {
t.Deals = make([]StorageDeal, extra)
t.Deals = make([]StorageDealProposal, extra)
}
for i := 0; i < int(extra); i++ {
var v StorageDeal
var v StorageDealProposal
if err := v.UnmarshalCBOR(br); err != nil {
return err
}
@ -3696,12 +3627,55 @@ func (t *OnChainDeal) MarshalCBOR(w io.Writer) error {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{130}); err != nil {
if _, err := w.Write([]byte{138}); err != nil {
return err
}
// t.t.Deal (actors.StorageDeal) (struct)
if err := t.Deal.MarshalCBOR(w); err != nil {
// t.t.PieceRef ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.PieceRef)))); err != nil {
return err
}
if _, err := w.Write(t.PieceRef); err != nil {
return err
}
// t.t.PieceSize (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.PieceSize))); err != nil {
return err
}
// t.t.PieceSerialization (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.PieceSerialization))); err != nil {
return err
}
// t.t.Client (address.Address) (struct)
if err := t.Client.MarshalCBOR(w); err != nil {
return err
}
// t.t.Provider (address.Address) (struct)
if err := t.Provider.MarshalCBOR(w); err != nil {
return err
}
// t.t.ProposalExpiration (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.ProposalExpiration))); err != nil {
return err
}
// t.t.Duration (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Duration))); err != nil {
return err
}
// t.t.StoragePricePerEpoch (types.BigInt) (struct)
if err := t.StoragePricePerEpoch.MarshalCBOR(w); err != nil {
return err
}
// t.t.StorageCollateral (types.BigInt) (struct)
if err := t.StorageCollateral.MarshalCBOR(w); err != nil {
return err
}
@ -3723,15 +3697,99 @@ func (t *OnChainDeal) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input should be of type array")
}
if extra != 2 {
if extra != 10 {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Deal (actors.StorageDeal) (struct)
// t.t.PieceRef ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if extra > 8192 {
return fmt.Errorf("t.PieceRef: array too large (%d)", extra)
}
if maj != cbg.MajByteString {
return fmt.Errorf("expected byte array")
}
t.PieceRef = make([]byte, extra)
if _, err := io.ReadFull(br, t.PieceRef); err != nil {
return err
}
// t.t.PieceSize (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.PieceSize = uint64(extra)
// t.t.PieceSerialization (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.PieceSerialization = uint64(extra)
// t.t.Client (address.Address) (struct)
{
if err := t.Deal.UnmarshalCBOR(br); err != nil {
if err := t.Client.UnmarshalCBOR(br); err != nil {
return err
}
}
// t.t.Provider (address.Address) (struct)
{
if err := t.Provider.UnmarshalCBOR(br); err != nil {
return err
}
}
// t.t.ProposalExpiration (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.ProposalExpiration = uint64(extra)
// t.t.Duration (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.Duration = uint64(extra)
// t.t.StoragePricePerEpoch (types.BigInt) (struct)
{
if err := t.StoragePricePerEpoch.UnmarshalCBOR(br); err != nil {
return err
}
}
// t.t.StorageCollateral (types.BigInt) (struct)
{
if err := t.StorageCollateral.UnmarshalCBOR(br); err != nil {
return err
}

View File

@ -5,7 +5,7 @@ import (
"io"
"github.com/filecoin-project/lotus/chain/types"
cid "github.com/ipfs/go-cid"
"github.com/ipfs/go-cid"
cbg "github.com/whyrusleeping/cbor-gen"
xerrors "golang.org/x/xerrors"
)

View File

@ -192,7 +192,7 @@ func (t *Response) MarshalCBOR(w io.Writer) error {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{133}); err != nil {
if _, err := w.Write([]byte{132}); err != nil {
return err
}
@ -215,23 +215,10 @@ func (t *Response) MarshalCBOR(w io.Writer) error {
return xerrors.Errorf("failed to write cid field t.Proposal: %w", err)
}
// t.t.StorageDeal (actors.StorageDeal) (struct)
if err := t.StorageDeal.MarshalCBOR(w); err != nil {
// t.t.StorageDealSubmission (types.SignedMessage) (struct)
if err := t.StorageDealSubmission.MarshalCBOR(w); err != nil {
return err
}
// t.t.PublishMessage (cid.Cid) (struct)
if t.PublishMessage == nil {
if _, err := w.Write(cbg.CborNull); err != nil {
return err
}
} else {
if err := cbg.WriteCid(w, *t.PublishMessage); err != nil {
return xerrors.Errorf("failed to write cid field t.PublishMessage: %w", err)
}
}
return nil
}
@ -246,7 +233,7 @@ func (t *Response) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input should be of type array")
}
if extra != 5 {
if extra != 4 {
return fmt.Errorf("cbor input had wrong number of fields")
}
@ -282,7 +269,7 @@ func (t *Response) UnmarshalCBOR(r io.Reader) error {
t.Proposal = c
}
// t.t.StorageDeal (actors.StorageDeal) (struct)
// t.t.StorageDealSubmission (types.SignedMessage) (struct)
{
@ -296,36 +283,12 @@ func (t *Response) UnmarshalCBOR(r io.Reader) error {
return err
}
} else {
t.StorageDeal = new(actors.StorageDeal)
if err := t.StorageDeal.UnmarshalCBOR(br); err != nil {
t.StorageDealSubmission = new(types.SignedMessage)
if err := t.StorageDealSubmission.UnmarshalCBOR(br); err != nil {
return err
}
}
}
// t.t.PublishMessage (cid.Cid) (struct)
{
pb, err := br.PeekByte()
if err != nil {
return err
}
if pb == cbg.CborNull[0] {
var nbuf [1]byte
if _, err := br.Read(nbuf[:]); err != nil {
return err
}
} else {
c, err := cbg.ReadCid(br)
if err != nil {
return xerrors.Errorf("failed to read cid field t.PublishMessage: %w", err)
}
t.PublishMessage = &c
}
}
return nil
}
@ -593,18 +556,10 @@ func (t *ClientDeal) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.PublishMessage (cid.Cid) (struct)
if t.PublishMessage == nil {
if _, err := w.Write(cbg.CborNull); err != nil {
return err
}
} else {
if err := cbg.WriteCid(w, *t.PublishMessage); err != nil {
return xerrors.Errorf("failed to write cid field t.PublishMessage: %w", err)
}
// t.t.PublishMessage (types.SignedMessage) (struct)
if err := t.PublishMessage.MarshalCBOR(w); err != nil {
return err
}
return nil
}
@ -683,7 +638,7 @@ func (t *ClientDeal) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field")
}
t.DealID = uint64(extra)
// t.t.PublishMessage (cid.Cid) (struct)
// t.t.PublishMessage (types.SignedMessage) (struct)
{
@ -697,13 +652,10 @@ func (t *ClientDeal) UnmarshalCBOR(r io.Reader) error {
return err
}
} else {
c, err := cbg.ReadCid(br)
if err != nil {
return xerrors.Errorf("failed to read cid field t.PublishMessage: %w", err)
t.PublishMessage = new(types.SignedMessage)
if err := t.PublishMessage.UnmarshalCBOR(br); err != nil {
return err
}
t.PublishMessage = &c
}
}

View File

@ -36,7 +36,7 @@ type ClientDeal struct {
MinerWorker address.Address
DealID uint64
PublishMessage *cid.Cid
PublishMessage *types.SignedMessage
s inet.Stream
}

View File

@ -44,6 +44,9 @@ func (c *Client) new(ctx context.Context, deal ClientDeal) (func(*ClientDeal), e
if err != nil {
return nil, err
}
// TODO: verify StorageDealSubmission
if err := c.disconnect(deal); err != nil {
return nil, err
}
@ -54,18 +57,14 @@ func (c *Client) new(ctx context.Context, deal ClientDeal) (func(*ClientDeal), e
}
return func(info *ClientDeal) {
info.PublishMessage = resp.PublishMessage
info.PublishMessage = resp.StorageDealSubmission
}, nil
}
func (c *Client) accepted(ctx context.Context, deal ClientDeal) (func(*ClientDeal), error) {
log.Infow("DEAL ACCEPTED!")
pubmsg, err := c.chain.GetMessage(*deal.PublishMessage)
if err != nil {
return nil, xerrors.Errorf("getting deal pubsish message: %w", err)
}
pubmsg := deal.PublishMessage.Message
pw, err := stmgr.GetMinerWorker(ctx, c.sm, nil, deal.Proposal.Provider)
if err != nil {
return nil, xerrors.Errorf("getting miner worker failed: %w", err)
@ -91,7 +90,7 @@ func (c *Client) accepted(ctx context.Context, deal ClientDeal) (func(*ClientDea
dealIdx := -1
for i, storageDeal := range params.Deals {
// TODO: make it less hacky
eq, err := cborutil.Equals(&deal.Proposal, &storageDeal.Proposal)
eq, err := cborutil.Equals(&deal.Proposal, &storageDeal)
if err != nil {
return nil, err
}
@ -102,11 +101,11 @@ func (c *Client) accepted(ctx context.Context, deal ClientDeal) (func(*ClientDea
}
if dealIdx == -1 {
return nil, xerrors.Errorf("deal publish didn't contain our deal (message cid: %s)", deal.PublishMessage)
return nil, xerrors.Errorf("deal publish didn't contain our deal (message cid: %s)", deal.PublishMessage.Cid())
}
// TODO: timeout
_, ret, err := c.sm.WaitForMessage(ctx, *deal.PublishMessage)
_, ret, err := c.sm.WaitForMessage(ctx, deal.PublishMessage.Cid())
if err != nil {
return nil, xerrors.Errorf("waiting for deal publish message: %w", err)
}

View File

@ -93,15 +93,8 @@ func (p *Provider) accept(ctx context.Context, deal MinerDeal) (func(*MinerDeal)
log.Info("publishing deal")
storageDeal := actors.StorageDeal{
Proposal: deal.Proposal,
}
if err := api.SignWith(ctx, p.full.WalletSign, waddr, &storageDeal); err != nil {
return nil, xerrors.Errorf("signing storage deal failed: ", err)
}
params, err := actors.SerializeParams(&actors.PublishStorageDealsParams{
Deals: []actors.StorageDeal{storageDeal},
Deals: []actors.StorageDealProposal{deal.Proposal},
})
if err != nil {
return nil, xerrors.Errorf("serializing PublishStorageDeals params failed: ", err)
@ -136,13 +129,11 @@ func (p *Provider) accept(ctx context.Context, deal MinerDeal) (func(*MinerDeal)
}
log.Infof("fetching data for a deal %d", resp.DealIDs[0])
mcid := smsg.Cid()
err = p.sendSignedResponse(&Response{
State: api.DealAccepted,
Proposal: deal.ProposalCid,
PublishMessage: &mcid,
StorageDeal: &storageDeal,
Proposal: deal.ProposalCid,
StorageDealSubmission: smsg,
})
if err != nil {
return nil, err

View File

@ -58,8 +58,7 @@ type Response struct {
Proposal cid.Cid
// DealAccepted
StorageDeal *actors.StorageDeal
PublishMessage *cid.Cid
StorageDealSubmission *types.SignedMessage
}
// TODO: Do we actually need this to be signed?

View File

@ -197,7 +197,7 @@ func SetupStoragePowerActor(bs bstore.Blockstore) (*types.Actor, error) {
}, nil
}
func SetupStorageMarketActor(bs bstore.Blockstore, sroot cid.Cid, deals []actors.StorageDeal) (cid.Cid, error) {
func SetupStorageMarketActor(bs bstore.Blockstore, sroot cid.Cid, deals []actors.StorageDealProposal) (cid.Cid, error) {
cst := hamt.CSTFromBstore(bs)
nd := hamt.NewNode(cst)
emptyHAMT, err := cst.Put(context.TODO(), nd)
@ -210,8 +210,16 @@ func SetupStorageMarketActor(bs bstore.Blockstore, sroot cid.Cid, deals []actors
cdeals := make([]cbg.CBORMarshaler, len(deals))
for i, deal := range deals {
cdeals[i] = &actors.OnChainDeal{
Deal: deal,
ActivationEpoch: 1,
PieceRef: deal.PieceRef,
PieceSize: deal.PieceSize,
PieceSerialization: deal.PieceSerialization,
Client: deal.Client,
Provider: deal.Provider,
ProposalExpiration: deal.ProposalExpiration,
Duration: deal.Duration,
StoragePricePerEpoch: deal.StoragePricePerEpoch,
StorageCollateral: deal.StorageCollateral,
ActivationEpoch: 1,
}
}
@ -267,7 +275,7 @@ func mustEnc(i cbg.CBORMarshaler) []byte {
return enc
}
func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid, gmcfg *GenMinerCfg) (cid.Cid, []actors.StorageDeal, error) {
func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid, gmcfg *GenMinerCfg) (cid.Cid, []actors.StorageDealProposal, error) {
vm, err := vm.NewVM(sroot, 0, nil, actors.NetworkAddress, cs.Blockstore())
if err != nil {
return cid.Undef, nil, xerrors.Errorf("failed to create NewVM: %w", err)
@ -281,7 +289,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid
return cid.Undef, nil, xerrors.Errorf("miner address list, and preseal count doesn't match (%d != %d)", len(gmcfg.MinerAddrs), len(gmcfg.PreSeals))
}
var deals []actors.StorageDeal
var deals []actors.StorageDealProposal
for i, maddr := range gmcfg.MinerAddrs {
ps, psok := gmcfg.PreSeals[maddr.String()]

View File

@ -5,7 +5,7 @@ import (
"io"
"math"
cid "github.com/ipfs/go-cid"
"github.com/ipfs/go-cid"
cbg "github.com/whyrusleeping/cbor-gen"
xerrors "golang.org/x/xerrors"
)

View File

@ -2,11 +2,11 @@ package seed
import (
"context"
"crypto/rand"
"crypto/sha256"
"encoding/json"
"fmt"
"io/ioutil"
"math/rand"
"os"
"path/filepath"
@ -53,7 +53,6 @@ func PreSeal(maddr address.Address, ssize uint64, offset uint64, sectors int, sb
return nil, err
}
r := rand.New(rand.NewSource(101))
size := sectorbuilder.UserBytesForSectorSize(ssize)
var sealedSectors []*genesis.PreSeal
@ -63,7 +62,7 @@ func PreSeal(maddr address.Address, ssize uint64, offset uint64, sectors int, sb
return nil, err
}
pi, err := sb.AddPiece(size, sid, r, nil)
pi, err := sb.AddPiece(size, sid, rand.Reader, nil)
if err != nil {
return nil, err
}
@ -153,20 +152,12 @@ func createDeals(m *genesis.GenesisMiner, k *wallet.Key, maddr address.Address,
ProposerSignature: nil,
}
// TODO: pretty sure we don't even need to sign this
if err := api.SignWith(context.TODO(), wallet.KeyWallet(k).Sign, k.Address, proposal); err != nil {
return err
}
deal := &actors.StorageDeal{
Proposal: *proposal,
CounterSignature: nil,
}
if err := api.SignWith(context.TODO(), wallet.KeyWallet(k).Sign, k.Address, deal); err != nil {
return err
}
sector.Deal = *deal
sector.Deal = *proposal
}
return nil

View File

@ -1,6 +1,7 @@
package main
import (
"bytes"
"context"
"crypto/rand"
"encoding/json"
@ -267,7 +268,7 @@ func migratePreSealMeta(ctx context.Context, api lapi.FullNode, presealDir strin
return err
}
proposalCid, err := sector.Deal.Proposal.Cid()
proposalCid, err := sector.Deal.Cid()
if err != nil {
return err
}
@ -275,7 +276,7 @@ func migratePreSealMeta(ctx context.Context, api lapi.FullNode, presealDir strin
dealKey := datastore.NewKey(deals.ProviderDsPrefix).ChildString(proposalCid.String())
deal := &deals.MinerDeal{
Proposal: sector.Deal.Proposal,
Proposal: sector.Deal,
ProposalCid: proposalCid,
State: lapi.DealComplete,
Ref: proposalCid, // TODO: This is super wrong, but there
@ -298,7 +299,7 @@ func migratePreSealMeta(ctx context.Context, api lapi.FullNode, presealDir strin
return nil
}
func findMarketDealID(ctx context.Context, api lapi.FullNode, deal actors.StorageDeal) (uint64, error) {
func findMarketDealID(ctx context.Context, api lapi.FullNode, deal actors.StorageDealProposal) (uint64, error) {
// TODO: find a better way
// (this is only used by genesis miners)
@ -308,11 +309,7 @@ func findMarketDealID(ctx context.Context, api lapi.FullNode, deal actors.Storag
}
for k, v := range deals {
eq, err := cborutil.Equals(&v.Deal, &deal)
if err != nil {
return 0, err
}
if eq {
if bytes.Equal(v.PieceRef, deal.PieceRef) {
return strconv.ParseUint(k, 10, 64)
}
}

View File

@ -122,7 +122,6 @@ func main() {
actors.StorageMarketState{},
actors.WithdrawBalanceParams{},
actors.StorageDealProposal{},
actors.StorageDeal{},
actors.PublishStorageDealsParams{},
actors.PublishStorageDealResponse{},
actors.ActivateStorageDealsParams{},

View File

@ -10,7 +10,7 @@ type PreSeal struct {
CommR [32]byte
CommD [32]byte
SectorID uint64
Deal actors.StorageDeal
Deal actors.StorageDealProposal
}
type GenesisMiner struct {

View File

@ -20,7 +20,7 @@ func (m *Miner) storeGarbage(ctx context.Context, sectorID uint64, existingPiece
return nil, nil
}
deals := make([]actors.StorageDeal, len(sizes))
deals := make([]actors.StorageDealProposal, len(sizes))
for i, size := range sizes {
release := m.sb.RateLimit()
commP, err := sectorbuilder.GeneratePieceCommitment(io.LimitReader(rand.New(rand.NewSource(42)), int64(size)), size)
@ -47,14 +47,7 @@ func (m *Miner) storeGarbage(ctx context.Context, sectorID uint64, existingPiece
return nil, xerrors.Errorf("signing storage deal failed: ", err)
}
storageDeal := actors.StorageDeal{
Proposal: sdp,
}
if err := api.SignWith(ctx, m.api.WalletSign, m.worker, &storageDeal); err != nil {
return nil, xerrors.Errorf("signing storage deal failed: ", err)
}
deals[i] = storageDeal
deals[i] = sdp
}
params, aerr := actors.SerializeParams(&actors.PublishStorageDealsParams{