From 831b83e1c4b6ce243f01247d67e62c1adb9ba989 Mon Sep 17 00:00:00 2001 From: Daniel Norman <1992255+2color@users.noreply.github.com> Date: Tue, 6 Aug 2024 21:19:57 +0200 Subject: [PATCH 1/6] fix(bitswap): increase timeout to ensure hole punching completes (#651) Co-authored-by: Marcin Rataj --- CHANGELOG.md | 1 + bitswap/network/ipfs_impl.go | 7 +------ 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5475412c2..17e71b53b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ The following emojis are used to highlight certain changes: - `boxo/gateway` now correctly returns 404 Status Not Found instead of 500 when the requested content cannot be found due to offline exchange, gateway running in no-fetch (non-recursive) mode, or a similar restriction that only serves a specific set of CIDs. - `bitswap/client` fix memory leak in BlockPresenceManager due to unlimited map growth. +- `bitswap/network` fixed race condition when a timeout occurred before hole punching completed while establishing a first-time stream to a peer behind a NAT ### Security diff --git a/bitswap/network/ipfs_impl.go b/bitswap/network/ipfs_impl.go index ac9ab66a6..7acc3abcc 100644 --- a/bitswap/network/ipfs_impl.go +++ b/bitswap/network/ipfs_impl.go @@ -28,8 +28,6 @@ import ( var log = logging.Logger("bitswap/network") -var connectTimeout = time.Second * 5 - var ( maxSendTimeout = 2 * time.Minute minSendTimeout = 10 * time.Second @@ -323,10 +321,7 @@ func (bsnet *impl) SendMessage( p peer.ID, outgoing bsmsg.BitSwapMessage, ) error { - tctx, cancel := context.WithTimeout(ctx, connectTimeout) - defer cancel() - - s, err := bsnet.newStreamToPeer(tctx, p) + s, err := bsnet.newStreamToPeer(ctx, p) if err != nil { return err } From 11ab1c18292bfacf35e69baf64ddaa7c259bb950 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Wed, 7 Aug 2024 00:24:44 +0200 Subject: [PATCH 2/6] docs: boxo v0.22.0 --- CHANGELOG.md | 14 ++++++++++++-- version.json | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17e71b53b..12771a888 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,16 @@ The following emojis are used to highlight certain changes: ### Changed +### Removed + +### Fixed + +### Security + +## [v0.22.0] + +### Changed + - `go-libp2p` dependency updated to [v0.36 (release notes)](https://github.com/libp2p/go-libp2p/releases/tag/v0.36.1) - `bitswap/server` minor memory use and performance improvements - `bitswap` unify logger names to use uniform format bitswap/path/pkgname @@ -26,14 +36,14 @@ The following emojis are used to highlight certain changes: ### Removed +- `util` logic for generating random test data moved to [`ipfs/go-test/random`](https://github.com/ipfs/go-test) + ### Fixed - `boxo/gateway` now correctly returns 404 Status Not Found instead of 500 when the requested content cannot be found due to offline exchange, gateway running in no-fetch (non-recursive) mode, or a similar restriction that only serves a specific set of CIDs. - `bitswap/client` fix memory leak in BlockPresenceManager due to unlimited map growth. - `bitswap/network` fixed race condition when a timeout occurred before hole punching completed while establishing a first-time stream to a peer behind a NAT -### Security - ## [v0.21.0] ### Changed diff --git a/version.json b/version.json index c6a304fe7..6578f1967 100644 --- a/version.json +++ b/version.json @@ -1,3 +1,3 @@ { - "version": "v0.21.0" + "version": "v0.22.0" } From adb0591746f65df33c37f09af4c124c3bf396ae7 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Wed, 7 Aug 2024 00:56:42 +0200 Subject: [PATCH 3/6] docs(changelog): move entry to correct release --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12771a888..2d52df4d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ The following emojis are used to highlight certain changes: - `boxo/gateway` now correctly returns 404 Status Not Found instead of 500 when the requested content cannot be found due to offline exchange, gateway running in no-fetch (non-recursive) mode, or a similar restriction that only serves a specific set of CIDs. - `bitswap/client` fix memory leak in BlockPresenceManager due to unlimited map growth. - `bitswap/network` fixed race condition when a timeout occurred before hole punching completed while establishing a first-time stream to a peer behind a NAT +- `bitswap`: wantlist overflow handling now cancels existing entries to make room for newer entries. This fix prevents the wantlist from filling up with CIDs that the server does not have. ## [v0.21.0] @@ -59,7 +60,6 @@ The following emojis are used to highlight certain changes: - `routing/http`: the `FindPeer` now returns `routing.ErrNotFound` when no addresses are found - `routing/http`: the `FindProvidersAsync` no longer causes a goroutine buildup -- `bitswap`: wantlist overflow handling now cancels existing entries to make room for newer entries. This fix prevents the wantlist from filling up with CIDs that the server does not have. ## [v0.20.0] From 6467aa7bc0e974547ee8fe9562c79672d2a41107 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Wed, 7 Aug 2024 13:53:08 +0200 Subject: [PATCH 4/6] docs(changelog): reference related PRs --- CHANGELOG.md | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d52df4d9..5b8ba989e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,21 +29,17 @@ The following emojis are used to highlight certain changes: ### Changed - `go-libp2p` dependency updated to [v0.36 (release notes)](https://github.com/libp2p/go-libp2p/releases/tag/v0.36.1) -- `bitswap/server` minor memory use and performance improvements -- `bitswap` unify logger names to use uniform format bitswap/path/pkgname -- `gateway` now always returns meaningful cache-control headers for generated HTML listings of UnixFS directories -- generate random test data using `ipfs/go-test` instead of internal util code - -### Removed - -- `util` logic for generating random test data moved to [`ipfs/go-test/random`](https://github.com/ipfs/go-test) +- `bitswap/server` minor memory use and performance improvements [#634](https://github.com/ipfs/boxo/pull/634) +- `bitswap` unify logger names to use uniform format bitswap/path/pkgname [#637](https://github.com/ipfs/boxo/pull/637) +- `gateway` now always returns meaningful cache-control headers for generated HTML listings of UnixFS directories [#643](https://github.com/ipfs/boxo/pull/643) +- `util` generate random test data using `ipfs/go-test` instead of internal util code [#638](https://github.com/ipfs/boxo/pull/638) ### Fixed -- `boxo/gateway` now correctly returns 404 Status Not Found instead of 500 when the requested content cannot be found due to offline exchange, gateway running in no-fetch (non-recursive) mode, or a similar restriction that only serves a specific set of CIDs. -- `bitswap/client` fix memory leak in BlockPresenceManager due to unlimited map growth. -- `bitswap/network` fixed race condition when a timeout occurred before hole punching completed while establishing a first-time stream to a peer behind a NAT -- `bitswap`: wantlist overflow handling now cancels existing entries to make room for newer entries. This fix prevents the wantlist from filling up with CIDs that the server does not have. +- `boxo/gateway` now correctly returns 404 Status Not Found instead of 500 when the requested content cannot be found due to offline exchange, gateway running in no-fetch (non-recursive) mode, or a similar restriction that only serves a specific set of CIDs. [#630](https://github.com/ipfs/boxo/pull/630) +- `bitswap/client` fix memory leak in BlockPresenceManager due to unlimited map growth. [#636](https://github.com/ipfs/boxo/pull/636) +- `bitswap/network` fixed race condition when a timeout occurred before hole punching completed while establishing a first-time stream to a peer behind a NAT [#651](https://github.com/ipfs/boxo/pull/651) +- `bitswap`: wantlist overflow handling now cancels existing entries to make room for newer entries. This fix prevents the wantlist from filling up with CIDs that the server does not have. [#629](https://github.com/ipfs/boxo/pull/629) ## [v0.21.0] From 635e1754f8eb888518f211d2e7253f384b0441d4 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Wed, 7 Aug 2024 16:35:27 +0200 Subject: [PATCH 5/6] docs(changelog): Wants interface change --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b8ba989e..0657c1a21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ The following emojis are used to highlight certain changes: - `bitswap` unify logger names to use uniform format bitswap/path/pkgname [#637](https://github.com/ipfs/boxo/pull/637) - `gateway` now always returns meaningful cache-control headers for generated HTML listings of UnixFS directories [#643](https://github.com/ipfs/boxo/pull/643) - `util` generate random test data using `ipfs/go-test` instead of internal util code [#638](https://github.com/ipfs/boxo/pull/638) +- `bitswap/server` `PeerLedger.Wants` now returns `bool` (interface change from `Wants(p peer.ID, e wl.Entry)` to `Wants(p peer.ID, e wl.Entry) bool`) [#629](https://github.com/ipfs/boxo/pull/629) ### Fixed From 88beadf0804607dedc7a4aa12cfef47381a74f89 Mon Sep 17 00:00:00 2001 From: Andrew Gillis <11790789+gammazero@users.noreply.github.com> Date: Thu, 8 Aug 2024 07:02:03 -0700 Subject: [PATCH 6/6] Stop using go-ipfs-blocksutil (#656) - Replace use of go-ipfs-blocksutil with go-test/random - Remove remaining references to go-blockservice --- bitswap/bitswap_test.go | 38 ++++++++----------- bitswap/client/bitswap_with_sessions_test.go | 31 ++++++--------- bitswap/client/client.go | 2 +- .../notifications/notifications_test.go | 7 ++-- .../client/internal/session/session_test.go | 21 ++++------ bitswap/message/message_test.go | 9 ++--- bitswap/network/ipfs_impl_test.go | 12 +++--- blockservice/blockservice_test.go | 33 ++++++++-------- blockservice/internal/tracing.go | 2 +- exchange/offline/offline_test.go | 7 ++-- go.mod | 1 - go.sum | 12 ------ provider/internal/queue/queue_test.go | 10 ++--- 13 files changed, 75 insertions(+), 110 deletions(-) diff --git a/bitswap/bitswap_test.go b/bitswap/bitswap_test.go index 505871d6e..85055879c 100644 --- a/bitswap/bitswap_test.go +++ b/bitswap/bitswap_test.go @@ -19,14 +19,16 @@ import ( blocks "github.com/ipfs/go-block-format" cid "github.com/ipfs/go-cid" detectrace "github.com/ipfs/go-detect-race" - blocksutil "github.com/ipfs/go-ipfs-blocksutil" delay "github.com/ipfs/go-ipfs-delay" ipld "github.com/ipfs/go-ipld-format" + "github.com/ipfs/go-test/random" tu "github.com/libp2p/go-libp2p-testing/etc" p2ptestutil "github.com/libp2p/go-libp2p-testing/netutil" peer "github.com/libp2p/go-libp2p/core/peer" ) +const blockSize = 4 + func isCI() bool { // https://github.blog/changelog/2020-04-15-github-actions-sets-the-ci-environment-variable-to-true/ return os.Getenv("CI") != "" @@ -52,9 +54,7 @@ func TestClose(t *testing.T) { vnet := tn.VirtualNetwork(mockrouting.NewServer(), delay.Fixed(kNetworkDelay)) ig := testinstance.NewTestInstanceGenerator(vnet, nil, nil) defer ig.Close() - bgen := blocksutil.NewBlockGenerator() - - block := bgen.Next() + block := random.BlocksOfSize(1, blockSize)[0] bitswap := ig.Next() bitswap.Exchange.Close() @@ -187,7 +187,6 @@ func TestUnwantedBlockNotAdded(t *testing.T) { func TestPendingBlockAdded(t *testing.T) { ctx := context.Background() net := tn.VirtualNetwork(mockrouting.NewServer(), delay.Fixed(kNetworkDelay)) - bg := blocksutil.NewBlockGenerator() sessionBroadcastWantCapacity := 4 ig := testinstance.NewTestInstanceGenerator(net, nil, nil) @@ -202,7 +201,7 @@ func TestPendingBlockAdded(t *testing.T) { // Request enough blocks to exceed the session's broadcast want list // capacity (by one block). The session will put the remaining block // into the "tofetch" queue - blks := bg.Blocks(sessionBroadcastWantCapacity + 1) + blks := random.BlocksOfSize(sessionBroadcastWantCapacity+1, blockSize) ks := make([]cid.Cid, 0, len(blks)) for _, b := range blks { ks = append(ks, b.Cid()) @@ -285,10 +284,9 @@ func PerformDistributionTest(t *testing.T, numInstances, numBlocks int) { bitswap.MaxOutstandingBytesPerPeer(1 << 20), }) defer ig.Close() - bg := blocksutil.NewBlockGenerator() instances := ig.Instances(numInstances) - blocks := bg.Blocks(numBlocks) + blocks := random.BlocksOfSize(numBlocks, blockSize) t.Log("Give the blocks to the first instance") @@ -338,7 +336,6 @@ func TestSendToWantingPeer(t *testing.T) { net := tn.VirtualNetwork(mockrouting.NewServer(), delay.Fixed(kNetworkDelay)) ig := testinstance.NewTestInstanceGenerator(net, nil, nil) defer ig.Close() - bg := blocksutil.NewBlockGenerator() peers := ig.Instances(2) peerA := peers[0] @@ -349,7 +346,7 @@ func TestSendToWantingPeer(t *testing.T) { waitTime := time.Second * 5 - alpha := bg.Next() + alpha := random.BlocksOfSize(1, blockSize)[0] // peerA requests and waits for block alpha ctx, cancel := context.WithTimeout(context.Background(), waitTime) defer cancel() @@ -409,12 +406,11 @@ func TestBasicBitswap(t *testing.T) { net := tn.VirtualNetwork(mockrouting.NewServer(), delay.Fixed(kNetworkDelay)) ig := testinstance.NewTestInstanceGenerator(net, nil, nil) defer ig.Close() - bg := blocksutil.NewBlockGenerator() t.Log("Test a one node trying to get one block from another") instances := ig.Instances(3) - blocks := bg.Blocks(1) + blocks := random.BlocksOfSize(1, blockSize) // First peer has block addBlock(t, context.Background(), instances[0], blocks[0]) @@ -481,12 +477,11 @@ func TestDoubleGet(t *testing.T) { net := tn.VirtualNetwork(mockrouting.NewServer(), delay.Fixed(kNetworkDelay)) ig := testinstance.NewTestInstanceGenerator(net, nil, nil) defer ig.Close() - bg := blocksutil.NewBlockGenerator() t.Log("Test a one node trying to get one block from another") instances := ig.Instances(2) - blocks := bg.Blocks(1) + blocks := random.BlocksOfSize(1, blockSize) // NOTE: A race condition can happen here where these GetBlocks requests go // through before the peers even get connected. This is okay, bitswap @@ -546,12 +541,11 @@ func TestWantlistCleanup(t *testing.T) { net := tn.VirtualNetwork(mockrouting.NewServer(), delay.Fixed(kNetworkDelay)) ig := testinstance.NewTestInstanceGenerator(net, nil, nil) defer ig.Close() - bg := blocksutil.NewBlockGenerator() instances := ig.Instances(2) instance := instances[0] bswap := instance.Exchange - blocks := bg.Blocks(20) + blocks := random.BlocksOfSize(20, blockSize) var keys []cid.Cid for _, b := range blocks { @@ -668,12 +662,11 @@ func TestBitswapLedgerOneWay(t *testing.T) { net := tn.VirtualNetwork(mockrouting.NewServer(), delay.Fixed(kNetworkDelay)) ig := testinstance.NewTestInstanceGenerator(net, nil, nil) defer ig.Close() - bg := blocksutil.NewBlockGenerator() t.Log("Test ledgers match when one peer sends block to another") instances := ig.Instances(2) - blocks := bg.Blocks(1) + blocks := random.BlocksOfSize(1, blockSize) addBlock(t, context.Background(), instances[0], blocks[0]) ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) @@ -693,12 +686,12 @@ func TestBitswapLedgerOneWay(t *testing.T) { } // check that receipts have intended values - ratest := newReceipt(1, 0, 1) + ratest := newReceipt(blockSize, 0, 1) err = assertLedgerEqual(ratest, ra) if err != nil { t.Fatal(err) } - rbtest := newReceipt(0, 1, 1) + rbtest := newReceipt(0, blockSize, 1) err = assertLedgerEqual(rbtest, rb) if err != nil { t.Fatal(err) @@ -717,12 +710,11 @@ func TestBitswapLedgerTwoWay(t *testing.T) { net := tn.VirtualNetwork(mockrouting.NewServer(), delay.Fixed(kNetworkDelay)) ig := testinstance.NewTestInstanceGenerator(net, nil, nil) defer ig.Close() - bg := blocksutil.NewBlockGenerator() t.Log("Test ledgers match when two peers send one block to each other") instances := ig.Instances(2) - blocks := bg.Blocks(2) + blocks := random.BlocksOfSize(2, blockSize) addBlock(t, context.Background(), instances[0], blocks[0]) addBlock(t, context.Background(), instances[1], blocks[1]) @@ -750,7 +742,7 @@ func TestBitswapLedgerTwoWay(t *testing.T) { } // check that receipts have intended values - rtest := newReceipt(1, 1, 2) + rtest := newReceipt(blockSize, blockSize, 2) err = assertLedgerEqual(rtest, ra) if err != nil { t.Fatal(err) diff --git a/bitswap/client/bitswap_with_sessions_test.go b/bitswap/client/bitswap_with_sessions_test.go index 0baede658..6241865ef 100644 --- a/bitswap/client/bitswap_with_sessions_test.go +++ b/bitswap/client/bitswap_with_sessions_test.go @@ -15,12 +15,14 @@ import ( mockrouting "github.com/ipfs/boxo/routing/mock" blocks "github.com/ipfs/go-block-format" cid "github.com/ipfs/go-cid" - blocksutil "github.com/ipfs/go-ipfs-blocksutil" delay "github.com/ipfs/go-ipfs-delay" + "github.com/ipfs/go-test/random" tu "github.com/libp2p/go-libp2p-testing/etc" "github.com/libp2p/go-libp2p/core/peer" ) +const blockSize = 4 + func getVirtualNetwork() tn.Network { // FIXME: the tests are really sensitive to the network delay. fix them to work // well under varying conditions @@ -46,9 +48,8 @@ func TestBasicSessions(t *testing.T) { vnet := getVirtualNetwork() ig := testinstance.NewTestInstanceGenerator(vnet, nil, nil) defer ig.Close() - bgen := blocksutil.NewBlockGenerator() - block := bgen.Next() + block := random.BlocksOfSize(1, blockSize)[0] inst := ig.Instances(2) a := inst[0] @@ -113,12 +114,11 @@ func TestSessionBetweenPeers(t *testing.T) { vnet := tn.VirtualNetwork(mockrouting.NewServer(), delay.Fixed(time.Millisecond)) ig := testinstance.NewTestInstanceGenerator(vnet, nil, []bitswap.Option{bitswap.SetSimulateDontHavesOnTimeout(false)}) defer ig.Close() - bgen := blocksutil.NewBlockGenerator() inst := ig.Instances(10) // Add 101 blocks to Peer A - blks := bgen.Blocks(101) + blks := random.BlocksOfSize(101, blockSize) if err := inst[0].Blockstore().PutMany(ctx, blks); err != nil { t.Fatal(err) } @@ -173,12 +173,11 @@ func TestSessionSplitFetch(t *testing.T) { vnet := getVirtualNetwork() ig := testinstance.NewTestInstanceGenerator(vnet, nil, nil) defer ig.Close() - bgen := blocksutil.NewBlockGenerator() inst := ig.Instances(11) // Add 10 distinct blocks to each of 10 peers - blks := bgen.Blocks(100) + blks := random.BlocksOfSize(100, blockSize) for i := 0; i < 10; i++ { if err := inst[i].Blockstore().PutMany(ctx, blks[i*10:(i+1)*10]); err != nil { t.Fatal(err) @@ -217,12 +216,11 @@ func TestFetchNotConnected(t *testing.T) { vnet := getVirtualNetwork() ig := testinstance.NewTestInstanceGenerator(vnet, nil, []bitswap.Option{bitswap.ProviderSearchDelay(10 * time.Millisecond)}) defer ig.Close() - bgen := blocksutil.NewBlockGenerator() other := ig.Next() // Provide 10 blocks on Peer A - blks := bgen.Blocks(10) + blks := random.BlocksOfSize(10, blockSize) for _, block := range blks { addBlock(t, ctx, other, block) } @@ -263,14 +261,13 @@ func TestFetchAfterDisconnect(t *testing.T) { bitswap.RebroadcastDelay(delay.Fixed(15 * time.Millisecond)), }) defer ig.Close() - bgen := blocksutil.NewBlockGenerator() inst := ig.Instances(2) peerA := inst[0] peerB := inst[1] // Provide 5 blocks on Peer A - blks := bgen.Blocks(10) + blks := random.BlocksOfSize(10, blockSize) var cids []cid.Cid for _, blk := range blks { cids = append(cids, blk.Cid()) @@ -338,9 +335,8 @@ func TestInterestCacheOverflow(t *testing.T) { vnet := getVirtualNetwork() ig := testinstance.NewTestInstanceGenerator(vnet, nil, nil) defer ig.Close() - bgen := blocksutil.NewBlockGenerator() - blks := bgen.Blocks(2049) + blks := random.BlocksOfSize(2049, blockSize) inst := ig.Instances(2) a := inst[0] @@ -388,9 +384,8 @@ func TestPutAfterSessionCacheEvict(t *testing.T) { vnet := getVirtualNetwork() ig := testinstance.NewTestInstanceGenerator(vnet, nil, nil) defer ig.Close() - bgen := blocksutil.NewBlockGenerator() - blks := bgen.Blocks(2500) + blks := random.BlocksOfSize(2500, blockSize) inst := ig.Instances(1) a := inst[0] @@ -426,9 +421,8 @@ func TestMultipleSessions(t *testing.T) { vnet := getVirtualNetwork() ig := testinstance.NewTestInstanceGenerator(vnet, nil, nil) defer ig.Close() - bgen := blocksutil.NewBlockGenerator() - blk := bgen.Blocks(1)[0] + blk := random.BlocksOfSize(1, blockSize)[0] inst := ig.Instances(2) a := inst[0] @@ -467,9 +461,8 @@ func TestWantlistClearsOnCancel(t *testing.T) { vnet := getVirtualNetwork() ig := testinstance.NewTestInstanceGenerator(vnet, nil, nil) defer ig.Close() - bgen := blocksutil.NewBlockGenerator() - blks := bgen.Blocks(10) + blks := random.BlocksOfSize(10, blockSize) var cids []cid.Cid for _, blk := range blks { cids = append(cids, blk.Cid()) diff --git a/bitswap/client/client.go b/bitswap/client/client.go index 0a5bdeb9e..e0f952d82 100644 --- a/bitswap/client/client.go +++ b/bitswap/client/client.go @@ -499,7 +499,7 @@ func (bs *Client) IsOnline() bool { // block requests in a row. The session returned will have it's own GetBlocks // method, but the session will use the fact that the requests are related to // be more efficient in its requests to peers. If you are using a session -// from go-blockservice, it will create a bitswap session automatically. +// from blockservice, it will create a bitswap session automatically. func (bs *Client) NewSession(ctx context.Context) exchange.Fetcher { ctx, span := internal.StartSpan(ctx, "NewSession") defer span.End() diff --git a/bitswap/client/internal/notifications/notifications_test.go b/bitswap/client/internal/notifications/notifications_test.go index 68b4da1ec..26378320b 100644 --- a/bitswap/client/internal/notifications/notifications_test.go +++ b/bitswap/client/internal/notifications/notifications_test.go @@ -8,10 +8,12 @@ import ( blocks "github.com/ipfs/go-block-format" cid "github.com/ipfs/go-cid" - blocksutil "github.com/ipfs/go-ipfs-blocksutil" + "github.com/ipfs/go-test/random" "github.com/libp2p/go-libp2p/core/peer" ) +const blockSize = 4 + func TestDuplicates(t *testing.T) { var zero peer.ID // this test doesn't check the peer id @@ -152,13 +154,12 @@ func TestCarryOnWhenDeadlineExpires(t *testing.T) { func TestDoesNotDeadLockIfContextCancelledBeforePublish(t *testing.T) { var zero peer.ID // this test doesn't check the peer id - g := blocksutil.NewBlockGenerator() ctx, cancel := context.WithCancel(context.Background()) n := New() defer n.Shutdown() t.Log("generate a large number of blocks. exceed default buffer") - bs := g.Blocks(1000) + bs := random.BlocksOfSize(1000, blockSize) ks := func() []cid.Cid { var keys []cid.Cid for _, b := range bs { diff --git a/bitswap/client/internal/session/session_test.go b/bitswap/client/internal/session/session_test.go index 1c40b64e1..a14fdffd0 100644 --- a/bitswap/client/internal/session/session_test.go +++ b/bitswap/client/internal/session/session_test.go @@ -15,13 +15,14 @@ import ( "github.com/ipfs/boxo/internal/test" blocks "github.com/ipfs/go-block-format" cid "github.com/ipfs/go-cid" - blocksutil "github.com/ipfs/go-ipfs-blocksutil" delay "github.com/ipfs/go-ipfs-delay" "github.com/ipfs/go-test/random" peer "github.com/libp2p/go-libp2p/core/peer" "github.com/stretchr/testify/require" ) +const blockSize = 4 + type mockSessionMgr struct { lk sync.Mutex removeSession bool @@ -165,8 +166,7 @@ func TestSessionGetBlocks(t *testing.T) { id := random.SequenceNext() sm := newMockSessionMgr() session := New(ctx, sm, id, fspm, fpf, sim, fpm, bpm, notif, time.Second, delay.Fixed(time.Minute), "") - blockGenerator := blocksutil.NewBlockGenerator() - blks := blockGenerator.Blocks(broadcastLiveWantsLimit * 2) + blks := random.BlocksOfSize(broadcastLiveWantsLimit*2, blockSize) var cids []cid.Cid for _, block := range blks { cids = append(cids, block.Cid()) @@ -249,8 +249,7 @@ func TestSessionFindMorePeers(t *testing.T) { sm := newMockSessionMgr() session := New(ctx, sm, id, fspm, fpf, sim, fpm, bpm, notif, time.Second, delay.Fixed(time.Minute), "") session.SetBaseTickDelay(200 * time.Microsecond) - blockGenerator := blocksutil.NewBlockGenerator() - blks := blockGenerator.Blocks(broadcastLiveWantsLimit * 2) + blks := random.BlocksOfSize(broadcastLiveWantsLimit*2, blockSize) var cids []cid.Cid for _, block := range blks { cids = append(cids, block.Cid()) @@ -319,8 +318,7 @@ func TestSessionOnPeersExhausted(t *testing.T) { id := random.SequenceNext() sm := newMockSessionMgr() session := New(ctx, sm, id, fspm, fpf, sim, fpm, bpm, notif, time.Second, delay.Fixed(time.Minute), "") - blockGenerator := blocksutil.NewBlockGenerator() - blks := blockGenerator.Blocks(broadcastLiveWantsLimit + 5) + blks := random.BlocksOfSize(broadcastLiveWantsLimit+5, blockSize) var cids []cid.Cid for _, block := range blks { cids = append(cids, block.Cid()) @@ -359,8 +357,7 @@ func TestSessionFailingToGetFirstBlock(t *testing.T) { id := random.SequenceNext() sm := newMockSessionMgr() session := New(ctx, sm, id, fspm, fpf, sim, fpm, bpm, notif, 10*time.Millisecond, delay.Fixed(100*time.Millisecond), "") - blockGenerator := blocksutil.NewBlockGenerator() - blks := blockGenerator.Blocks(4) + blks := random.BlocksOfSize(4, blockSize) var cids []cid.Cid for _, block := range blks { cids = append(cids, block.Cid()) @@ -482,8 +479,7 @@ func TestSessionCtxCancelClosesGetBlocksChannel(t *testing.T) { defer timerCancel() // Request a block with a new context - blockGenerator := blocksutil.NewBlockGenerator() - blks := blockGenerator.Blocks(1) + blks := random.BlocksOfSize(1, blockSize) getctx, getcancel := context.WithTimeout(context.Background(), 100*time.Millisecond) defer getcancel() @@ -545,8 +541,7 @@ func TestSessionReceiveMessageAfterCtxCancel(t *testing.T) { id := random.SequenceNext() sm := newMockSessionMgr() session := New(ctx, sm, id, fspm, fpf, sim, fpm, bpm, notif, time.Second, delay.Fixed(time.Minute), "") - blockGenerator := blocksutil.NewBlockGenerator() - blks := blockGenerator.Blocks(2) + blks := random.BlocksOfSize(2, blockSize) cids := []cid.Cid{blks[0].Cid(), blks[1].Cid()} _, err := session.GetBlocks(ctx, cids) diff --git a/bitswap/message/message_test.go b/bitswap/message/message_test.go index ec07cbcff..2b943aeb1 100644 --- a/bitswap/message/message_test.go +++ b/bitswap/message/message_test.go @@ -6,15 +6,13 @@ import ( "github.com/ipfs/boxo/bitswap/client/wantlist" pb "github.com/ipfs/boxo/bitswap/message/pb" - blocksutil "github.com/ipfs/go-ipfs-blocksutil" - - u "github.com/ipfs/boxo/util" blocks "github.com/ipfs/go-block-format" cid "github.com/ipfs/go-cid" + "github.com/ipfs/go-test/random" ) func mkFakeCid(s string) cid.Cid { - return cid.NewCidV0(u.Hash([]byte(s))) + return random.Cids(1)[0] } func TestAppendWanted(t *testing.T) { @@ -290,8 +288,7 @@ func TestAddWantlistEntry(t *testing.T) { } func TestEntrySize(t *testing.T) { - blockGenerator := blocksutil.NewBlockGenerator() - c := blockGenerator.Next().Cid() + c := random.BlocksOfSize(1, 4)[0].Cid() e := Entry{ Entry: wantlist.Entry{ Cid: c, diff --git a/bitswap/network/ipfs_impl_test.go b/bitswap/network/ipfs_impl_test.go index af76e20d6..91e998846 100644 --- a/bitswap/network/ipfs_impl_test.go +++ b/bitswap/network/ipfs_impl_test.go @@ -15,7 +15,7 @@ import ( tn "github.com/ipfs/boxo/bitswap/testnet" mockrouting "github.com/ipfs/boxo/routing/mock" ds "github.com/ipfs/go-datastore" - blocksutil "github.com/ipfs/go-ipfs-blocksutil" + "github.com/ipfs/go-test/random" tnet "github.com/libp2p/go-libp2p-testing/net" "github.com/libp2p/go-libp2p/core/host" "github.com/libp2p/go-libp2p/core/network" @@ -215,9 +215,10 @@ func TestMessageSendAndReceive(t *testing.T) { if _, ok := r2.peers[p1.ID()]; !ok { t.Fatal("did to connect to correct peer") } - blockGenerator := blocksutil.NewBlockGenerator() - block1 := blockGenerator.Next() - block2 := blockGenerator.Next() + randBlocks := random.BlocksOfSize(2, 4) + block1 := randBlocks[0] + block2 := randBlocks[1] + sent := bsmsg.New(false) sent.AddEntry(block1.Cid(), 1, pb.Message_Wantlist_Block, true) sent.AddBlock(block2) @@ -323,8 +324,7 @@ func prepareNetwork(t *testing.T, ctx context.Context, p1 tnet.Identity, r1 *rec t.Fatal(err) } - blockGenerator := blocksutil.NewBlockGenerator() - block1 := blockGenerator.Next() + block1 := random.BlocksOfSize(1, 4)[0] msg := bsmsg.New(false) msg.AddEntry(block1.Cid(), 1, pb.Message_Wantlist_Block, true) diff --git a/blockservice/blockservice_test.go b/blockservice/blockservice_test.go index 53fd725f3..29350ff37 100644 --- a/blockservice/blockservice_test.go +++ b/blockservice/blockservice_test.go @@ -12,12 +12,14 @@ import ( cid "github.com/ipfs/go-cid" ds "github.com/ipfs/go-datastore" dssync "github.com/ipfs/go-datastore/sync" - butil "github.com/ipfs/go-ipfs-blocksutil" ipld "github.com/ipfs/go-ipld-format" + "github.com/ipfs/go-test/random" "github.com/multiformats/go-multihash" "github.com/stretchr/testify/assert" ) +const blockSize = 4 + func TestWriteThroughWorks(t *testing.T) { t.Parallel() @@ -28,9 +30,8 @@ func TestWriteThroughWorks(t *testing.T) { exchbstore := blockstore.NewBlockstore(dssync.MutexWrap(ds.NewMapDatastore())) exch := offline.Exchange(exchbstore) bserv := New(bstore, exch, WriteThrough()) - bgen := butil.NewBlockGenerator() - block := bgen.Next() + block := random.BlocksOfSize(1, blockSize)[0] t.Logf("PutCounter: %d", bstore.PutCounter) err := bserv.AddBlock(context.Background(), block) @@ -63,7 +64,6 @@ func TestExchangeWrite(t *testing.T) { 0, } bserv := New(bstore, exch, WriteThrough()) - bgen := butil.NewBlockGenerator() for name, fetcher := range map[string]BlockGetter{ "blockservice": bserv, @@ -71,7 +71,8 @@ func TestExchangeWrite(t *testing.T) { } { t.Run(name, func(t *testing.T) { // GetBlock - block := bgen.Next() + blks := random.BlocksOfSize(3, blockSize) + block := blks[0] err := exchbstore.Put(context.Background(), block) if err != nil { t.Fatal(err) @@ -91,12 +92,12 @@ func TestExchangeWrite(t *testing.T) { } // GetBlocks - b1 := bgen.Next() + b1 := blks[1] err = exchbstore.Put(context.Background(), b1) if err != nil { t.Fatal(err) } - b2 := bgen.Next() + b2 := blks[2] err = exchbstore.Put(context.Background(), b2) if err != nil { t.Fatal(err) @@ -137,14 +138,14 @@ func TestLazySessionInitialization(t *testing.T) { exch := offline.Exchange(bstore3) sessionExch := &fakeSessionExchange{Interface: exch, session: session} bservSessEx := New(bstore, sessionExch, WriteThrough()) - bgen := butil.NewBlockGenerator() + blks := random.BlocksOfSize(2, blockSize) - block := bgen.Next() + block := blks[0] err := bstore.Put(ctx, block) if err != nil { t.Fatal(err) } - block2 := bgen.Next() + block2 := blks[1] err = bstore2.Put(ctx, block2) if err != nil { t.Fatal(err) @@ -230,8 +231,7 @@ func TestNilExchange(t *testing.T) { ctx, cancel := context.WithCancel(ctx) defer cancel() - bgen := butil.NewBlockGenerator() - block := bgen.Next() + block := random.BlocksOfSize(1, blockSize)[0] bs := blockstore.NewBlockstore(dssync.MutexWrap(ds.NewMapDatastore())) bserv := New(bs, nil, WriteThrough()) @@ -261,8 +261,7 @@ func TestAllowlist(t *testing.T) { ctx, cancel := context.WithCancel(ctx) defer cancel() - bgen := butil.NewBlockGenerator() - block := bgen.Next() + block := random.BlocksOfSize(1, blockSize)[0] data := []byte("this is some blake3 block") mh, err := multihash.Sum(data, multihash.BLAKE3, -1) @@ -324,9 +323,9 @@ func TestContextSession(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - bgen := butil.NewBlockGenerator() - block1 := bgen.Next() - block2 := bgen.Next() + blks := random.BlocksOfSize(2, blockSize) + block1 := blks[0] + block2 := blks[1] bs := blockstore.NewBlockstore(ds.NewMapDatastore()) a.NoError(bs.Put(ctx, block1)) diff --git a/blockservice/internal/tracing.go b/blockservice/internal/tracing.go index ee04673f4..742641484 100644 --- a/blockservice/internal/tracing.go +++ b/blockservice/internal/tracing.go @@ -13,5 +13,5 @@ func StartSpan(ctx context.Context, name string, opts ...trace.SpanStartOption) // outline logic so the string concatenation can be inlined and executed at compile time func startSpan(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span) { - return otel.Tracer("go-blockservice").Start(ctx, name, opts...) + return otel.Tracer("blockservice").Start(ctx, name, opts...) } diff --git a/exchange/offline/offline_test.go b/exchange/offline/offline_test.go index 2167f3e2e..cc344a0f0 100644 --- a/exchange/offline/offline_test.go +++ b/exchange/offline/offline_test.go @@ -9,9 +9,11 @@ import ( cid "github.com/ipfs/go-cid" ds "github.com/ipfs/go-datastore" ds_sync "github.com/ipfs/go-datastore/sync" - blocksutil "github.com/ipfs/go-ipfs-blocksutil" + "github.com/ipfs/go-test/random" ) +const blockSize = 4 + func TestBlockReturnsErr(t *testing.T) { off := Exchange(bstore()) c := cid.NewCidV0(u.Hash([]byte("foo"))) @@ -25,9 +27,8 @@ func TestBlockReturnsErr(t *testing.T) { func TestGetBlocks(t *testing.T) { store := bstore() ex := Exchange(store) - g := blocksutil.NewBlockGenerator() - expected := g.Blocks(2) + expected := random.BlocksOfSize(2, blockSize) for _, b := range expected { if err := store.Put(context.Background(), b); err != nil { diff --git a/go.mod b/go.mod index ed882bbee..3ccf62b41 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,6 @@ require ( github.com/ipfs/go-cidutil v0.1.0 github.com/ipfs/go-datastore v0.6.0 github.com/ipfs/go-detect-race v0.0.1 - github.com/ipfs/go-ipfs-blocksutil v0.0.1 github.com/ipfs/go-ipfs-delay v0.0.1 github.com/ipfs/go-ipfs-redirects-file v0.1.1 github.com/ipfs/go-ipld-format v0.6.0 diff --git a/go.sum b/go.sum index 59626e503..354e5378c 100644 --- a/go.sum +++ b/go.sum @@ -149,8 +149,6 @@ github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:Fecb github.com/grpc-ecosystem/grpc-gateway v1.5.0/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw= github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1YCS1PXdKYWi8FsN0= github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737NnSbmxQAppXMRziHUxPOC8k= -github.com/gxed/hashland/keccakpg v0.0.1/go.mod h1:kRzw3HkwxFU1mpmPP8v1WyQzwdGfmKFJ6tItnhQ67kU= -github.com/gxed/hashland/murmur3 v0.0.1/go.mod h1:KjXop02n4/ckmZSnY2+HKcLud/tcmvhST0bie/0lS48= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -168,12 +166,10 @@ github.com/ipfs/go-bitfield v1.1.0 h1:fh7FIo8bSwaJEh6DdTWbCeZ1eqOaOkKFI74SCnsWbG github.com/ipfs/go-bitfield v1.1.0/go.mod h1:paqf1wjq/D2BBmzfTVFlJQ9IlFOZpg422HL0HqsGWHU= github.com/ipfs/go-bitswap v0.11.0 h1:j1WVvhDX1yhG32NTC9xfxnqycqYIlhzEzLXG/cU1HyQ= github.com/ipfs/go-bitswap v0.11.0/go.mod h1:05aE8H3XOU+LXpTedeAS0OZpcO1WFsj5niYQH9a1Tmk= -github.com/ipfs/go-block-format v0.0.2/go.mod h1:AWR46JfpcObNfg3ok2JHDUfdiHRgWhJgCQF+KIgOPJY= github.com/ipfs/go-block-format v0.2.0 h1:ZqrkxBA2ICbDRbK8KJs/u0O3dlp6gmAuuXUJNiW1Ycs= github.com/ipfs/go-block-format v0.2.0/go.mod h1:+jpL11nFx5A/SPpsoBn6Bzkra/zaArfSmsknbPMYgzM= github.com/ipfs/go-blockservice v0.5.2 h1:in9Bc+QcXwd1apOVM7Un9t8tixPKdaHQFdLSUM1Xgk8= github.com/ipfs/go-blockservice v0.5.2/go.mod h1:VpMblFEqG67A/H2sHKAemeH9vlURVavlysbdUI632yk= -github.com/ipfs/go-cid v0.0.1/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM= github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s= github.com/ipfs/go-cid v0.4.1/go.mod h1:uQHwDeX4c6CtyrFwdqyhpNcxVewur1M7l7fNU7LKwZk= github.com/ipfs/go-cidutil v0.1.0 h1:RW5hO7Vcf16dplUU60Hs0AKDkQAVPVplr7lk97CFL+Q= @@ -202,7 +198,6 @@ github.com/ipfs/go-ipfs-redirects-file v0.1.1 h1:Io++k0Vf/wK+tfnhEh63Yte1oQK5VGT github.com/ipfs/go-ipfs-redirects-file v0.1.1/go.mod h1:tAwRjCV0RjLTjH8DR/AU7VYvfQECg+lpUy2Mdzv7gyk= github.com/ipfs/go-ipfs-routing v0.3.0 h1:9W/W3N+g+y4ZDeffSgqhgo7BsBSJwPMcyssET9OWevc= github.com/ipfs/go-ipfs-routing v0.3.0/go.mod h1:dKqtTFIql7e1zYsEuWLyuOU+E0WJWW8JjbTPLParDWo= -github.com/ipfs/go-ipfs-util v0.0.1/go.mod h1:spsl5z8KUnrve+73pOhSVZND1SIxPW5RyBCNzQxlJBc= github.com/ipfs/go-ipfs-util v0.0.3 h1:2RFdGez6bu2ZlZdI+rWfIdbQb1KudQp3VGwPtdNCmE0= github.com/ipfs/go-ipfs-util v0.0.3/go.mod h1:LHzG1a0Ig4G+iZ26UUOMjHd+lfM84LZCrn17xAKWBvs= github.com/ipfs/go-ipld-cbor v0.1.0 h1:dx0nS0kILVivGhfWuB6dUpMa/LAwElHPw1yOGYopoYs= @@ -322,17 +317,14 @@ github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b/go.mod h1:lxPUiZwKo github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc h1:PTfri+PuQmWDqERdnNMiD9ZejrlswWrCpBEZgWOiTrc= github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc/go.mod h1:cGKTAVKx4SxOuR/czcZ/E2RSJ3sfHs8FpHhQ5CWMf9s= github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ= -github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U= github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dzMM= github.com/minio/sha256-simd v1.0.1/go.mod h1:Pz6AKMiUdngCLpeTL/RJY1M9rUuPMYujV5xJjtbRSN8= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8= github.com/mr-tron/base58 v1.1.2/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o= github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= -github.com/multiformats/go-base32 v0.0.3/go.mod h1:pLiuGC8y0QR3Ue4Zug5UzK9LjgbkL8NSQj0zQ5Nz/AA= github.com/multiformats/go-base32 v0.1.0 h1:pVx9xoSPqEIQG8o+UbAe7DNi51oej1NtK+aGkbLYxPE= github.com/multiformats/go-base32 v0.1.0/go.mod h1:Kj3tFY6zNr+ABYMqeUNeGvkIC/UYgtWibDcT0rExnbI= github.com/multiformats/go-base36 v0.2.0 h1:lFsAbNOGeKtuKozrtBsAkSVhv1p9D0/qedU9rQyccr0= @@ -346,12 +338,10 @@ github.com/multiformats/go-multiaddr-dns v0.3.1 h1:QgQgR+LQVt3NPTjbrLLpsaT2ufAA2 github.com/multiformats/go-multiaddr-dns v0.3.1/go.mod h1:G/245BRQ6FJGmryJCrOuTdB37AMA5AMOVuO6NY3JwTk= github.com/multiformats/go-multiaddr-fmt v0.1.0 h1:WLEFClPycPkp4fnIzoFoV9FVd49/eQsuaL3/CWe167E= github.com/multiformats/go-multiaddr-fmt v0.1.0/go.mod h1:hGtDIW4PU4BqJ50gW2quDuPVjyWNZxToGUh/HwTZYJo= -github.com/multiformats/go-multibase v0.0.1/go.mod h1:bja2MqRZ3ggyXtZSEDKpl0uO/gviWFaSteVbWT51qgs= github.com/multiformats/go-multibase v0.2.0 h1:isdYCVLvksgWlMW9OZRYJEa9pZETFivncJHmHnnd87g= github.com/multiformats/go-multibase v0.2.0/go.mod h1:bFBZX4lKCA/2lyOFSAoKH5SS6oPyjtnzK/XTFDPkNuk= github.com/multiformats/go-multicodec v0.9.0 h1:pb/dlPnzee/Sxv/j4PmkDRxCOi3hXTz3IbPKOXWJkmg= github.com/multiformats/go-multicodec v0.9.0/go.mod h1:L3QTQvMIaVBkXOXXtVmYE+LI16i14xuaojr/H7Ai54k= -github.com/multiformats/go-multihash v0.0.1/go.mod h1:w/5tugSrLEbWqlcgJabL3oHFKTwfvkofsjW2Qa1ct4U= github.com/multiformats/go-multihash v0.0.8/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew= github.com/multiformats/go-multihash v0.2.3 h1:7Lyc8XfX/IY2jWb/gI7JP+o7JEq9hOa7BFvVU9RSh+U= github.com/multiformats/go-multihash v0.2.3/go.mod h1:dXgKXCXjBzdscBLk9JkjINiEsCKRVch90MdaGiKsvSM= @@ -586,7 +576,6 @@ go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= go4.org v0.0.0-20180809161055-417644f6feb5/go.mod h1:MkTOUMDaeVYJUOUsaDXIhWPZYa1yOyC1qaOBpL57BhE= golang.org/x/build v0.0.0-20190111050920-041ab4dc3f9d/go.mod h1:OWs+y06UdEOHN4y+MfF/py+xQ/tYqIWW03b70/CG9Rw= golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -668,7 +657,6 @@ golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181029174526-d69651ed3497/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190219092855-153ac476189d/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190316082340-a2f829d7f35f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/provider/internal/queue/queue_test.go b/provider/internal/queue/queue_test.go index a2d9f0be4..a9a49cc66 100644 --- a/provider/internal/queue/queue_test.go +++ b/provider/internal/queue/queue_test.go @@ -9,16 +9,16 @@ import ( "github.com/ipfs/go-cid" "github.com/ipfs/go-datastore" "github.com/ipfs/go-datastore/sync" - blocksutil "github.com/ipfs/go-ipfs-blocksutil" + "github.com/ipfs/go-test/random" ) -var blockGenerator = blocksutil.NewBlockGenerator() +const blockSize = 4 func makeCids(n int) []cid.Cid { - cids := make([]cid.Cid, 0, n) + blks := random.BlocksOfSize(n, blockSize) + cids := make([]cid.Cid, n) for i := 0; i < n; i++ { - c := blockGenerator.Next().Cid() - cids = append(cids, c) + cids[i] = blks[i].Cid() } return cids }