-
Notifications
You must be signed in to change notification settings - Fork 32
feat: check if CID exists in local store #1331
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
Conversation
emizzle
left a comment
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.
Awesome, thank you for doing that Arnaud!
marcinczenko
left a comment
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.
Thanks!
tests/codex/node/testnode.nim
Outdated
| for blk in blocks: | ||
| check not (await blk.cid in localStore) | ||
|
|
||
| test "Should returns true when a cid is already in the local store": |
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.
| test "Should returns true when a cid is already in the local store": | |
| test "Should return true when a cid is already in the local store": |
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.
To use this method in my current CodexClient - the hasLocalBlock needs to be exposed via API - Maybe you can already use in the lib, it would be good to have it available via API as well....
I am using this in codex/rest/api.nim:
router.api(MethodGet, "/api/codex/v1/data/{cid}/has") do(
cid: Cid, resp: HttpResponseRef
) -> RestApiResponse:
## Only test if the give CID is available in the local store
##
var headers = buildCorsHeaders("GET", allowedOrigin)
if cid.isErr:
return RestApiResponse.error(Http400, $cid.error(), headers = headers)
let cid = cid.get()
let hasCid = await node.hasLocalBlock(cid)
let json = %*{$cid: hasCid}
return RestApiResponse.response($json, contentType = "application/json")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.
I'd definitely say let's add this in a commit @marcinczenko. Ok for you @2-towns?
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.
I'd definitely say let's add this in a commit @marcinczenko. Ok for you @2-towns?
I am already on it
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.
Okay so sorry I was already working on it before your message @emizzle.
I pushed with the tests and updated the openapi description.
Don't hesitate next time @marcinczenko to commit / push.
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.
My preference would be to name the endpoint /api/codex/v1/data/{cid}/exists instead of has, but definitely not a blocker for me.
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.
exists sounds indeed more pro, but is harder to type ;)
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.
I have updated CodexClient to use exists API - if everything sounds ok, it should be ok to merge - or maybe we better wait a little bit till I adjust archive downloader?
marcinczenko
left a comment
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.
I think we have all - but as I said, if it is not blocking other things, I would suggest to wait with merging - I am now changing archive downloader to use first only trigger the downloads, then to poll using "exists" API to finally locally fetch.
b2b29fa to
cbe93c5
Compare
A small method that checks if a CID exists in the local store. Useful for integration with
status-goand can be exposed in the Go wrapper.