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.
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
feat: add cache control to IPNS #473
feat: add cache control to IPNS #473
Changes from 2 commits
afa9785
259fd98
0539d9e
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a sense, we're breaking from the IPNS spec by not respecting the TTL value:
This is somewhat related to this PR. If we were to respect the TTL, we could apply TTL logic when
nocache
is undefined. However this would also require us to store a timestamp when we resolve the record the first time. Sounds like something for a separate PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to address this now, in this PR. I am afraid if we don't leverage TTL in caching decision here, we will have users complaining that "(JS-)IPNS is slow" because the result will be cached until signature is valid, which is usually 2 days. So for 2 days you get no updates.
Adding TTL-awareness is not hard, instead of caching record, cache object with timestamp field
{ record, cacheEOL }
wherecacheEOL
ismin((now()+record-ttl) ,record-validity-expiration)
, and then when reading a cached entry back, ignore it ifnow()>cacheEOL
.Prior art in
boxo/namesys/ipns_resolver#calculateBestTTL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nocache
isundefined
by default, so the local datastore is queried first. If the record is present, andipnsValidator
does not throw (e.g. it's structurally valid and we are within the TTL), the record is returned.I think you mean "while TTL is valid", please correct me if I'm wrong.
I'm a little confused here, as I read it, this is by design:
So you don't check for updates while the TTL is valid. If you want to bypass the cache and check for updates, pass
nocache: true
.If boxo is doing something else, then it's not following the spec, or the spec needs to be updated to say that we should check for updates every time.
Also, the suggested default in the spec is one hour, not two days?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IPNS Records have two values:
What I meant is that as far I can see,
#findIpnsRecord
has no concept of cache expiration based on TTL (if it happens on different abstraction later, lmk where). When TTL is not implemented for caching, Signature Validity takes its place and you get "IPNS is slow (to update)" behavior:this.localStore
this.localStore
But I don't think we should block on this, over-caching is better than no caching, and TTL support can be added in follow-up PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we don't store something like
cacheEOL
orstoredAt
timestamp, then we have no way to, as Daniel first mentioned, "[respect] the TTL value", or am I missing something?this is the current flow:
requesting record for the first time
later requests for record (with default nocache=undefined)
we essentially need a check between 1 & 2 of
later requests for record
that will check if the record is expired.. unless this.localStore is already handling expiry, but it doesn't seem like it is:we have no calls to
remove
, and localStore doesn't have any methods other thanput
/get
/has
, and nothing called on the datastore (given in localStore creation) other thanput
/get
/has
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's also my understanding. @SgtPooki's summed it up nicely.
Either, no need to block this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we remove it from the cache? or are we waiting on it being overwritten with later processing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we already did the work and confirmed it is invalid, removing it sgtm
Check warning on line 560 in packages/ipns/src/index.ts
Codecov / codecov/patch
packages/ipns/src/index.ts#L560