Skip to content

Commit

Permalink
chore(retrievalmarket): remove old types
Browse files Browse the repository at this point in the history
  • Loading branch information
hannahhoward committed May 12, 2022
1 parent a7d62b8 commit 58940d3
Show file tree
Hide file tree
Showing 19 changed files with 128 additions and 2,604 deletions.
59 changes: 0 additions & 59 deletions discovery/impl/local_test.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
package discoveryimpl_test

import (
"bytes"
"context"
"testing"
"time"

"github.com/ipfs/go-datastore"
dshelp "github.com/ipfs/go-ipfs-ds-help"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/filecoin-project/go-address"
specst "github.com/filecoin-project/specs-actors/v8/support/testing"

discoveryimpl "github.com/filecoin-project/go-fil-markets/discovery/impl"
"github.com/filecoin-project/go-fil-markets/discovery/migrations"
"github.com/filecoin-project/go-fil-markets/retrievalmarket"
retrievalmigrations "github.com/filecoin-project/go-fil-markets/retrievalmarket/migrations"
"github.com/filecoin-project/go-fil-markets/shared_testutil"
)

Expand Down Expand Up @@ -71,57 +66,3 @@ func TestLocal_AddPeer(t *testing.T) {
})
}
}

func TestLocalMigrations(t *testing.T) {
ctx := context.Background()
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
ds := datastore.NewMapDatastore()

peers := shared_testutil.GeneratePeers(4)
pieceCIDs := shared_testutil.GenerateCids(4)
payloadCids := shared_testutil.GenerateCids(2)
for i, c := range payloadCids {
rps := migrations.RetrievalPeers0{
Peers: []retrievalmigrations.RetrievalPeer0{
{
Address: address.TestAddress,
ID: peers[i*2],
PieceCID: &pieceCIDs[i*2],
},
{
Address: address.TestAddress2,
ID: peers[i*2+1],
PieceCID: &pieceCIDs[i*2+1],
},
},
}
buf := new(bytes.Buffer)
err := rps.MarshalCBOR(buf)
require.NoError(t, err)
err = ds.Put(ctx, dshelp.MultihashToDsKey(c.Hash()), buf.Bytes())
require.NoError(t, err)
}

l, err := discoveryimpl.NewLocal(ds)
require.NoError(t, err)
shared_testutil.StartAndWaitForReady(ctx, t, l)

for i, c := range payloadCids {
expectedPeers := []retrievalmarket.RetrievalPeer{
{
Address: address.TestAddress,
ID: peers[i*2],
PieceCID: &pieceCIDs[i*2],
},
{
Address: address.TestAddress2,
ID: peers[i*2+1],
PieceCID: &pieceCIDs[i*2+1],
},
}
peers, err := l.GetPeers(c)
require.NoError(t, err)
require.Equal(t, expectedPeers, peers)
}
}
31 changes: 1 addition & 30 deletions discovery/migrations/migrations.go
Original file line number Diff line number Diff line change
@@ -1,37 +1,8 @@
package migrations

import (
versioning "github.com/filecoin-project/go-ds-versioning/pkg"
"github.com/filecoin-project/go-ds-versioning/pkg/versioned"

"github.com/filecoin-project/go-fil-markets/discovery"
"github.com/filecoin-project/go-fil-markets/retrievalmarket"
"github.com/filecoin-project/go-fil-markets/retrievalmarket/migrations"
)

//go:generate cbor-gen-for RetrievalPeers0

// RetrievalPeers0 is version 0 of RetrievalPeers
type RetrievalPeers0 struct {
Peers []migrations.RetrievalPeer0
}

// MigrateRetrievalPeers0To1 migrates a tuple encoded list of retrieval peers to a map encoded list
func MigrateRetrievalPeers0To1(oldRps *RetrievalPeers0) (*discovery.RetrievalPeers, error) {
peers := make([]retrievalmarket.RetrievalPeer, 0, len(oldRps.Peers))
for _, oldRp := range oldRps.Peers {
peers = append(peers, retrievalmarket.RetrievalPeer{
Address: oldRp.Address,
ID: oldRp.ID,
PieceCID: oldRp.PieceCID,
})
}
return &discovery.RetrievalPeers{
Peers: peers,
}, nil
}

// RetrievalPeersMigrations are migrations for the store local discovery list of peers we can retrieve from
var RetrievalPeersMigrations = versioned.BuilderList{
versioned.NewVersionedBuilder(MigrateRetrievalPeers0To1, versioning.VersionKey("1")),
}
var RetrievalPeersMigrations = versioned.BuilderList{}
99 changes: 0 additions & 99 deletions discovery/migrations/migrations_cbor_gen.go

This file was deleted.

27 changes: 0 additions & 27 deletions retrievalmarket/impl/askstore/askstore_impl_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package askstore_test

import (
"bytes"
"context"
"math/rand"
"testing"

"github.com/ipfs/go-datastore"
Expand All @@ -14,7 +11,6 @@ import (

"github.com/filecoin-project/go-fil-markets/retrievalmarket"
"github.com/filecoin-project/go-fil-markets/retrievalmarket/impl/askstore"
"github.com/filecoin-project/go-fil-markets/retrievalmarket/migrations"
)

func TestAskStoreImpl(t *testing.T) {
Expand Down Expand Up @@ -51,26 +47,3 @@ func TestAskStoreImpl(t *testing.T) {
stored = newStore.GetAsk()
require.Equal(t, newAsk, stored)
}
func TestMigrations(t *testing.T) {
ds := dss.MutexWrap(datastore.NewMapDatastore())
oldAsk := &migrations.Ask0{
PricePerByte: abi.NewTokenAmount(rand.Int63()),
UnsealPrice: abi.NewTokenAmount(rand.Int63()),
PaymentInterval: rand.Uint64(),
PaymentIntervalIncrease: rand.Uint64(),
}
buf := new(bytes.Buffer)
err := oldAsk.MarshalCBOR(buf)
require.NoError(t, err)
ds.Put(context.TODO(), datastore.NewKey("retrieval-ask"), buf.Bytes())
newStore, err := askstore.NewAskStore(ds, datastore.NewKey("retrieval-ask"))
require.NoError(t, err)
ask := newStore.GetAsk()
expectedAsk := &retrievalmarket.Ask{
PricePerByte: oldAsk.PricePerByte,
UnsealPrice: oldAsk.UnsealPrice,
PaymentInterval: oldAsk.PaymentInterval,
PaymentIntervalIncrease: oldAsk.PaymentIntervalIncrease,
}
require.Equal(t, expectedAsk, ask)
}
44 changes: 4 additions & 40 deletions retrievalmarket/impl/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

"github.com/filecoin-project/go-address"
datatransfer "github.com/filecoin-project/go-data-transfer/v2"
versioning "github.com/filecoin-project/go-ds-versioning/pkg"
versionedfsm "github.com/filecoin-project/go-ds-versioning/pkg/fsm"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
Expand Down Expand Up @@ -103,44 +104,28 @@ func NewClient(
StateEntryFuncs: clientstates.ClientStateEntryFuncs,
FinalityStates: clientstates.ClientFinalityStates,
Notifier: c.notifySubscribers,
}, retrievalMigrations, "2")
}, retrievalMigrations, versioning.VersionKey("2"))
if err != nil {
return nil, err
}
err = dataTransfer.RegisterVoucherResultType(&retrievalmarket.DealResponse{})
if err != nil {
return nil, err
}
err = dataTransfer.RegisterVoucherResultType(&migrations.DealResponse0{})
if err != nil {
return nil, err
}
err = dataTransfer.RegisterVoucherType(&retrievalmarket.DealProposal{}, nil)
if err != nil {
return nil, err
}
err = dataTransfer.RegisterVoucherType(&migrations.DealProposal0{}, nil)
if err != nil {
return nil, err
}
err = dataTransfer.RegisterVoucherType(&retrievalmarket.DealPayment{}, nil)
if err != nil {
return nil, err
}
err = dataTransfer.RegisterVoucherType(&migrations.DealPayment0{}, nil)
if err != nil {
return nil, err
}
dataTransfer.SubscribeToEvents(dtutils.ClientDataTransferSubscriber(c.stateMachines))
transportConfigurer := dtutils.TransportConfigurer(network.ID(), &clientStoreGetter{c})
err = dataTransfer.RegisterTransportConfigurer(&retrievalmarket.DealProposal{}, transportConfigurer)
if err != nil {
return nil, err
}
err = dataTransfer.RegisterTransportConfigurer(&migrations.DealProposal0{}, transportConfigurer)
if err != nil {
return nil, err
}
return c, nil
}

Expand Down Expand Up @@ -418,7 +403,7 @@ func (c *clientDealEnvironment) Node() retrievalmarket.RetrievalClientNode {
return c.c.node
}

func (c *clientDealEnvironment) OpenDataTransfer(ctx context.Context, to peer.ID, proposal *retrievalmarket.DealProposal, legacy bool) (datatransfer.ChannelID, error) {
func (c *clientDealEnvironment) OpenDataTransfer(ctx context.Context, to peer.ID, proposal *retrievalmarket.DealProposal) (datatransfer.ChannelID, error) {
sel := selectorparse.CommonSelector_ExploreAllRecursively
if proposal.SelectorSpecified() {
var err error
Expand All @@ -429,32 +414,11 @@ func (c *clientDealEnvironment) OpenDataTransfer(ctx context.Context, to peer.ID
}

var vouch datatransfer.Voucher = proposal
if legacy {
vouch = &migrations.DealProposal0{
PayloadCID: proposal.PayloadCID,
ID: proposal.ID,
Params0: migrations.Params0{
Selector: proposal.Selector,
PieceCID: proposal.PieceCID,
PricePerByte: proposal.PricePerByte,
PaymentInterval: proposal.PaymentInterval,
PaymentIntervalIncrease: proposal.PaymentIntervalIncrease,
UnsealPrice: proposal.UnsealPrice,
},
}
}
return c.c.dataTransfer.OpenPullDataChannel(ctx, to, vouch, proposal.PayloadCID, sel)
}

func (c *clientDealEnvironment) SendDataTransferVoucher(ctx context.Context, channelID datatransfer.ChannelID, payment *retrievalmarket.DealPayment, legacy bool) error {
func (c *clientDealEnvironment) SendDataTransferVoucher(ctx context.Context, channelID datatransfer.ChannelID, payment *retrievalmarket.DealPayment) error {
var vouch datatransfer.Voucher = payment
if legacy {
vouch = &migrations.DealPayment0{
ID: payment.ID,
PaymentChannel: payment.PaymentChannel,
PaymentVoucher: payment.PaymentVoucher,
}
}
return c.c.dataTransfer.SendVoucher(ctx, channelID, vouch)
}

Expand Down
Loading

0 comments on commit 58940d3

Please sign in to comment.