From 4623db891496bf4833d2bedbbf3c5e93df31c514 Mon Sep 17 00:00:00 2001 From: Ivan Schasny Date: Tue, 5 Dec 2023 12:46:08 +0000 Subject: [PATCH] Add a flag to skip multihash mismatch errors Any error returned by the link system other than ipld.ErrNotExists results into IPNI halting ingestion of such adchain. The new configuration option will allow boost to "skip" such advertisements instead without affecting the rest of the chain. --- engine/linksystem.go | 6 +++++- engine/options.go | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/engine/linksystem.go b/engine/linksystem.go index f51a9b51..06fed4e3 100644 --- a/engine/linksystem.go +++ b/engine/linksystem.go @@ -127,7 +127,11 @@ func (e *Engine) mkLinkSystem() ipld.LinkSystem { } if regeneratedLink == nil || !c.Equals(regeneratedLink.(cidlink.Link).Cid) { log.Errorw("Regeneration of entries link from multihash iterator did not match the original link. Check that multihash iterator consistently returns the same entries for the same key.", "want", lnk, "got", regeneratedLink) - return nil, ErrEntriesLinkMismatch + if e.skipMultihashMismatchErros { + return nil, ipld.ErrNotExists{} + } else { + return nil, ErrEntriesLinkMismatch + } } } else { log.Debugw("Found cache entry for CID", "cid", c) diff --git a/engine/options.go b/engine/options.go index 20d6b7f4..58e8e06d 100644 --- a/engine/options.go +++ b/engine/options.go @@ -101,6 +101,8 @@ type ( purgeCache bool chunker chunker.NewChunkerFunc + skipMultihashMismatchErros bool + syncPolicy *policy.Policy } ) @@ -442,3 +444,13 @@ func WithExtraGossipData(extraData []byte) Option { return nil } } + +// WithSkipMultihashMismatchErros instructs the underlying link system to skip multihash mismatch errors +// and return ipld.ErrNotExists if such occur. ipld.ErrNotExists is treated as content not found and will result to +// 404 returned back to IPNI. +func WithSkipMultihashMismatchErros(b bool) Option { + return func(o *options) error { + o.skipMultihashMismatchErros = b + return nil + } +}