From fa3d6c9bd64f80ab227244a7d62d7b53352ceddd Mon Sep 17 00:00:00 2001 From: Ivan Schasny Date: Mon, 23 Oct 2023 11:47:52 +0100 Subject: [PATCH 1/2] Test publish after remove for the context id Verify that index-provider allows reusing the same context id. To do that one would need to call NotifyRemove followed by NotifyPut. --- engine/engine_test.go | 56 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/engine/engine_test.go b/engine/engine_test.go index 7ab6018d..dd67ac89 100644 --- a/engine/engine_test.go +++ b/engine/engine_test.go @@ -734,6 +734,62 @@ func TestEngine_RegenrateEntryChunksFromOldDatastore(t *testing.T) { requireLoadEntryChunkFromEngine(t, subject, ad.Entries) } +func TestEngine_DeleteAndPublishWithTheSameContextID(t *testing.T) { + ctx, cancel := context.WithTimeout(context.Background(), testTimeout) + t.Cleanup(cancel) + + mhs1 := test.RandomMultihashes(42) + mhs2 := test.RandomMultihashes(42) + + subject, err := engine.New() + require.NoError(t, err) + err = subject.Start(ctx) + require.NoError(t, err) + defer subject.Shutdown() + + cnt := 0 + subject.RegisterMultihashLister(func(ctx context.Context, p peer.ID, contextID []byte) (provider.MultihashIterator, error) { + cnt++ + if cnt == 1 { + return provider.SliceMultihashIterator(mhs1), nil + } else { + // return mhs1 only for the first ad + return provider.SliceMultihashIterator(mhs2), nil + } + }) + + md := metadata.Default.New(metadata.Bitswap{}) + contextId := []byte("fish") + paddr := peer.AddrInfo{ID: subject.Host().ID(), Addrs: subject.Host().Addrs()} + + // publish the first ad + ad1Cid, err := subject.NotifyPut(ctx, &paddr, contextId, md) + require.NoError(t, err) + require.NotEqual(t, cid.Undef, ad1Cid) + + // publish a remove for the context id followed by a new ad - that should result into the latest ad linking to the new array of multihashes + ad2Cid, err := subject.NotifyRemove(ctx, paddr.ID, contextId) + require.NoError(t, err) + require.NotEqual(t, ad1Cid, ad2Cid) + + ad3Cid, err := subject.NotifyPut(ctx, &paddr, contextId, md) + require.NoError(t, err) + require.NotEqual(t, ad2Cid, ad3Cid) + + latestAdCid, latestAd, err := subject.GetLatestAdv(ctx) + require.NoError(t, err) + require.Equal(t, ad3Cid, latestAdCid) + + // read cached entries and extract multihashes + var mhs []multihash.Multihash + entryChunks := requireLoadEntryChunkFromEngine(t, subject, latestAd.Entries) + for _, ch := range entryChunks { + mhs = append(mhs, ch.Entries...) + } + + require.Equal(t, mhs2, mhs) +} + func verifyAd(t *testing.T, ctx context.Context, subject *engine.Engine, expected, actual *schema.Advertisement) { require.Equal(t, expected.ContextID, actual.ContextID) require.Equal(t, expected.Provider, actual.Provider) From fee2db82d4afcffb354d13cdfed7301fd4c0a12e Mon Sep 17 00:00:00 2001 From: Ivan Schasny Date: Mon, 23 Oct 2023 13:29:39 +0100 Subject: [PATCH 2/2] Ignore linting for delegatedrouting --- delegatedrouting/listener.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/delegatedrouting/listener.go b/delegatedrouting/listener.go index 090c8877..a830561a 100644 --- a/delegatedrouting/listener.go +++ b/delegatedrouting/listener.go @@ -293,11 +293,13 @@ func (listener *Listener) FindProviders(ctx context.Context, key cid.Cid, limit return nil, errors.New("unsupported find providers request") } +//lint:ignore update to the new API once it materialises in boxo func (listener *Listener) Provide(ctx context.Context, req *server.WriteProvideRequest) (iter.ResultIter[types.Record], error) { log.Warn("Received unsupported Provide request") return nil, errors.New("unsupported provide request") } +//lint:ignore update to the new API once it materialises in boxo func (listener *Listener) ProvideBitswap(ctx context.Context, req *server.BitswapWriteProvideRequest) (time.Duration, error) { cids := req.Keys pid := req.ID