Skip to content

Commit c0cd272

Browse files
gammazerorvagg
authored andcommitted
upgrade go-graphsync and other dependencies
- replace test code with equivalents from ipfs/go-test
1 parent d6b2dac commit c0cd272

36 files changed

+629
-658
lines changed

benchmarks/benchmark_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ import (
1414
"testing"
1515
"time"
1616

17-
"github.com/ipfs/go-blockservice"
17+
"github.com/ipfs/boxo/blockservice"
18+
blockstore "github.com/ipfs/boxo/blockstore"
19+
chunker "github.com/ipfs/boxo/chunker"
20+
offline "github.com/ipfs/boxo/exchange/offline"
21+
files "github.com/ipfs/boxo/files"
22+
"github.com/ipfs/boxo/ipld/merkledag"
23+
"github.com/ipfs/boxo/ipld/unixfs/importer/balanced"
24+
ihelper "github.com/ipfs/boxo/ipld/unixfs/importer/helpers"
1825
"github.com/ipfs/go-cid"
19-
blockstore "github.com/ipfs/go-ipfs-blockstore"
20-
chunker "github.com/ipfs/go-ipfs-chunker"
21-
offline "github.com/ipfs/go-ipfs-exchange-offline"
22-
files "github.com/ipfs/go-ipfs-files"
2326
ipldformat "github.com/ipfs/go-ipld-format"
24-
"github.com/ipfs/go-merkledag"
25-
"github.com/ipfs/go-unixfs/importer/balanced"
26-
ihelper "github.com/ipfs/go-unixfs/importer/helpers"
2727
basicnode "github.com/ipld/go-ipld-prime/node/basic"
2828
ipldselector "github.com/ipld/go-ipld-prime/traversal/selector"
2929
"github.com/ipld/go-ipld-prime/traversal/selector/builder"

benchmarks/testinstance/testinstance.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"time"
66

7+
blockstore "github.com/ipfs/boxo/blockstore"
78
"github.com/ipfs/go-datastore"
89
ds "github.com/ipfs/go-datastore"
910
"github.com/ipfs/go-datastore/delayed"
@@ -13,7 +14,6 @@ import (
1314
graphsync "github.com/ipfs/go-graphsync"
1415
gsimpl "github.com/ipfs/go-graphsync/impl"
1516
"github.com/ipfs/go-graphsync/storeutil"
16-
blockstore "github.com/ipfs/go-ipfs-blockstore"
1717
delay "github.com/ipfs/go-ipfs-delay"
1818
"github.com/ipld/go-ipld-prime"
1919
peer "github.com/libp2p/go-libp2p/core/peer"

channelmonitor/channelmonitor.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/bep/debounce"
1010
logging "github.com/ipfs/go-log/v2"
1111
"github.com/libp2p/go-libp2p/core/peer"
12-
"golang.org/x/xerrors"
1312

1413
datatransfer "github.com/filecoin-project/go-data-transfer/v2"
1514
"github.com/filecoin-project/go-data-transfer/v2/channels"
@@ -272,12 +271,12 @@ func (mc *monitoredChannel) start() {
272271
case datatransfer.SendDataError:
273272
// If the transport layer reports an error sending data over the wire,
274273
// attempt to restart the channel
275-
err := xerrors.Errorf("%s: data transfer transport send error, restarting data transfer", mc.chid)
274+
err := fmt.Errorf("%s: data transfer transport send error, restarting data transfer", mc.chid)
276275
go mc.restartChannelDebounced(err)
277276
case datatransfer.ReceiveDataError:
278277
// If the transport layer reports an error receiving data over the wire,
279278
// attempt to restart the channel
280-
err := xerrors.Errorf("%s: data transfer transport receive error, restarting data transfer", mc.chid)
279+
err := fmt.Errorf("%s: data transfer transport receive error, restarting data transfer", mc.chid)
281280
go mc.restartChannelDebounced(err)
282281
case datatransfer.FinishTransfer:
283282
// The channel initiator has finished sending / receiving all data.
@@ -312,7 +311,7 @@ func (mc *monitoredChannel) watchForResponderAccept() func() {
312311
case <-timer.C:
313312
// Timer expired before we received an Accept from the responder,
314313
// fail the data transfer
315-
err := xerrors.Errorf("%s: timed out waiting %s for Accept message from remote peer",
314+
err := fmt.Errorf("%s: timed out waiting %s for Accept message from remote peer",
316315
mc.chid, mc.cfg.AcceptTimeout)
317316
mc.closeChannelAndShutdown(err)
318317
}
@@ -338,7 +337,7 @@ func (mc *monitoredChannel) watchForResponderComplete() {
338337
// its context is cancelled
339338
case <-timer.C:
340339
// Timer expired before we received a Complete message from the responder
341-
err := xerrors.Errorf("%s: timed out waiting %s for Complete message from remote peer",
340+
err := fmt.Errorf("%s: timed out waiting %s for Complete message from remote peer",
342341
mc.chid, mc.cfg.CompleteTimeout)
343342
mc.closeChannelAndShutdown(err)
344343
}
@@ -437,7 +436,7 @@ func (mc *monitoredChannel) doRestartChannel() error {
437436
if uint32(restartCount) > mc.cfg.MaxConsecutiveRestarts {
438437
// If no data has been transferred since the last restart, and we've
439438
// reached the consecutive restart limit, return an error
440-
return xerrors.Errorf("%s: after %d consecutive restarts failed to transfer any data", mc.chid, restartCount)
439+
return fmt.Errorf("%s: after %d consecutive restarts failed to transfer any data", mc.chid, restartCount)
441440
}
442441

443442
// Send the restart message
@@ -462,7 +461,7 @@ func (mc *monitoredChannel) sendRestartMessage(restartCount int) error {
462461
start := time.Now()
463462
err := mc.mgr.ConnectTo(mc.ctx, p)
464463
if err != nil {
465-
return xerrors.Errorf("%s: failed to reconnect to peer %s after %s: %w",
464+
return fmt.Errorf("%s: failed to reconnect to peer %s after %s: %w",
466465
mc.chid, p, time.Since(start), err)
467466
}
468467
log.Debugf("%s: re-established connection to %s in %s", mc.chid, p, time.Since(start))
@@ -471,7 +470,7 @@ func (mc *monitoredChannel) sendRestartMessage(restartCount int) error {
471470
log.Debugf("%s: sending restart message to %s (%d consecutive restarts)", mc.chid, p, restartCount)
472471
err = mc.mgr.RestartDataTransferChannel(mc.ctx, mc.chid)
473472
if err != nil {
474-
return xerrors.Errorf("%s: failed to send restart message to %s: %w", mc.chid, p, err)
473+
return fmt.Errorf("%s: failed to send restart message to %s: %w", mc.chid, p, err)
475474
}
476475

477476
// The restart message was sent successfully.

channelmonitor/channelmonitor_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ package channelmonitor
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"sync"
78
"testing"
89
"time"
910

1011
"github.com/libp2p/go-libp2p/core/peer"
1112
"github.com/stretchr/testify/require"
12-
"golang.org/x/xerrors"
1313

1414
datatransfer "github.com/filecoin-project/go-data-transfer/v2"
1515
"github.com/filecoin-project/go-data-transfer/v2/testutil"
@@ -191,7 +191,7 @@ func awaitRestartComplete(mch *monitoredChannel) error {
191191
}
192192
time.Sleep(time.Millisecond)
193193
}
194-
return xerrors.Errorf("restart did not complete after 10ms")
194+
return errors.New("restart did not complete after 10ms")
195195
}
196196

197197
func TestChannelMonitorQueuedRestart(t *testing.T) {
@@ -416,7 +416,7 @@ func (m *mockMonitorAPI) fireEvent(e datatransfer.Event, state datatransfer.Chan
416416

417417
func (m *mockMonitorAPI) ConnectTo(ctx context.Context, id peer.ID) error {
418418
if m.connectErrors {
419-
return xerrors.Errorf("connect err")
419+
return errors.New("connect err")
420420
}
421421
return nil
422422
}
@@ -431,7 +431,7 @@ func (m *mockMonitorAPI) RestartDataTransferChannel(ctx context.Context, chid da
431431
}()
432432

433433
if m.restartErrors {
434-
return xerrors.Errorf("restart err")
434+
return errors.New("restart err")
435435
}
436436
return nil
437437
}
@@ -440,7 +440,7 @@ func (m *mockMonitorAPI) awaitRestartSent() error {
440440
timeout := 100 * time.Millisecond
441441
select {
442442
case <-time.After(timeout):
443-
return xerrors.Errorf("failed to restart channel after %s", timeout)
443+
return fmt.Errorf("failed to restart channel after %s", timeout)
444444
case <-m.restartMessages:
445445
return nil
446446
}

channels/channels.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ package channels
33
import (
44
"context"
55
"errors"
6+
"fmt"
67
"time"
78

89
"github.com/ipfs/go-cid"
910
"github.com/ipfs/go-datastore"
1011
"github.com/ipld/go-ipld-prime/datamodel"
1112
peer "github.com/libp2p/go-libp2p/core/peer"
12-
"golang.org/x/xerrors"
1313

1414
versioning "github.com/filecoin-project/go-ds-versioning/pkg"
1515
versionedfsm "github.com/filecoin-project/go-ds-versioning/pkg/fsm"
@@ -134,8 +134,10 @@ func (c *Channels) CreateNew(selfPeer peer.ID, tid datatransfer.TransferID, base
134134
Stages: &datatransfer.ChannelStages{},
135135
Vouchers: []internal.EncodedVoucher{
136136
{
137-
Type: voucher.Type,
138-
Voucher: internal.CborGenCompatibleNode{voucher.Voucher},
137+
Type: voucher.Type,
138+
Voucher: internal.CborGenCompatibleNode{
139+
Node: voucher.Voucher,
140+
},
139141
},
140142
},
141143
Status: datatransfer.Requested,
@@ -456,7 +458,7 @@ func (c *Channels) checkChannelExists(chid datatransfer.ChannelID, code datatran
456458
return err
457459
}
458460
if !has {
459-
return xerrors.Errorf("cannot send FSM event %s to data-transfer channel %s: %w",
461+
return fmt.Errorf("cannot send FSM event %s to data-transfer channel %s: %w",
460462
datatransfer.Events[code], chid, NewErrNotFound(chid))
461463
}
462464
return nil

channels/channels_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import (
1111
"github.com/ipfs/go-cid"
1212
"github.com/ipfs/go-datastore"
1313
dss "github.com/ipfs/go-datastore/sync"
14+
"github.com/ipfs/go-test/random"
1415
basicnode "github.com/ipld/go-ipld-prime/node/basic"
1516
"github.com/ipld/go-ipld-prime/traversal/selector/builder"
1617
peer "github.com/libp2p/go-libp2p/core/peer"
1718
"github.com/stretchr/testify/require"
18-
"golang.org/x/xerrors"
1919

2020
versioning "github.com/filecoin-project/go-ds-versioning/pkg"
2121
versionedds "github.com/filecoin-project/go-ds-versioning/pkg/datastore"
@@ -41,9 +41,9 @@ func TestChannels(t *testing.T) {
4141
tid2 := datatransfer.TransferID(1)
4242
fv1 := testutil.NewTestTypedVoucher()
4343
fv2 := testutil.NewTestTypedVoucher()
44-
cids := testutil.GenerateCids(4)
44+
cids := random.Cids(4)
4545
selector := builder.NewSelectorSpecBuilder(basicnode.Prototype.Any).Matcher().Node()
46-
peers := testutil.GeneratePeers(4)
46+
peers := random.Peers(4)
4747

4848
channelList, err := channels.New(ds, notifier, &fakeEnv{}, peers[0])
4949
require.NoError(t, err)
@@ -97,7 +97,7 @@ func TestChannels(t *testing.T) {
9797
// empty if channel does not exist
9898
state, err = channelList.GetByID(ctx, datatransfer.ChannelID{Initiator: peers[1], Responder: peers[1], ID: tid1})
9999
require.Equal(t, nil, state)
100-
require.True(t, xerrors.As(err, new(*channels.ErrNotFound)))
100+
require.True(t, errors.As(err, new(*channels.ErrNotFound)))
101101

102102
// works for other channel as well
103103
state, err = channelList.GetByID(ctx, datatransfer.ChannelID{Initiator: peers[3], Responder: peers[2], ID: tid2})
@@ -117,7 +117,7 @@ func TestChannels(t *testing.T) {
117117
require.Equal(t, state.Status(), datatransfer.Queued)
118118

119119
err = channelList.Accept(datatransfer.ChannelID{Initiator: peers[1], Responder: peers[0], ID: tid1})
120-
require.True(t, xerrors.As(err, new(*channels.ErrNotFound)))
120+
require.True(t, errors.As(err, new(*channels.ErrNotFound)))
121121
})
122122

123123
t.Run("transfer initiated", func(t *testing.T) {
@@ -207,9 +207,9 @@ func TestChannels(t *testing.T) {
207207

208208
// errors if channel does not exist
209209
err = channelList.DataReceived(datatransfer.ChannelID{Initiator: peers[1], Responder: peers[0], ID: tid1}, cids[1], 200, 2, true)
210-
require.True(t, xerrors.As(err, new(*channels.ErrNotFound)))
210+
require.True(t, errors.As(err, new(*channels.ErrNotFound)))
211211
err = channelList.DataSent(datatransfer.ChannelID{Initiator: peers[1], Responder: peers[0], ID: tid1}, cids[1], 200, 2, true)
212-
require.True(t, xerrors.As(err, new(*channels.ErrNotFound)))
212+
require.True(t, errors.As(err, new(*channels.ErrNotFound)))
213213

214214
err = channelList.DataReceived(datatransfer.ChannelID{Initiator: peers[0], Responder: peers[1], ID: tid1}, cids[1], 50, 2, true)
215215
require.NoError(t, err)
@@ -435,15 +435,15 @@ func TestChannels(t *testing.T) {
435435
state := checkEvent(ctx, t, received, datatransfer.Open)
436436
require.Equal(t, datatransfer.Requested, state.Status())
437437

438-
disconnectErr := xerrors.Errorf("disconnected")
438+
disconnectErr := errors.New("disconnected")
439439
err = channelList.Disconnected(chid, disconnectErr)
440440
require.NoError(t, err)
441441
state = checkEvent(ctx, t, received, datatransfer.Disconnected)
442442
require.Equal(t, disconnectErr.Error(), state.Message())
443443
})
444444

445445
t.Run("test self peer and other peer", func(t *testing.T) {
446-
peers := testutil.GeneratePeers(3)
446+
peers := random.Peers(3)
447447
// sender is self peer
448448
chid, err := channelList.CreateNew(peers[1], tid1, cids[0], selector, fv1, peers[1], peers[1], peers[2])
449449
require.NoError(t, err)
@@ -502,7 +502,7 @@ func TestMigrations(t *testing.T) {
502502
receivedIndex := make([]int64, numChannels)
503503
queuedIndex := make([]int64, numChannels)
504504
allSelector := builder.NewSelectorSpecBuilder(basicnode.Prototype.Any).Matcher().Node()
505-
selfPeer := testutil.GeneratePeers(1)[0]
505+
selfPeer := random.Peers(1)[0]
506506

507507
list, err := migrations.GetChannelStateMigrations(selfPeer)
508508
require.NoError(t, err)
@@ -518,13 +518,13 @@ func TestMigrations(t *testing.T) {
518518
}
519519
for i := 0; i < numChannels; i++ {
520520
transferIDs[i] = datatransfer.TransferID(rand.Uint64())
521-
initiators[i] = testutil.GeneratePeers(1)[0]
522-
responders[i] = testutil.GeneratePeers(1)[0]
523-
baseCids[i] = testutil.GenerateCids(1)[0]
521+
initiators[i] = random.Peers(1)[0]
522+
responders[i] = random.Peers(1)[0]
523+
baseCids[i] = random.Cids(1)[0]
524524
totalSizes[i] = rand.Uint64()
525525
sents[i] = rand.Uint64()
526526
receiveds[i] = rand.Uint64()
527-
messages[i] = string(testutil.RandomBytes(20))
527+
messages[i] = string(random.Bytes(20))
528528
vouchers[i] = testutil.NewTestTypedVoucher()
529529
voucherResults[i] = testutil.NewTestTypedVoucher()
530530
sentIndex[i] = rand.Int63()

0 commit comments

Comments
 (0)