Skip to content

Commit

Permalink
fix(storagemarket): set miner peer id on deals (#216)
Browse files Browse the repository at this point in the history
Set the local miner peer id on MinerDeal and verify JSON marshall/unmarshal works
  • Loading branch information
hannahhoward authored Apr 30, 2020
1 parent 6245a19 commit 5e9a9cb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
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
}

0 comments on commit 5e9a9cb

Please sign in to comment.