Skip to content

Expose provider record TTL as options#1237

Merged
guillaumemichel merged 2 commits intolibp2p:masterfrom
phillebaba:feature/provider-ttl-option
Mar 4, 2026
Merged

Expose provider record TTL as options#1237
guillaumemichel merged 2 commits intolibp2p:masterfrom
phillebaba:feature/provider-ttl-option

Conversation

@phillebaba
Copy link
Contributor

This change exposes address TTL and provide validity as options in the provider manager, making it possible to configure these settings per instance. It also fixes the provider record returned by the cache to filter expired records before returning. This ensures that expired records are not returned if garbage collection has not been run yet.

Fixes #1228

@phillebaba
Copy link
Contributor Author

I am unsure if it is better to split this up into separate PRs, it was a bit hard making the changes as they are all related to each other. Let me know if it is better to keep things in smaller changes.

Copy link
Collaborator

@guillaumemichel guillaumemichel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @phillebaba, it looks good! Just 1 line to fix

Signed-off-by: Philip Laine <philip.laine@gmail.com>
@phillebaba
Copy link
Contributor Author

@guillaumemichel addressed your issue and expanded some of the TTL test because I realized the cache invalidation wasn't actually being tested with the original test. I also exposed the provider manager options as a DHT option. Similar to how swarm options are exposed in the host. I hope that is an ok solution.

@phillebaba phillebaba force-pushed the feature/provider-ttl-option branch from 9b40b64 to 1d7ff4e Compare March 3, 2026 08:46
@guillaumemichel
Copy link
Collaborator

Exposing the options is OK, thanks!

@phillebaba there seems to be a race in the newly introduced test. Could you please take a look?

@gammazero gammazero added the status/in-progress In progress label Mar 3, 2026
@phillebaba
Copy link
Contributor Author

I realize now what is going on. AddProvider is eventually consistent. I didn't think about the logic properly until now, which explains why my lazy time.Sleep solution works but causes a data race. The add only blocks until the channel is consumed not until the record has been added to the cache and store.

Without doing some major re-work I cant really see an easy fix for this. I think we either remove that part of the test for now or do something about it. I question how worth the work is considering the plans to refactor provider manager in the future.

@guillaumemichel
Copy link
Collaborator

Refactored TestProvidesCacheExpire to use testing/synctest to fake time and ensure AddProvider is fully done before continuing. It also allows to test with higher validity and cleanup intervals without CI taking too long to run the test.

Everything looks good now, merging.

Thank you for the contribution @phillebaba!

@guillaumemichel guillaumemichel merged commit 15f0b42 into libp2p:master Mar 4, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Configurable provider record TTL

3 participants