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:
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.
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: