Skip to content

Commit

Permalink
feat(deps): update go-graphsync v0.8.0
Browse files Browse the repository at this point in the history
Update to go-graphsync v0.8.0 with go-ipld-prime linksystem branch & trusted store.
  • Loading branch information
hannahhoward committed Jun 1, 2021
1 parent 5b6d12f commit ff91033
Show file tree
Hide file tree
Showing 20 changed files with 190 additions and 147 deletions.
20 changes: 11 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ require (
github.com/filecoin-project/go-address v0.0.3
github.com/filecoin-project/go-cbor-util v0.0.0-20191219014500-08c40a1e63a2
github.com/filecoin-project/go-commp-utils v0.0.0-20201119054358-b88f7a96a434
github.com/filecoin-project/go-data-transfer v1.5.0
github.com/filecoin-project/go-data-transfer v1.1.1-0.20210601184249-6ea84a31d226
github.com/filecoin-project/go-ds-versioning v0.1.0
github.com/filecoin-project/go-multistore v0.0.3
github.com/filecoin-project/go-multistore v0.0.4-0.20210601185713-428a2691a567
github.com/filecoin-project/go-padreader v0.0.0-20200903213702-ed5fae088b20
github.com/filecoin-project/go-state-types v0.0.0-20201102161440-c8033295a1fc
github.com/filecoin-project/go-statemachine v0.0.0-20200925024713-05bd7c71fbfe
Expand All @@ -17,11 +17,11 @@ require (
github.com/filecoin-project/specs-actors/v2 v2.3.2
github.com/hannahhoward/cbor-gen-for v0.0.0-20200817222906-ea96cece81f1
github.com/hannahhoward/go-pubsub v0.0.0-20200423002714-8d62886cc36e
github.com/ipfs/go-block-format v0.0.2
github.com/ipfs/go-block-format v0.0.3
github.com/ipfs/go-blockservice v0.1.4-0.20200624145336-a978cec6e834
github.com/ipfs/go-cid v0.0.7
github.com/ipfs/go-datastore v0.4.5
github.com/ipfs/go-graphsync v0.6.1
github.com/ipfs/go-graphsync v0.8.0
github.com/ipfs/go-ipfs-blockstore v1.0.3
github.com/ipfs/go-ipfs-blocksutil v0.0.1
github.com/ipfs/go-ipfs-chunker v0.0.5
Expand All @@ -32,15 +32,17 @@ require (
github.com/ipfs/go-log/v2 v2.1.2-0.20200626104915-0016c0b4b3e4
github.com/ipfs/go-merkledag v0.3.2
github.com/ipfs/go-unixfs v0.2.4
github.com/ipld/go-car v0.1.1-0.20201119040415-11b6074b6d4d
github.com/ipld/go-ipld-prime v0.5.1-0.20201021195245-109253e8a018
github.com/ipld/go-car v0.3.1-0.20210601190600-f512dac51e8e
github.com/ipld/go-ipld-prime v0.9.1-0.20210324083106-dc342a9917db
github.com/jbenet/go-random v0.0.0-20190219211222-123a90aedc0c
github.com/jpillora/backoff v1.0.0
github.com/libp2p/go-libp2p v0.12.0
github.com/libp2p/go-libp2p-core v0.7.0
github.com/libp2p/go-libp2p v0.13.0
github.com/libp2p/go-libp2p-core v0.8.5
github.com/minio/sha256-simd v1.0.0
github.com/multiformats/go-multiaddr v0.3.1
github.com/multiformats/go-multibase v0.0.3
github.com/stretchr/testify v1.6.1
github.com/multiformats/go-multihash v0.0.15
github.com/stretchr/testify v1.7.0
github.com/whyrusleeping/cbor-gen v0.0.0-20210219115102-f37d292932f2
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd
golang.org/x/net v0.0.0-20201021035429-f5854403a974
Expand Down
131 changes: 91 additions & 40 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion retrievalmarket/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
func DecodeNode(defnode *cbg.Deferred) (ipld.Node, error) {
reader := bytes.NewReader(defnode.Raw)
nb := basicnode.Prototype.Any.NewBuilder()
err := dagcbor.Decoder(nb, reader)
err := dagcbor.Decode(nb, reader)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion retrievalmarket/impl/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ func TestMigrations(t *testing.T) {
selfPeer := tut.GeneratePeers(1)[0]

allSelectorBuf := new(bytes.Buffer)
err = dagcbor.Encoder(shared.AllSelector(), allSelectorBuf)
err = dagcbor.Encode(shared.AllSelector(), allSelectorBuf)
require.NoError(t, err)
allSelectorBytes := allSelectorBuf.Bytes()

Expand Down
4 changes: 2 additions & 2 deletions retrievalmarket/impl/dtutils/dtutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ type StoreGetter interface {
// StoreConfigurableTransport defines the methods needed to
// configure a data transfer transport use a unique store for a given request
type StoreConfigurableTransport interface {
UseStore(datatransfer.ChannelID, ipld.Loader, ipld.Storer) error
UseStore(datatransfer.ChannelID, ipld.LinkSystem) error
}

// TransportConfigurer configurers the graphsync transport to use a custom blockstore per deal
Expand All @@ -185,7 +185,7 @@ func TransportConfigurer(thisPeer peer.ID, storeGetter StoreGetter) datatransfer
if store == nil {
return
}
err = gsTransport.UseStore(channelID, store.Loader, store.Storer)
err = gsTransport.UseStore(channelID, store.LinkSystem)
if err != nil {
log.Errorf("attempting to configure data store: %w", err)
}
Expand Down
12 changes: 5 additions & 7 deletions retrievalmarket/impl/dtutils/dtutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,16 +493,14 @@ func (ft *fakeTransport) Shutdown(context.Context) error {

type fakeGsTransport struct {
datatransfer.Transport
lastChannelID datatransfer.ChannelID
lastLoader ipld.Loader
lastStorer ipld.Storer
called bool
lastChannelID datatransfer.ChannelID
lastLinkSystem ipld.LinkSystem
called bool
}

func (fgt *fakeGsTransport) UseStore(channelID datatransfer.ChannelID, loader ipld.Loader, storer ipld.Storer) error {
func (fgt *fakeGsTransport) UseStore(channelID datatransfer.ChannelID, lsys ipld.LinkSystem) error {
fgt.lastChannelID = channelID
fgt.lastLoader = loader
fgt.lastStorer = storer
fgt.lastLinkSystem = lsys
fgt.called = true
return nil
}
8 changes: 4 additions & 4 deletions retrievalmarket/impl/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func requireSetupTestClientAndProvider(ctx context.Context, t *testing.T, payChA
AddFundsCID: cids[1],
})

gs1 := graphsyncimpl.New(ctx, network.NewFromLibp2pHost(testData.Host1), testData.Loader1, testData.Storer1)
gs1 := graphsyncimpl.New(ctx, network.NewFromLibp2pHost(testData.Host1), testData.LinkSystem1)
dtTransport1 := dtgstransport.NewTransport(testData.Host1.ID(), gs1)
dt1, err := dtimpl.NewDataTransfer(testData.DTStore1, testData.DTTmpDir1, testData.DTNet1, dtTransport1)
require.NoError(t, err)
Expand Down Expand Up @@ -141,7 +141,7 @@ func requireSetupTestClientAndProvider(ctx context.Context, t *testing.T, payChA

paymentAddress := address.TestAddress2

gs2 := graphsyncimpl.New(ctx, network.NewFromLibp2pHost(testData.Host2), testData.Loader2, testData.Storer2)
gs2 := graphsyncimpl.New(ctx, network.NewFromLibp2pHost(testData.Host2), testData.LinkSystem2)
dtTransport2 := dtgstransport.NewTransport(testData.Host2.ID(), gs2)
dt2, err := dtimpl.NewDataTransfer(testData.DTStore2, testData.DTTmpDir2, testData.DTNet2, dtTransport2)
require.NoError(t, err)
Expand Down Expand Up @@ -615,7 +615,7 @@ func setupClient(
ChannelAvailableFunds: channelAvailableFunds,
})

gs1 := graphsyncimpl.New(ctx, network.NewFromLibp2pHost(testData.Host1), testData.Loader1, testData.Storer1)
gs1 := graphsyncimpl.New(ctx, network.NewFromLibp2pHost(testData.Host1), testData.LinkSystem1)
dtTransport1 := dtgstransport.NewTransport(testData.Host1.ID(), gs1)
dt1, err := dtimpl.NewDataTransfer(testData.DTStore1, testData.DTTmpDir1, testData.DTNet1, dtTransport1)
require.NoError(t, err)
Expand Down Expand Up @@ -652,7 +652,7 @@ func setupProvider(
pieceStore.ExpectCID(payloadCID, cidInfo)
pieceStore.ExpectPiece(expectedPiece, pieceInfo)

gs2 := graphsyncimpl.New(ctx, network.NewFromLibp2pHost(testData.Host2), testData.Loader2, testData.Storer2)
gs2 := graphsyncimpl.New(ctx, network.NewFromLibp2pHost(testData.Host2), testData.LinkSystem2)
dtTransport2 := dtgstransport.NewTransport(testData.Host2.ID(), gs2)
dt2, err := dtimpl.NewDataTransfer(testData.DTStore2, testData.DTTmpDir2, testData.DTNet2, dtTransport2)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion retrievalmarket/impl/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ func TestProviderMigrations(t *testing.T) {
offsets := make([]abi.PaddedPieceSize, numDeals)
lengths := make([]abi.PaddedPieceSize, numDeals)
allSelectorBuf := new(bytes.Buffer)
err = dagcbor.Encoder(shared.AllSelector(), allSelectorBuf)
err = dagcbor.Encode(shared.AllSelector(), allSelectorBuf)
require.NoError(t, err)
allSelectorBytes := allSelectorBuf.Bytes()

Expand Down
4 changes: 2 additions & 2 deletions retrievalmarket/impl/requestvalidation/requestvalidation.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var allSelectorBytes []byte

func init() {
buf := new(bytes.Buffer)
_ = dagcbor.Encoder(shared.AllSelector(), buf)
_ = dagcbor.Encode(shared.AllSelector(), buf)
allSelectorBytes = buf.Bytes()
}

Expand Down Expand Up @@ -100,7 +100,7 @@ func (rv *ProviderRequestValidator) validatePull(isRestart bool, receiver peer.I

// Check the proposal selector matches
buf := new(bytes.Buffer)
err := dagcbor.Encoder(selector, buf)
err := dagcbor.Encode(selector, buf)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion retrievalmarket/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func NewParamsV1(pricePerByte abi.TokenAmount, paymentInterval uint64, paymentIn
return Params{}, xerrors.New("selector required for NewParamsV1")
}

err := dagcbor.Encoder(sel, &buffer)
err := dagcbor.Encode(sel, &buffer)
if err != nil {
return Params{}, xerrors.Errorf("error encoding selector: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion retrievalmarket/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestParamsMarshalUnmarshal(t *testing.T) {
assert.Equal(t, params, *unmarshalled)

nb := basicnode.Prototype.Any.NewBuilder()
err = dagcbor.Decoder(nb, bytes.NewBuffer(unmarshalled.Selector.Raw))
err = dagcbor.Decode(nb, bytes.NewBuffer(unmarshalled.Selector.Raw))
assert.NoError(t, err)
sel := nb.Build()
assert.Equal(t, sel, allSelector)
Expand Down
40 changes: 40 additions & 0 deletions shared_testutil/makecid.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package shared_testutil

import (
"errors"

"github.com/ipfs/go-cid"
"github.com/minio/sha256-simd"
mh "github.com/multiformats/go-multihash"

"github.com/filecoin-project/go-state-types/abi"
)

// make a cid directly with a given input and prefix
func MakeCID(input string, prefix *cid.Prefix) cid.Cid {
data := []byte(input)
if prefix == nil {
c, err := abi.CidBuilder.Sum(data)
if err != nil {
panic(err)
}
return c
}
c, err := prefix.Sum(data)
switch {
case errors.Is(err, mh.ErrSumNotSupported):
// multihash library doesn't support this hash function.
// just fake it.
case err == nil:
return c
default:
panic(err)
}

sum := sha256.Sum256(data)
hash, err := mh.Encode(sum[:], prefix.MhType)
if err != nil {
panic(err)
}
return cid.NewCidV1(prefix.Codec, hash)
}
50 changes: 7 additions & 43 deletions shared_testutil/mocknet.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package shared_testutil

import (
"bytes"
"errors"
"io"
"io/ioutil"
"os"
Expand All @@ -11,11 +10,11 @@ import (
"runtime"
"testing"

blocks "github.com/ipfs/go-block-format"
"github.com/ipfs/go-blockservice"
"github.com/ipfs/go-datastore"
"github.com/ipfs/go-datastore/namespace"
dss "github.com/ipfs/go-datastore/sync"
"github.com/ipfs/go-graphsync/storeutil"
bstore "github.com/ipfs/go-ipfs-blockstore"
chunk "github.com/ipfs/go-ipfs-chunker"
offline "github.com/ipfs/go-ipfs-exchange-offline"
Expand Down Expand Up @@ -52,10 +51,8 @@ type Libp2pTestData struct {
DTStore2 datastore.Batching
DTTmpDir1 string
DTTmpDir2 string
Loader1 ipld.Loader
Loader2 ipld.Loader
Storer1 ipld.Storer
Storer2 ipld.Storer
LinkSystem1 ipld.LinkSystem
LinkSystem2 ipld.LinkSystem
Host1 host.Host
Host2 host.Host
OrigBytes []byte
Expand All @@ -66,38 +63,7 @@ type Libp2pTestData struct {
func NewLibp2pTestData(ctx context.Context, t *testing.T) *Libp2pTestData {
testData := &Libp2pTestData{}
testData.Ctx = ctx
makeLoader := func(bs bstore.Blockstore) ipld.Loader {
return func(lnk ipld.Link, lnkCtx ipld.LinkContext) (io.Reader, error) {
c, ok := lnk.(cidlink.Link)
if !ok {
return nil, errors.New("incorrect Link Type")
}
// read block from one store
block, err := bs.Get(c.Cid)
if err != nil {
return nil, err
}
return bytes.NewReader(block.RawData()), nil
}
}

makeStorer := func(bs bstore.Blockstore) ipld.Storer {
return func(lnkCtx ipld.LinkContext) (io.Writer, ipld.StoreCommitter, error) {
var buf bytes.Buffer
var committer ipld.StoreCommitter = func(lnk ipld.Link) error {
c, ok := lnk.(cidlink.Link)
if !ok {
return errors.New("incorrect Link Type")
}
block, err := blocks.NewBlockWithCid(buf.Bytes(), c.Cid)
if err != nil {
return err
}
return bs.Put(block)
}
return &buf, committer, nil
}
}
var err error

testData.Ds1 = dss.MutexWrap(datastore.NewMapDatastore())
Expand All @@ -115,13 +81,11 @@ func NewLibp2pTestData(ctx context.Context, t *testing.T) *Libp2pTestData {
testData.DagService1 = merkledag.NewDAGService(blockservice.New(testData.Bs1, offline.Exchange(testData.Bs1)))
testData.DagService2 = merkledag.NewDAGService(blockservice.New(testData.Bs2, offline.Exchange(testData.Bs2)))

// setup an IPLD loader/storer for bstore 1
testData.Loader1 = makeLoader(testData.Bs1)
testData.Storer1 = makeStorer(testData.Bs1)
// setup an IPLD link system for bstore 1
testData.LinkSystem1 = storeutil.LinkSystemForBlockstore(testData.Bs1)

// setup an IPLD loader/storer for bstore 2
testData.Loader2 = makeLoader(testData.Bs2)
testData.Storer2 = makeStorer(testData.Bs2)
// setup an IPLD link system for bstore 2
testData.LinkSystem2 = storeutil.LinkSystemForBlockstore(testData.Bs2)

mn := mocknet.New(ctx)

Expand Down
31 changes: 11 additions & 20 deletions shared_testutil/test_ipld_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,21 @@ type TestIPLDTree struct {
func NewTestIPLDTree() TestIPLDTree {
var storage = make(map[ipld.Link][]byte)
encode := func(n ipld.Node) (ipld.Node, ipld.Link) {
lb := cidlink.LinkBuilder{Prefix: cid.Prefix{
lb := cidlink.LinkPrototype{Prefix: cid.Prefix{
Version: 1,
Codec: 0x0129,
MhType: 0x17,
MhType: 0x13,
MhLength: 4,
}}
lnk, err := lb.Build(context.Background(), ipld.LinkContext{}, n,
func(ipld.LinkContext) (io.Writer, ipld.StoreCommitter, error) {
buf := bytes.Buffer{}
return &buf, func(lnk ipld.Link) error {
storage[lnk] = buf.Bytes()
return nil
}, nil
},
)
lsys := cidlink.DefaultLinkSystem()
lsys.StorageWriteOpener = func(ipld.LinkContext) (io.Writer, ipld.BlockWriteCommitter, error) {
buf := bytes.Buffer{}
return &buf, func(lnk ipld.Link) error {
storage[lnk] = buf.Bytes()
return nil
}, nil
}
lnk, err := lsys.Store(ipld.LinkContext{}, lb, n)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -115,15 +115,6 @@ func NewTestIPLDTree() TestIPLDTree {
}
}

// Loader is an IPLD comptabile loader for the "storage" part of the tree
func (tt TestIPLDTree) Loader(lnk ipld.Link, lnkCtx ipld.LinkContext) (io.Reader, error) {
data, ok := tt.Storage[lnk]
if !ok {
return nil, errors.New("No block found")
}
return bytes.NewBuffer(data), nil
}

// Get makes a test tree behave like a block read store
func (tt TestIPLDTree) Get(c cid.Cid) (blocks.Block, error) {
data, ok := tt.Storage[cidlink.Link{Cid: c}]
Expand Down
4 changes: 2 additions & 2 deletions storagemarket/impl/dtutils/dtutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ type StoreGetter interface {
// StoreConfigurableTransport defines the methods needed to
// configure a data transfer transport use a unique store for a given request
type StoreConfigurableTransport interface {
UseStore(datatransfer.ChannelID, ipld.Loader, ipld.Storer) error
UseStore(datatransfer.ChannelID, ipld.LinkSystem) error
}

// TransportConfigurer configurers the graphsync transport to use a custom blockstore per deal
Expand All @@ -141,7 +141,7 @@ func TransportConfigurer(storeGetter StoreGetter) datatransfer.TransportConfigur
if store == nil {
return
}
err = gsTransport.UseStore(channelID, store.Loader, store.Storer)
err = gsTransport.UseStore(channelID, store.LinkSystem)
if err != nil {
log.Errorf("attempting to configure data store: %w", err)
}
Expand Down
Loading

0 comments on commit ff91033

Please sign in to comment.