Skip to content

Commit

Permalink
use addresses from miner info for connecting to miners (#290)
Browse files Browse the repository at this point in the history
* use addresses from miner info for connecting to miners

* fix(storagemarket): fix integration test harness (#291)

Provide a real response to GetMinerInfo so that integration tests pass

* fix(storagemarket): fix rebase issues

fix problems from rebase and add a few doc things

Co-authored-by: Hannah Howard <[email protected]>
  • Loading branch information
whyrusleeping and hannahhoward authored Jun 29, 2020
1 parent ecce3a1 commit 2da69d9
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 4 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ require (
github.com/jbenet/go-random v0.0.0-20190219211222-123a90aedc0c
github.com/libp2p/go-libp2p v0.6.0
github.com/libp2p/go-libp2p-core v0.5.0
github.com/multiformats/go-multiaddr v0.2.1
github.com/multiformats/go-multihash v0.0.13
github.com/stretchr/testify v1.5.1
github.com/whyrusleeping/cbor-gen v0.0.0-20200414195334-429a0b5e922e
Expand Down
1 change: 1 addition & 0 deletions retrievalmarket/storage_retrieval_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ func newStorageHarness(ctx context.Context, t *testing.T) *storageHarness {
PeerID: td.Host2.ID(),
}

smState.Providers = []*storagemarket.StorageProviderInfo{&providerInfo}
return &storageHarness{
Ctx: ctx,
Epoch: epoch,
Expand Down
10 changes: 10 additions & 0 deletions storagemarket/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,16 @@ func ValidateAskSignature(ctx context.Context, ask *SignedStorageAsk, tok shared
```
Verify the signature in `ask`, returning true (valid) or false (invalid).


#### GetMinerInfo
```go
func GetMinerInfo(ctx context.Context, maddr address.Address, tok shared.TipSetToken,
) (*StorageProviderInfo, error)
```

Returns `StorageProviderInfo` for a specific provider at the given address


## Construction

### StorageClient
Expand Down
20 changes: 16 additions & 4 deletions storagemarket/impl/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ func (c *Client) GetLocalDeal(ctx context.Context, cid cid.Cid) (storagemarket.C
// When it receives a response, it verifies the signature and returns the validated
// StorageAsk if successful
func (c *Client) GetAsk(ctx context.Context, info storagemarket.StorageProviderInfo) (*storagemarket.SignedStorageAsk, error) {
if len(info.Addrs) > 0 {
c.net.AddAddrs(info.PeerID, info.Addrs)
}
s, err := c.net.NewAskStream(info.PeerID)
if err != nil {
return nil, xerrors.Errorf("failed to open stream to miner: %w", err)
Expand Down Expand Up @@ -409,7 +412,7 @@ func (c *Client) restartDeals() error {
continue
}

_, err := c.ensureDealStream(deal.Miner, deal.ProposalCid)
_, err := c.ensureDealStream(context.TODO(), deal.ProposalCid, deal.ClientDealProposal.Proposal.Provider)
if err != nil {
return err
}
Expand Down Expand Up @@ -438,13 +441,22 @@ func (c *Client) dispatch(eventName fsm.EventName, deal fsm.StateType) {
}
}

func (c *Client) ensureDealStream(provider peer.ID, proposalCid cid.Cid) (network.StorageDealStream, error) {
func (c *Client) ensureDealStream(ctx context.Context, proposalCid cid.Cid, maddr address.Address) (network.StorageDealStream, error) {
s, err := c.conns.DealStream(proposalCid)
if err == nil {
return s, nil
}

s, err = c.net.NewDealStream(provider)
minfo, err := c.node.GetMinerInfo(ctx, maddr, nil)
if err != nil {
return nil, err
}

if len(minfo.Addrs) > 0 {
c.net.AddAddrs(minfo.PeerID, minfo.Addrs)
}

s, err = c.net.NewDealStream(minfo.PeerID)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -518,7 +530,7 @@ func (c *clientDealEnvironment) Node() storagemarket.StorageClientNode {
}

func (c *clientDealEnvironment) WriteDealProposal(p peer.ID, proposalCid cid.Cid, proposal network.Proposal) error {
s, err := c.c.ensureDealStream(p, proposalCid)
s, err := c.c.ensureDealStream(context.TODO(), proposalCid, proposal.DealProposal.Proposal.Provider)
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions storagemarket/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ func newHarnessWithTestData(t *testing.T, ctx context.Context, td *shared_testut
PeerID: td.Host2.ID(),
}

smState.Providers = []*storagemarket.StorageProviderInfo{&providerInfo}
return &harness{
Ctx: ctx,
Epoch: epoch,
Expand Down
6 changes: 6 additions & 0 deletions storagemarket/network/libp2p_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package network
import (
"bufio"
"context"
"time"

logging "github.com/ipfs/go-log/v2"
"github.com/libp2p/go-libp2p-core/host"
"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"
ma "github.com/multiformats/go-multiaddr"

"github.com/filecoin-project/go-fil-markets/storagemarket"
)
Expand Down Expand Up @@ -108,3 +110,7 @@ func (impl *libp2pStorageMarketNetwork) getReaderOrReset(s network.Stream) *bufi
func (impl *libp2pStorageMarketNetwork) ID() peer.ID {
return impl.host.ID()
}

func (impl *libp2pStorageMarketNetwork) AddAddrs(p peer.ID, addrs []ma.Multiaddr) {
impl.host.Peerstore().AddAddrs(p, addrs, time.Minute*10)
}
3 changes: 3 additions & 0 deletions storagemarket/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package network

import (
"github.com/libp2p/go-libp2p-core/peer"

ma "github.com/multiformats/go-multiaddr"
)

// These are the required interfaces that must be implemented to send and receive data
Expand Down Expand Up @@ -56,4 +58,5 @@ type StorageMarketNetwork interface {
SetDelegate(StorageReceiver) error
StopHandlingRequests() error
ID() peer.ID
AddAddrs(peer.ID, []ma.Multiaddr)
}
3 changes: 3 additions & 0 deletions storagemarket/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,7 @@ type StorageClientNode interface {

// ValidateAskSignature verifies a the signature is valid for a given SignedStorageAsk
ValidateAskSignature(ctx context.Context, ask *SignedStorageAsk, tok shared.TipSetToken) (bool, error)

// GetMinerInfo returns info for a single miner with the given address
GetMinerInfo(ctx context.Context, maddr address.Address, tok shared.TipSetToken) (*StorageProviderInfo, error)
}
9 changes: 9 additions & 0 deletions storagemarket/testnodes/testnodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package testnodes

import (
"context"
"errors"
"io"

"github.com/filecoin-project/go-address"
Expand Down Expand Up @@ -224,6 +225,14 @@ func (n *FakeClientNode) GetDefaultWalletAddress(ctx context.Context) (address.A
return n.ClientAddr, nil
}

// GetMinerInfo returns stubbed information for the first miner in storage market state
func (n *FakeClientNode) GetMinerInfo(ctx context.Context, maddr address.Address, tok shared.TipSetToken) (*storagemarket.StorageProviderInfo, error) {
if len(n.SMState.Providers) == 0 {
return nil, errors.New("Provider not found")
}
return n.SMState.Providers[0], nil
}

// ValidateAskSignature returns the stubbed validation error and a boolean value
// communicating the validity of the provided signature
func (n *FakeClientNode) ValidateAskSignature(ctx context.Context, ask *storagemarket.SignedStorageAsk, tok shared.TipSetToken) (bool, error) {
Expand Down
2 changes: 2 additions & 0 deletions storagemarket/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/filecoin-project/specs-actors/actors/crypto"
"github.com/ipfs/go-cid"
"github.com/libp2p/go-libp2p-core/peer"
ma "github.com/multiformats/go-multiaddr"

"github.com/filecoin-project/go-fil-markets/filestore"
)
Expand Down Expand Up @@ -122,6 +123,7 @@ type StorageProviderInfo struct {
Worker address.Address // signs messages
SectorSize uint64
PeerID peer.ID
Addrs []ma.Multiaddr
}

// ProposeStorageDealResult returns the result for a proposing a deal
Expand Down

0 comments on commit 2da69d9

Please sign in to comment.