Skip to content

Conversation

@SgtPooki
Copy link
Member

@SgtPooki SgtPooki commented Aug 5, 2025

Title

fix: do not download all blocks when listing dir

Description

Fixes #260
Related ipfs/helia#836
Related ipfs/js-ipfs-unixfs#439
Related ipfs/js-ipfs-unixfs#440

Notes & open questions

Two things:

  1. There are multiple places where we could potentially use the extended: false option.
  2. Currently there seems to be a bug or problem with using the ipfs-unix-fs exporter with the extended: false option.

Other places we may want to use extended: false

There are multiple places where we use unix-fs-exporter.. these were added and commented out in the initial commit in this PR: e4d7a15 (#261)

./packages/verified-fetch/src/utils/walk-path.ts

const entry of exporterWalk(path, blockstore, options) do we need to call it here?

./packages/verified-fetch/src/plugins/plugin-handle-dag-pb.ts

places where we call () => exporter

Bug with extended: false

Looking at these lines in plugin-handle-dag-pb:

const entry = await handleServerTiming('exporter-dir', '', async () => exporter(`/ipfs/${dirCid}/${rootFilePath}`, helia.blockstore, {
signal: options?.signal,
onProgress: options?.onProgress
}), withServerTiming)
log.trace('found root file at %c/%s with cid %c', dirCid, rootFilePath, entry.cid)

When extended: true, and added a console.log for entry,I get the following output:

  helia:verified-fetch:dag-pb-plugin:trace found directory at bafybeifgpc3zqsh3ftf6u65rwuid2okrc75f7ojxipzyzlfkepzfxhlavm/, looking for index.html +0ms
entry {
  type: 'file',
  name: 'index.html',
  path: 'bafybeifgpc3zqsh3ftf6u65rwuid2okrc75f7ojxipzyzlfkepzfxhlavm/index.html',
  cid: CID(bafybeig6e22n6aozgcfdqlh3ysctvsfwrqi7qa6u4qrafb5pzn3keke6ci),
  content: [AsyncGeneratorFunction: yieldFileContent],
  unixfs: UnixFS {
    type: 'file',
    data: undefined,
    blockSizes: [ 2n, 2n ],
    hashType: undefined,
    fanout: undefined,
    mtime: undefined,
    _mode: 420,
    _originalMode: 0
  },
  depth: 1,
  node: {
    Data: Uint8Array(8) [
       8, 2, 24, 4,
      32, 2, 32, 2
    ],
    Links: [ [Object], [Object] ]
  },
  size: 4n
}
  helia:verified-fetch:dag-pb-plugin:trace found root file at bafybeifgpc3zqsh3ftf6u65rwuid2okrc75f7ojxipzyzlfkepzfxhlavm/index.html with cid bafybeig6e22n6aozgcfdqlh3ysctvsfwrqi7qa6u4qrafb5pzn3keke6ci

When extended: false, I get the following:

  helia:verified-fetch:dag-pb-plugin:trace found directory at bafybeifgpc3zqsh3ftf6u65rwuid2okrc75f7ojxipzyzlfkepzfxhlavm/, looking for index.html +0ms
entry {
  cid: CID(bafybeifgpc3zqsh3ftf6u65rwuid2okrc75f7ojxipzyzlfkepzfxhlavm),
  name: 'bafybeifgpc3zqsh3ftf6u65rwuid2okrc75f7ojxipzyzlfkepzfxhlavm',
  path: 'bafybeifgpc3zqsh3ftf6u65rwuid2okrc75f7ojxipzyzlfkepzfxhlavm'
}
  helia:verified-fetch:dag-pb-plugin:trace found root file at bafybeifgpc3zqsh3ftf6u65rwuid2okrc75f7ojxipzyzlfkepzfxhlavm/index.html with cid bafybeifgpc3zqsh3ftf6u65rwuid2okrc75f7ojxipzyzlfkepzfxhlavm

The exporter is not reporting on the path passed to it.. instead taking the root and seeming to stop. This is tested with:

DEBUG="-mocha*,*,*:trace" npm run test -- -t node -g 'should abort a request while loading file data'

in /packages/verified-fetch

At the most, this seems like a bug.. at the least, it’s unexpected that passing extended: false would change the CID the response is giving back

In summary:

Passing extended: false on a path that exists, <CID>/index.html in this case, to the exporter returns only the CID of the directory, not of the file at the path I give it.

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 linked an issue Aug 5, 2025 that may be closed by this pull request
@SgtPooki SgtPooki marked this pull request as ready for review August 5, 2025 17:22
@SgtPooki SgtPooki requested a review from a team as a code owner August 5, 2025 17:22
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

listing: items.map((item) => {
return {
size: item.size.toString(),
size: item.size?.toString() ?? '?',
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 no longer have the sizes.. we will need to either fetch them with stat or decide on a better default.

@parkan
Copy link

parkan commented Sep 6, 2025

@SgtPooki can I help resolve this with feedback from a user perspective?

@lidel lidel moved this to In Progress in @lidel's IPFS wishlist Sep 9, 2025
@lidel lidel requested a review from achingbrain September 9, 2025 14:10
@SgtPooki
Copy link
Member Author

change in ipfs/js-ipfs-unixfs#440 should fix passing extended: false not returning what we expect

@SgtPooki
Copy link
Member Author

@SgtPooki can I help resolve this with feedback from a user perspective?

@parkan I'm happy to hear about your user perspective, but I think we have the solution in hand.

@SgtPooki
Copy link
Member Author

we chatted about this in ipfs/helia#850 and just setting extended: false in the fall to fs.ls should be sufficient

@SgtPooki
Copy link
Member Author

currently running into issues with gateway conformance hanging.. i'm investigating

@SgtPooki
Copy link
Member Author

tested this branch vs main (using npm run build && DEBUG="*,*:trace" node packages/gateway-conformance/dist/src/demo-server.js).

@parkan let me know if anything seems off here.. Ideally we would add some configurability to the dir-index-html plugin to support getting the sizes of children when necessary..

This PR:

Server timing (1.78s to load large dir)

image

Screenshot

image

Main:

Server timing (times out due to basic-server 10s timeout)

image

Screenshot

image

@SgtPooki SgtPooki merged commit 356e62c into main Sep 15, 2025
21 checks passed
@SgtPooki SgtPooki deleted the 260-bug-fsls-seems-to-query-too-many-blocks branch September 15, 2025 12:59
@github-project-automation github-project-automation bot moved this from In Progress to Done in @lidel's IPFS wishlist Sep 15, 2025
github-actions bot pushed a commit that referenced this pull request Sep 15, 2025
## [@helia/verified-fetch-v3.2.2](https://github.com/ipfs/helia-verified-fetch/compare/@helia/verified-fetch-3.2.1...@helia/verified-fetch-3.2.2) (2025-09-15)

### Bug Fixes

* do not download all blocks when listing dir ([#261](#261)) ([356e62c](356e62c))
@github-actions
Copy link

🎉 This PR is included in version @helia/verified-fetch-v3.2.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@parkan
Copy link

parkan commented Sep 16, 2025

beautiful! will test and report but the numbers are already looking good 👍

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.

bug: fs.ls seems to query too many blocks

3 participants