8000 feat: car export supports custom dag traversal and export by SgtPooki · Pull Request #767 · ipfs/helia · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: car export supports custom dag traversal and export #767

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

Merged
merged 53 commits into from
Apr 18, 2025

Conversation

SgtPooki
Copy link
Member
@SgtPooki SgtPooki commented Mar 14, 2025

Title

feat: support dag-scope

Description

This PR adds support for the dag-scope query parameter to the export and stream methods. This parameter allows the user to specify the scope of the DAG they want to retrieve. The possible values are all, entity, and block. The default value is all.

Also refactored the code quite a bit to support different strategies for walking the dag, and added two new options: dagRoot & knownDagPath.

This code also updates the blockFilter check to occur before the blockstore.get call to prevent potentially unnecessary network calls.

Related ipfs/helia-verified-fetch#198
Related ipfs/service-worker-gateway#356

Notes & open questions

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation if necessary (this includes comments as well)
  • I have added tests that prove my fix is effective or that my feature works

@SgtPooki SgtPooki requested a review from a team as a code owner March 14, 2025 20:24
Copy link
Member Author
@SgtPooki SgtPooki left a comment

Choose a reason for hiding this comment

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

self review

Comment on lines 209 to 212
const isTargetRoot = roots.some(r => r.equals(lastCid))
if (!isTargetRoot) {
throw new Error('knownDagPath must end with one of the target roots')
}
Copy link
Member Author

Choose a reason for hiding this comment

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

we need some solution here to handle multiple roots where there are paths to each root.

I know this sounds confusing, but "root" according to current kubo/boxo is the "target" root block of a dag.. the "dagRoot" is the root of the dag walked to get to that subdag starting node

@SgtPooki
Copy link
Member Author

cspell is yelling about some words in dag-scope.spec.ts

@SgtPooki
Copy link
Member Author

ping @achingbrain @2color I think some other eyes on this would be good, and this is blocking ipfs/service-worker-gateway#356

Copy link
Member
@achingbrain achingbrain left a comment

Choose a reason for hiding this comment

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

Initial pass, need to look in more detail tomorrow

@SgtPooki
6D40 Copy link
Member Author
SgtPooki commented Apr 4, 2025

Ok @achingbrain I've got things refactored to use the traversal and export strategy API you suggested.

One thing I don't like about these changes is that we have to do traversal twice, but if root===target or target===some-leaf-node, it's practically no extra work on either side.

Let me know if you see anything that can be improved.

Copy link
Member Author
@SgtPooki SgtPooki left a comment

Choose a reason for hiding this comment

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

self review

@SgtPooki SgtPooki requested a review from achingbrain April 4, 2025 21:57
@SgtPooki SgtPooki changed the title feat: support dag-scope feat: car export supports custom dag traversal and export Apr 17, 2025
Copy link
Member Author
@SgtPooki SgtPooki left a comment

Choose a reason for hiding this comment

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

some minor nits and cleanup could be done, but makes sense and mostly lgtm

export class BlockExporter implements ExportStrategy {
async * export (cid: CID, block: BlockView<any, any, any, 0 | 1>): AsyncGenerator<CID, void, undefined> {
// don't yield the block, index.ts will add it to the car file and then
// we're done
Copy link
Member Author

Choose a reason for hiding this comment

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

:P

@SgtPooki SgtPooki merged commit 313e2c1 into main Apr 18, 2025
18 checks passed
@SgtPooki SgtPooki deleted the feat/support-dag-scope branch April 18, 2025 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0