Skip to content

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

Closed
rvagg wants to merge 1 commit intowhyrusleeping:masterfrom
rvagg:rvagg/RFC7049_keysort
Closed

Sort map keys according to RFC7049 & DAG-CBOR strict ordering#42
rvagg wants to merge 1 commit intowhyrusleeping:masterfrom
rvagg:rvagg/RFC7049_keysort

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