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

fix(storagemarket): set miner peer id on deals #216

Merged
merged 1 commit into from
Apr 30, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions storagemarket/impl/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ func (p *Provider) receiveDeal(s network.StorageDealStream) error {

deal := &storagemarket.MinerDeal{
Client: s.RemotePeer(),
Miner: p.net.ID(),
ClientDealProposal: *proposal.DealProposal,
ProposalCid: proposalNd.Cid(),
State: storagemarket.StorageDealUnknown,
Expand Down
12 changes: 12 additions & 0 deletions storagemarket/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package storagemarket_test
import (
"bytes"
"context"
"encoding/json"
"io/ioutil"
"math/rand"
"reflect"
Expand Down Expand Up @@ -44,7 +45,18 @@ func TestMakeDeal(t *testing.T) {

// set up a subscriber
dealChan := make(chan storagemarket.MinerDeal)
var checkedUnmarshalling bool
subscriber := func(event storagemarket.ProviderEvent, deal storagemarket.MinerDeal) {
if !checkedUnmarshalling {
// test that deal created can marshall and unmarshalled
jsonBytes, err := json.Marshal(deal)
require.NoError(t, err)
var unmarhalledDeal storagemarket.MinerDeal
err = json.Unmarshal(jsonBytes, &unmarhalledDeal)
require.NoError(t, err)
require.Equal(t, deal, unmarhalledDeal)
checkedUnmarshalling = true
}
dealChan <- deal
}
_ = h.Provider.SubscribeToEvents(subscriber)
Expand Down
4 changes: 4 additions & 0 deletions storagemarket/network/libp2p_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,7 @@ func (impl *libp2pStorageMarketNetwork) handleNewDealStream(s network.Stream) {
ds := &dealStream{remotePID, s, buffered}
impl.receiver.HandleDealStream(ds)
}

func (impl *libp2pStorageMarketNetwork) ID() peer.ID {
return impl.host.ID()
}
1 change: 1 addition & 0 deletions storagemarket/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ type StorageMarketNetwork interface {
NewDealStream(peer.ID) (StorageDealStream, error)
SetDelegate(StorageReceiver) error
StopHandlingRequests() error
ID() peer.ID
}