Skip to content
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

Sort map keys according to RFC7049 & DAG-CBOR strict ordering #42

Closed
wants to merge 1 commit into from

Conversation

rvagg
Copy link
Contributor

@rvagg rvagg commented Aug 25, 2020

I know this is disruptive where maps are used, and very late for Filecoin, so obviously proceed with caution.

This adds proper RFC7049 map key sorting, to both bare maps and structs in map representation. The other DAG-CBOR codec implementations strictly sort by length first, then bytes, as per https://github.com/ipld/specs/blob/master/block-layer/codecs/dag-cbor.md#strictness. The current implementation will render CBOR that won't produce stable CIDs with a round-trip using another DAG-CBOR encoder.

Illustrated by a failed round-trip attempt on this:

genesis_keysort

@Stebalien
Copy link
Collaborator

While the genesis block issue isn't actually related to this, I don't think we use maps as a part of consensus so this might not be too problematic. And I agree not having canonical CBOR would be unfortunate.

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