Skip to content

IPIP-550: PBNode field ordering - #550

Open
achingbrain wants to merge 9 commits into
mainfrom
ipip-550-pbnode-field-ordering
Open

IPIP-550: PBNode field ordering#550
achingbrain wants to merge 9 commits into
mainfrom
ipip-550-pbnode-field-ordering

Conversation

@achingbrain

Copy link
Copy Markdown
Member

Having Link messages before the Data message in PBNode messages means for HAMT shards you have to read every Link before you can process any of them, since the hash type/fanout values used to calculate the prefix each directory entry has is stored in the Data field at the end of the message.

This IPIP suggests allowing writers to encode the Data field first, this allows readers to use streaming parsers that can skip out on reading links if they have already reached the directory entry they are interested in.

Further discussion can be found in #533

@achingbrain
achingbrain requested a review from a team as a code owner August 24, 2026 13:20
@github-actions

github-actions Bot commented Aug 24, 2026

Copy link
Copy Markdown

🚀 Build Preview on IPFS ready

  • 🔎 Commit: b707207
  • 🔏 CID bafybeiaogevns7gp3m6dwrur7be357gx4ikf2spgd73jl52kpz5ezkluhm
  • 📦 Preview:

Having `Link` messages before the `Data` message in `PBNode` messages
means for HAMT shards you have to read every `Link` before you can
process any of them, since the hash type/fanout values used to
calculate the prefix each directory entry has is stored in the `Data`
field at the end of the message.

This IPIP suggests allowing writers to encode the `Data` field first,
this allows readers to use streaming parsers that can skip out on
reading links if they have already reached the directory entry they
are interested in.

Further discussion can be found in #533
@achingbrain
achingbrain force-pushed the ipip-550-pbnode-field-ordering branch from 37fdb60 to 51f16e3 Compare August 24, 2026 13:48

@lidel lidel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, left some quick first-pass drive-by comments below.

Comment thread src/ipips/ipip-0550.md Outdated
Comment thread src/unixfs.md Outdated
Comment thread src/ipips/ipip-0550.md Outdated
Comment thread src/ipips/ipip-0550.md
achingbrain added a commit to ipld/ipld that referenced this pull request Aug 25, 2026
Writing the `Links` first makes reading HAMT data more expensive
since, if you are only trying to read a certain path, you have to
read all of the `Links` before you can process any of them, as the
config needed to calculate the hash prefix length is stored in the
`Data` field at the end of the message.

Swap the fields round so `Data` can be read before `Links`.

Further discussion: ipfs/specs#533
IPIP: ipfs/specs#550
lidel added a commit to ipfs/gateway-conformance that referenced this pull request Aug 27, 2026
* feat: tests for IPIP-550 PBNode field ordering

Gateways must resolve UnixFS content regardless of PBNode field
order: the legacy Links-first encoding and the Data-first order
proposed for the unixfs-v1-2026 profile.

- fixtures: pbnode-field-orders.car, single-entry Directory and
  HAMTShard in both orders, byte-identical to the IPIP table
- tests: path resolution through all four roots, raw block
  responses byte-exact for all five blocks

Refs ipfs/specs#550

* chore: changelog entry under v0.14.1
Make the Data-first ordering opt-in per profile and align the
text with DAG-PB codec behavior.

- unixfs.md: Profiles registry section with names implementations
  SHOULD use; both PBNode orderings with reader/writer rules and
  UnixFS precedence over the legacy DAG-PB codec spec; data-first
  test vectors in the appendix
- ipip-0550: accurate motivation and compatibility, PBNode field
  order profile parameter (links-first default), two-way security
  notes, alternatives, fixtures relabeled and linked to tagged
  gateway-conformance v0.14.1 CARs, working code links
@lidel

lidel commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Pushed 17444ef and b707207: the ordering is now defined per profile. Does this look sensible @achingbrain?

unixfs.md gains a Profiles registry (unixfs-v0-2015, unixfs-v1-2025, unixfs-v1-2026) showing both PBNode orderings with reader/writer rules, and Compatibility now matches DAG-PB codec behavior: decoders already accept both orders, and for UnixFS data this spec takes precedence on the write side.

Working code in Go:

That makes ratification relatively low-risk: whoever needs the streaming-friendly order can lock it in via the profile, and everyone else, legacy DAGs and libraries included, keeps preexisting behavior.

@achingbrain

Copy link
Copy Markdown
Member Author

Thanks for the updates, all looks good to me.

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