Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow specification of 'wallet' for ensure funds calls #129

Merged
merged 3 commits into from
Feb 28, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion retrievalmarket/impl/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func NewClient(
func (c *client) FindProviders(payloadCID cid.Cid) []retrievalmarket.RetrievalPeer {
peers, err := c.resolver.GetPeers(payloadCID)
if err != nil {
log.Error(err)
log.Errorf("failed to get peers: %s", err)
return []retrievalmarket.RetrievalPeer{}
}
return peers
Expand Down
5 changes: 3 additions & 2 deletions retrievalmarket/impl/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/ipfs/go-datastore/namespace"
blockstore "github.com/ipfs/go-ipfs-blockstore"
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
"golang.org/x/xerrors"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-fil-markets/pieceio/cario"
Expand Down Expand Up @@ -274,7 +275,7 @@ func (p *provider) GetPieceSize(c cid.Cid) (uint64, error) {
func getPieceInfoFromCid(pieceStore piecestore.PieceStore, c cid.Cid) (piecestore.PieceInfo, error) {
cidInfo, err := pieceStore.GetCIDInfo(c)
if err != nil {
return piecestore.PieceInfoUndefined, err
return piecestore.PieceInfoUndefined, xerrors.Errorf("get cid info: %w", err)
}
var lastErr error
for _, pieceBlockLocation := range cidInfo.PieceBlockLocations {
Expand All @@ -284,5 +285,5 @@ func getPieceInfoFromCid(pieceStore piecestore.PieceStore, c cid.Cid) (piecestor
}
lastErr = err
}
return piecestore.PieceInfoUndefined, lastErr
return piecestore.PieceInfoUndefined, xerrors.Errorf("could not locate piece: %w", lastErr)
}
2 changes: 1 addition & 1 deletion storagemarket/impl/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func (c *Client) Start(ctx context.Context, p ClientDealProposal) (cid.Cid, erro
ClientCollateral: big.Zero(),
}

if err := c.node.EnsureFunds(ctx, p.Client, dealProposal.ClientBalanceRequirement()); err != nil {
if err := c.node.EnsureFunds(ctx, p.Client, p.Client, dealProposal.ClientBalanceRequirement()); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious what is the value of StorageClientNode taking two parameters if it's always going to be the same (it's clear why for the provider where the values are different)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah cause we have a common method in the integration test... I wonder if it would be better to just rewrite the test to not use fake common for that method.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cause in the implementation it's actually two different entire classes that don't share anything

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(as mentioned in slack) lotus also uses a common thingy for implementing this. We could have them be separate interfaces, but i think the mental overhead is lower if we just have it be the same. Plus, theres no reason you couldnt fund your deal collateral with a different account

return cid.Undef, xerrors.Errorf("adding market funds failed: %w", err)
}

Expand Down
2 changes: 1 addition & 1 deletion storagemarket/impl/provider_states.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (p *Provider) publishing(ctx context.Context, deal MinerDeal) (func(*MinerD
}

// TODO: check StorageCollateral (may be too large (or too small))
if err := p.spn.EnsureFunds(ctx, waddr, deal.Proposal.ProviderCollateral); err != nil {
if err := p.spn.EnsureFunds(ctx, deal.Proposal.Provider, waddr, deal.Proposal.ProviderCollateral); err != nil {
return nil, err
}

Expand Down
2 changes: 1 addition & 1 deletion storagemarket/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ func (n *fakeCommon) AddFunds(ctx context.Context, addr address.Address, amount
return nil
}

func (n *fakeCommon) EnsureFunds(ctx context.Context, addr address.Address, amount abi.TokenAmount) error {
func (n *fakeCommon) EnsureFunds(ctx context.Context, addr, wallet address.Address, amount abi.TokenAmount) error {
balance := n.SMState.Balance(addr)
if balance.Available.LessThan(amount) {
n.SMState.AddFunds(addr, big.Sub(amount, balance.Available))
Expand Down
5 changes: 3 additions & 2 deletions storagemarket/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ type StorageProviderNode interface {
AddFunds(ctx context.Context, addr address.Address, amount abi.TokenAmount) error

// Ensures that a storage market participant has a certain amount of available funds
EnsureFunds(ctx context.Context, addr address.Address, amount abi.TokenAmount) error
// If additional funds are needed, they will be sent from the 'wallet' address
EnsureFunds(ctx context.Context, addr, wallet address.Address, amount abi.TokenAmount) error

// GetBalance returns locked/unlocked for a storage participant. Used by both providers and clients.
GetBalance(ctx context.Context, addr address.Address) (Balance, error)
Expand Down Expand Up @@ -210,7 +211,7 @@ type StorageClientNode interface {
// Adds funds with the StorageMinerActor for a storage participant. Used by both providers and clients.
AddFunds(ctx context.Context, addr address.Address, amount abi.TokenAmount) error

EnsureFunds(ctx context.Context, addr address.Address, amount abi.TokenAmount) error
EnsureFunds(ctx context.Context, addr, wallet address.Address, amount abi.TokenAmount) error

// GetBalance returns locked/unlocked for a storage participant. Used by both providers and clients.
GetBalance(ctx context.Context, addr address.Address) (Balance, error)
Expand Down