Skip to content

Commit

Permalink
feat(retrievalmarket): support regular blockstore
Browse files Browse the repository at this point in the history
support using regular blockstores on client side for IPFS compatibility
  • Loading branch information
hannahhoward committed Jul 28, 2020
1 parent 0fcc588 commit cf6b0a7
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 18 deletions.
2 changes: 1 addition & 1 deletion retrievalmarket/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type RetrievalClient interface {
miner peer.ID,
clientWallet address.Address,
minerWallet address.Address,
storeID multistore.StoreID,
storeID *multistore.StoreID,
) (DealID, error)

// SubscribeToEvents listens for events that happen related to client retrievals
Expand Down
15 changes: 10 additions & 5 deletions retrievalmarket/impl/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,18 @@ From then on, the statemachine controls the deal flow in the client. Other compo
Documentation of the client state machine can be found at https://godoc.org/github.com/filecoin-project/go-fil-markets/retrievalmarket/impl/clientstates
*/
func (c *Client) Retrieve(ctx context.Context, payloadCID cid.Cid, params retrievalmarket.Params, totalFunds abi.TokenAmount, miner peer.ID, clientWallet address.Address, minerWallet address.Address, storeID multistore.StoreID) (retrievalmarket.DealID, error) {
func (c *Client) Retrieve(ctx context.Context, payloadCID cid.Cid, params retrievalmarket.Params, totalFunds abi.TokenAmount, miner peer.ID, clientWallet address.Address, minerWallet address.Address, storeID *multistore.StoreID) (retrievalmarket.DealID, error) {
var err error
next, err := c.storedCounter.Next()
if err != nil {
return 0, err
}
// make sure the store is loadable
_, err = c.multiStore.Get(storeID)
if err != nil {
return 0, err
if storeID != nil {
_, err = c.multiStore.Get(*storeID)
if err != nil {
return 0, err
}
}
dealID := retrievalmarket.DealID(next)
dealState := retrievalmarket.ClientDealState{
Expand Down Expand Up @@ -305,7 +307,10 @@ func (csg *clientStoreGetter) Get(otherPeer peer.ID, dealID retrievalmarket.Deal
if err != nil {
return nil, err
}
return csg.c.multiStore.Get(deal.StoreID)
if deal.StoreID == nil {
return nil, nil
}
return csg.c.multiStore.Get(*deal.StoreID)
}

// ClientFSMParameterSpec is a valid set of parameters for a client deal FSM - used in doc generation
Expand Down
5 changes: 4 additions & 1 deletion retrievalmarket/impl/dtutils/dtutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

logging "github.com/ipfs/go-log/v2"
"github.com/ipld/go-ipld-prime"
peer "github.com/libp2p/go-libp2p-peer"
peer "github.com/libp2p/go-libp2p-core/peer"

datatransfer "github.com/filecoin-project/go-data-transfer"
"github.com/filecoin-project/go-multistore"
Expand Down Expand Up @@ -166,6 +166,9 @@ func TransportConfigurer(thisPeer peer.ID, storeGetter StoreGetter) datatransfer
log.Errorf("attempting to configure data store: %w", err)
return
}
if store == nil {
return
}
err = gsTransport.UseStore(channelID, store.Loader, store.Storer)
if err != nil {
log.Errorf("attempting to configure data store: %w", err)
Expand Down
21 changes: 18 additions & 3 deletions retrievalmarket/impl/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/filecoin-project/go-address"
dtimpl "github.com/filecoin-project/go-data-transfer/impl"
dtgstransport "github.com/filecoin-project/go-data-transfer/transport/graphsync"
"github.com/filecoin-project/go-multistore"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/abi/big"
"github.com/filecoin-project/specs-actors/actors/builtin/paych"
Expand Down Expand Up @@ -167,6 +168,7 @@ func TestClientCanMakeDealWithProvider(t *testing.T) {
selector ipld.Node
unsealPrice abi.TokenAmount
paramsV1, addFunds bool
skipStores bool
}{
{name: "1 block file retrieval succeeds with existing payment channel",
filename: "lorem_under_1_block.txt",
Expand Down Expand Up @@ -213,6 +215,12 @@ func TestClientCanMakeDealWithProvider(t *testing.T) {
filesize: 410,
voucherAmts: []abi.TokenAmount{abi.NewTokenAmount(410000)},
},
{name: "succeeds for regular blockstore",
filename: "lorem.txt",
filesize: 19000,
voucherAmts: []abi.TokenAmount{abi.NewTokenAmount(10136000), abi.NewTokenAmount(9784000)},
skipStores: true,
},
}

for i, testCase := range testCases {
Expand Down Expand Up @@ -358,8 +366,11 @@ CurrentInterval: %d
rmParams = retrievalmarket.NewParamsV0(pricePerByte, paymentInterval, paymentIntervalIncrease)
}

clientStoreID := testData.MultiStore1.Next()

var clientStoreID *multistore.StoreID
if !testCase.skipStores {
id := testData.MultiStore1.Next()
clientStoreID = &id
}
// *** Retrieve the piece
did, err := client.Retrieve(bgCtx, payloadCID, rmParams, expectedTotal, retrievalPeer.ID, clientPaymentChannel, retrievalPeer.Address, clientStoreID)
assert.Equal(t, did, retrievalmarket.DealID(0))
Expand Down Expand Up @@ -403,7 +414,11 @@ CurrentInterval: %d
}
// verify that the provider saved the same voucher values
providerNode.VerifyExpectations(t)
testData.VerifyFileTransferredIntoStore(t, pieceLink, clientStoreID, false, testCase.filesize)
if testCase.skipStores {
testData.VerifyFileTransferred(t, pieceLink, false, testCase.filesize)
} else {
testData.VerifyFileTransferredIntoStore(t, pieceLink, *clientStoreID, false, testCase.filesize)
}
})
}

Expand Down
2 changes: 1 addition & 1 deletion retrievalmarket/storage_retrieval_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func TestStorageRetrieval(t *testing.T) {
// *** Retrieve the piece

clientStoreID := sh.TestData.MultiStore1.Next()
did, err := rh.Client.Retrieve(bgCtx, sh.PayloadCid, rmParams, expectedTotal, retrievalPeer.ID, *rh.ExpPaych, retrievalPeer.Address, clientStoreID)
did, err := rh.Client.Retrieve(bgCtx, sh.PayloadCid, rmParams, expectedTotal, retrievalPeer.ID, *rh.ExpPaych, retrievalPeer.Address, &clientStoreID)
assert.Equal(t, did, retrievalmarket.DealID(0))
require.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion retrievalmarket/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type PaymentInfo struct {
// of a retrieval client
type ClientDealState struct {
DealProposal
StoreID multistore.StoreID
StoreID *multistore.StoreID
ChannelID datatransfer.ChannelID
LastPaymentRequested bool
AllBlocksReceived bool
Expand Down
30 changes: 24 additions & 6 deletions retrievalmarket/types_cbor_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cf6b0a7

Please sign in to comment.