Pull second copies from `/download` with per-piece FOC grants
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
- Issue type
- Feature
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- typescript
- Domain
- backend-api-design
Research direction
Start with manager.ts at the batched and unbatched pull paths, then trace createPieceUrlPDP, createPullBatcher, pullPieces, and the upload and StorageContext.pull options. Read pull-pieces.ts around line 242 and the existing MSW pull tests to understand body retries and status polls. Done means both pull paths build grant-aware /download sources lazily, preserve extraData on resends, avoid new grants during polls, and scrub grants from errors and callbacks.
Written by the indexing model from the issue text.
Description
Description
Secondary pulls always use /public/{cid} source URLs, built with createPieceUrlPDP. That is true on both the batched path (manager.ts:605, the default) and the unbatched one (manager.ts:760). A restricted piece (#1197) is not served on /public, so a secondary can only copy it from /download/{cid}, with a FOC grant.
filecoin-project/curio#1643 accepts that grant on a pull as basic-auth userinfo on each source URL. The username is FOC Grant (or FOC%20Grant) and the password is the token, which must not be empty (pdp/pull_grant_url.go). Curio keeps a URL that already carries userinfo as it is, sends the grant to the primary as basic auth, and redacts it from its logs.
This issue adds the grant-aware pull path without turning it on. Nothing changes until #1197 passes a read mode and a grant.
Proposed solution
- URLs. Give
createPieceUrlPDPa read mode, or add a/downloadbuilder next to it. Restricted gives/download/{cid}; absent or public gives/public/{cid}, as today. - Grant callback. Add an optional
getGrant(pieceCid) => Promise<string>:- Where it goes: on each call's options (
upload,StorageContext.pull, and corecreatePullBatcher/pullPieces), and passed on to replacement secondaries. Don't store it on the context:StorageManagerreuses cached default contexts when copies, exclusions and metadata match (manager.ts:1158-1170), so a callback stored on the context would leak into later calls that pass a different one. - What it returns: exactly what keysmith's
authorizationHeader()returns (FOC-Grant <base64url>). The SDK strips the prefix. - What it signs: the same PieceCIDv2 that appears in the URL.
- Lifetime: sign pull grants with
expiresIn = MAX_REQUEST_LIFETIME(300 s). Keysmith and Curio both accept up to 300 s plus 60 s of clock skew.
- Where it goes: on each call's options (
- Source URL:
https://FOC%20Grant:<token>@<primary>/download/<cid>. - Lazy sources.
PullSourceandPullBatchInput.sourceUrlaccept a lazy, async source. Widening these types is additive for callers. - When grants are made.
- Create them when the pull body is built, after
extraDatais signed, onegetGrantcall at a time per batch. A batch holds at most 10 pieces (PULL_BATCH_SIZE). - Rebuild the body only for resends Curio did not accept (429 or 5xx). Curio sends a 429 before it stores anything.
- Keep
extraDataunchanged on every resend. It is Curio's idempotency key, and a 5xx can arrive after Curio has already accepted the pull. In that case Curio returns the existing pull and ignores the new URLs, so its stored grants are the originals. - Status polls reuse the accepted body. Today iso-web resends one fixed body (
pull-pieces.ts:242), so the 429 loop moves out of iso-web's retry.
- Create them when the pull body is built, after
- Scrubbing. A Curio 400 can echo the source URL. That text reaches
PullError.details, andPullError.fromHttpErroralso keeps theHttpError(with the response) ascause; from there it reachesonCopyFailedandfailedAttempts. RemoveFOC%20Grant:…@userinfo before thePullErroris built, from both the details and the cause. Returned URLs never contain a grant.
Done criteria
- With no read mode and no
getGrant, pull URLs and request bodies are byte-for-byte what they are today - A
/downloadsource URL carries one grant per piece, signed for the same PieceCIDv2 that is in the URL - Batched and unbatched pulls both accept lazy, async sources
- Status polls never create new grants; resends Curio did not accept do, and every resend keeps the same
extraData - A cached default context never uses a previous call's
getGrant - No grant appears in returned URLs,
PullError(details orcause),onCopyFailedorfailedAttempts - MSW pull mocks capture
sourceUrl; tests cover both URL forms, the poll and resend rules, and scrubbing
Trade-offs and risks
- Grant lifetime. If the secondary's queue time plus Curio's retries (3 attempts, 30 s then 2 min apart) outlast the grant, the primary returns 403. Curio treats that as permanent, and the copy fails. Longer pull grants would need a Curio change.
- Wallet prompts. Each grant is one
signTypedData. Callers should sign with a session or delegated key, not a wallet.
Notes
- Can land before Curio releases #1643, because the path is off by default.
- Part of #1088. Prerequisite for #1197. Downloads with grants: #1193.
- Curio: filecoin-project/curio#1643 (grants on pulls), #1660 (design).
- Dominant language
- TypeScript
- Stars
- 27
- Forks
- 36
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 65
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from FilOzone/synapse-sdk
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
FilOzone/synapse-sdk#1201 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
FilOzone/synapse-sdk#1198 · 1 comment ·
Maintainers usually reply within 1 day
-
Clarify add pieces and create set can be made concurrentlyPossibly taken @hugomrdias claimed this 22 days ago. Opengood first issue
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
FilOzone/synapse-sdk#749 · 1 comment · 1 assignee ·
Maintainers usually reply within 1 day
-
Upload to restricted data sets with `read: "restricted"`Possibly taken @JAG-UK claimed this today. Open
Difficulty 5/5 Over a week Newbie friendliness 25/100
FilOzone/synapse-sdk#1197 · 2 comments ·
Maintainers usually reply within 1 day
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 72/100
FilOzone/synapse-sdk#1195 · 1 comment ·
Maintainers usually reply within 1 day
All issues in FilOzone/synapse-sdk
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
zabuton-app/meguri#875 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 86/100
iruzen-dono/workless#117 ·
Maintainers usually reply within 1 day
-
area:api area:web wave wave:trivial
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
vetro-protocol/vetro-monorepo#1321 ·
Maintainers usually reply within 1 day