From 041ae0273bec3b4af9a2eb95d49b413411ef2936 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Fri, 14 Nov 2025 00:12:27 +0100 Subject: [PATCH] fix(add): respect Provide config in fast-provide-root fast-provide-root should honor the same config settings as the regular provide system: - skip when Provide.Enabled is false - skip when Provide.DHT.Interval is 0 - respect Provide.Strategy (all/pinned/roots/mfs/combinations) This ensures fast-provide only runs when appropriate based on user configuration and the nature of the content being added (pinned vs unpinned, added to MFS or not). --- core/commands/add.go | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/core/commands/add.go b/core/commands/add.go index e191eb24e..2eb18a2e7 100644 --- a/core/commands/add.go +++ b/core/commands/add.go @@ -602,7 +602,43 @@ https://github.com/ipfs/kubo/blob/master/docs/config.md#import // Apply fast-provide-root if the flag is enabled if fastProvideRoot && (lastRootCid != path.ImmutablePath{}) { - if ipfsNode.HasActiveDHTClient() { + cfg, err := ipfsNode.Repo.Config() + if err != nil { + return err + } + + // Parse the provide strategy to check if we should provide based on pin/MFS status + strategyStr := cfg.Provide.Strategy.WithDefault(config.DefaultProvideStrategy) + strategy := config.ParseProvideStrategy(strategyStr) + + // Determine if we should provide based on strategy + shouldProvide := false + if strategy == config.ProvideStrategyAll { + // 'all' strategy: always provide + shouldProvide = true + } else { + // For combined strategies (pinned+mfs), check each component + if strategy&config.ProvideStrategyPinned != 0 && dopin { + shouldProvide = true + } + if strategy&config.ProvideStrategyRoots != 0 && dopin { + shouldProvide = true + } + if strategy&config.ProvideStrategyMFS != 0 && toFilesSet { + shouldProvide = true + } + } + + switch { + case !cfg.Provide.Enabled.WithDefault(config.DefaultProvideEnabled): + log.Debugw("fast-provide-root: skipped", "reason", "Provide.Enabled is false") + case cfg.Provide.DHT.Interval.WithDefault(config.DefaultProvideDHTInterval) == 0: + log.Debugw("fast-provide-root: skipped", "reason", "Provide.DHT.Interval is 0") + case !shouldProvide: + log.Debugw("fast-provide-root: skipped", "reason", "strategy does not match content", "strategy", strategyStr, "pinned", dopin, "to-files", toFilesSet) + case !ipfsNode.HasActiveDHTClient(): + log.Debugw("fast-provide-root: skipped", "reason", "DHT not available") + default: rootCid := lastRootCid.RootCid() if fastProvideWait { @@ -627,8 +663,6 @@ https://github.com/ipfs/kubo/blob/master/docs/config.md#import } }() } - } else { - log.Debugw("fast-provide-root: skipped", "reason", "DHT not available") } } else if fastProvideWait && !fastProvideRoot { // Log that wait flag is ignored when provide-root is disabled