-
Notifications
You must be signed in to change notification settings - Fork 249
feat: Reprovide Sweep #1082
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
guillaumemichel
wants to merge
126
commits into
master
Choose a base branch
from
reprovide-sweep
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
feat: Reprovide Sweep #1082
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4e3c483
to
d16f5b2
Compare
6cad84d
to
9bd54ba
Compare
9bd54ba
to
9b5bb41
Compare
8129731
to
b060d52
Compare
cc979b9
to
66ab0a4
Compare
a9c7270
to
0f045de
Compare
This was referenced Jul 22, 2025
eb43269
to
20e658f
Compare
fa69218
to
3642888
Compare
3642888
to
c4f311a
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Note
This PR may be replaced by
Summary
Problem
Reproviding many keys to the DHT one by one is inefficient, because it requires a
GetClosestPeers
(orGCP
) request for every key.Current state
Currently, reprovides are managed in
boxo/provider
. EveryReprovideInterval
(22h
in Amino DHT), all keys matching the reprovide strategy are reprovided at once. The process is slightly different depending on whether the accelerated DHT client is enabled.Default DHT client
All the keys are reprovided sequentially, using the
go-libp2p-kad-dht
Provide() method. This operation consists in finding thek
closest peers to the given key, and then request them all to store the associated provider record.The process is expensive because it requires a
GCP
for each key (opening approx. 20-30 connections). Timeouts due to unreachable peers make this process very long, resulting in a mean of ~10s in provide time (source: probelab.io 2025-06-13).With 10 seconds per provide, a node using this process could reprovide less than 8'000 keys over the reprovide interval of 22h (using a single thread).
Accelerated DHT client (
fullrt
)The accelerated DHT client periodically (every 1h) crawls the DHT swarm to cache the addresses of all discovered peers. It allows it to skip the GCP during the provide request, since it already knows the
k
closest peers and the associated multiaddrs.Hence, the accelerated DHT client is able to provide much more keys during the reprovide interval compared with the default DHT client. However, crawling the DHT swarm is an expensive operation (networking, memory), and since all the keys are reprovided at once, the node will experience a bust period until all keys are reprovided.
Ideally, nodes wouldn't have to crawl the swarm to reprovide content, and the reprovide operation could be smoothed over time to avoid a bust during which the libp2p node is incapable of performing other actions.
Pooling Reprovides
If there are more keys to be reprovided than the number of nodes in the DHT swarm divided by the replication factor (
k
), then it means that there are at least two keys that will be provided to the exact same set of peers. This means that the number ofGCP
is less than the number of keys to reprovide.For the Amino DHT, containing ~10k DHT servers and having a replication factor of 20, pooling reprovides becomes efficient starting from 500 keys.
Reprovide Sweep
The current process of reproviding all keys at once is bad because it creates a bust. In order to smooth the reprovide process, we can sweep the keyspace from left to right, in order to cover all peers over time. This consists of exploring keyspace regions, corresponding to a set of peers that are close to each other in the Kademlia XOR distance metric.
A keyspace region is explored using a few (typically 2-4 GCP) to discover all the peers it contains. A keyspace region can be identified by a Kademlia identifier prefix, the kademlia identifiers of all peers within this region start with the region's prefix.
Once a region is fully explored, all the keys matching the keyspace region's prefix can be allocated to this set of peers. No additional GCP is needed.
Implementation
This PR contains an implementation of the Reprovide Sweep strategy. The
SweepingReprovider
basically does the following:Provide()
andProvideMany()
methods. All cids passed through this methods are provided to the DHT as expected.Features
ResetReprovideSet
method to replace the cids that must be reprovided.Missing features
trie.Trie
in memory containing all cids to be reprovidedprefix
->timestamp
).lastProvided
->[prefix, timestamp]
)cid
->timestamp
). These can {expire, be garbage collected} afterreprovideInterval
.Provide()
Provide(cidA)
beforeProvide(cidB)
doesn't mean thatcidA
will be provided beforecidB
)[ ] The Dual DHT (used by Kubo) currently has 1SweepingReprovider
for each DHT (LAN and WAN)Allow theSweepingReprovider
to (re)provide content to multiple DHT swarms with a single scheduler and cids store (trie)It means that pending regions/cids have to be distinct for each swarm since provide could work for a swarm, but fail in another oneIt will probably require multipleConnectivityCheckers
, one for each DHT swarm.ReprovideSweeper
s is the set of cids that needs to be reprovided (datastore).kubo
get rid of theboxo/provider.System
implementation ingo-libp2p-kad-dht/dual/reprovider.go
TODO
go-libp2p-kad-dht/reprovider/README.md
kubo
feat: DHT Reprovide Sweep ipfs/kubo#10834Admin
Depends on:
Need new release of:
Closes #824
Part of ipshipyard/roadmaps#6, ipshipyard/roadmaps#7, ipshipyard/roadmaps#8