From 5e9a9cbac406599049c4cef6f67527fbc49a9684 Mon Sep 17 00:00:00 2001 From: Hannah Howard Date: Thu, 30 Apr 2020 16:15:39 -0700 Subject: [PATCH] fix(storagemarket): set miner peer id on deals (#216) Set the local miner peer id on MinerDeal and verify JSON marshall/unmarshal works --- storagemarket/impl/provider.go | 1 + storagemarket/integration_test.go | 12 ++++++++++++ storagemarket/network/libp2p_impl.go | 4 ++++ storagemarket/network/network.go | 1 + 4 files changed, 18 insertions(+) diff --git a/storagemarket/impl/provider.go b/storagemarket/impl/provider.go index 975f3844..10df72c1 100644 --- a/storagemarket/impl/provider.go +++ b/storagemarket/impl/provider.go @@ -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, diff --git a/storagemarket/integration_test.go b/storagemarket/integration_test.go index 946704d8..f5c1dbb3 100644 --- a/storagemarket/integration_test.go +++ b/storagemarket/integration_test.go @@ -3,6 +3,7 @@ package storagemarket_test import ( "bytes" "context" + "encoding/json" "io/ioutil" "math/rand" "reflect" @@ -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) diff --git a/storagemarket/network/libp2p_impl.go b/storagemarket/network/libp2p_impl.go index 4699f89e..8eeeef2d 100644 --- a/storagemarket/network/libp2p_impl.go +++ b/storagemarket/network/libp2p_impl.go @@ -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() +} diff --git a/storagemarket/network/network.go b/storagemarket/network/network.go index bc954380..03c4b8d7 100644 --- a/storagemarket/network/network.go +++ b/storagemarket/network/network.go @@ -38,4 +38,5 @@ type StorageMarketNetwork interface { NewDealStream(peer.ID) (StorageDealStream, error) SetDelegate(StorageReceiver) error StopHandlingRequests() error + ID() peer.ID }