Skip to content

Commit

Permalink
storage client: Call EnsureFunds more correctly (#123)
Browse files Browse the repository at this point in the history
* More correct client EnsureFunds call

* market client: Set ClientCollateral field
  • Loading branch information
magik6k authored Feb 24, 2020
1 parent bfd0308 commit 1f82dd5
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions storagemarket/impl/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/filecoin-project/go-fil-markets/storagemarket/network"

cborutil "github.com/filecoin-project/go-cbor-util"
"github.com/filecoin-project/specs-actors/actors/abi/big"
"github.com/ipfs/go-cid"
blockstore "github.com/ipfs/go-ipfs-blockstore"
logging "github.com/ipfs/go-log/v2"
Expand All @@ -23,7 +24,6 @@ import (
"github.com/filecoin-project/go-fil-markets/storagemarket"
"github.com/filecoin-project/go-statestore"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/abi/big"
"github.com/filecoin-project/specs-actors/actors/builtin/market"
)

Expand Down Expand Up @@ -192,11 +192,6 @@ type ClientDealProposal struct {
}

func (c *Client) Start(ctx context.Context, p ClientDealProposal) (cid.Cid, error) {
amount := big.Mul(p.PricePerEpoch, abi.NewTokenAmount(int64(p.EndEpoch)-int64(p.StartEpoch)))
if err := c.node.EnsureFunds(ctx, p.Client, amount); err != nil {
return cid.Undef, xerrors.Errorf("adding market funds failed: %w", err)
}

commP, pieceSize, err := c.commP(ctx, p.Data.Root)
if err != nil {
return cid.Undef, xerrors.Errorf("computing commP failed: %w", err)
Expand All @@ -211,6 +206,11 @@ func (c *Client) Start(ctx context.Context, p ClientDealProposal) (cid.Cid, erro
EndEpoch: p.EndEpoch,
StoragePricePerEpoch: p.PricePerEpoch,
ProviderCollateral: abi.NewTokenAmount(int64(pieceSize)), // TODO: real calc
ClientCollateral: big.Zero(),
}

if err := c.node.EnsureFunds(ctx, p.Client, dealProposal.ClientBalanceRequirement()); err != nil {
return cid.Undef, xerrors.Errorf("adding market funds failed: %w", err)
}

clientDealProposal, err := c.node.SignProposal(ctx, p.Client, dealProposal)
Expand Down

0 comments on commit 1f82dd5

Please sign in to comment.