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

Mention if duplicates are allowed in maps in the CDDL files #4335

Open
itsfarseen opened this issue May 16, 2024 · 2 comments
Open

Mention if duplicates are allowed in maps in the CDDL files #4335

itsfarseen opened this issue May 16, 2024 · 2 comments
Labels
cddl Issues related to cddl specification conway

Comments

@itsfarseen
Copy link

In conway.cddl, there are many types which are maps.
As per CDDL spec, maps are allowed to have duplicate keys.
But the node doesn't allow duplicate keys in some places, and allows in some other places.

For example, the multiasset type is defined as a map:

multiasset<a> = { + policy_id => { + asset_name => a } }

The mint type, which is an instance of multiasset, can have duplicate keys.

mint = multiasset<nonZeroInt64>

But the multiasset field of the value type can't have.

value = coin / [coin, multiasset<positive_coin>]

It would be helpful for library/tools authors to have comments in the CDDL file around map types, describing whether duplicate keys are allowed or not.

@lehins
Copy link
Collaborator

lehins commented May 21, 2024

Duplicate keys are not allowed in any of the maps in cbor, simply because the mapping must be unique from keys to values. The difference is in some cases we fail hard on duplicates while in others we discard the duplicate mapping from the map. It is a bit unfortunate, but it has to do with the limitation of current implementation of serialization that we have (See #4009). Although we do have strong plans on fixing it throughout all of the ledger types.
As far as the tooling is concerned, IMHO it should not allow duplicate keys, because that is the ultimate goal. That being said, I am totally for documenting this discrepancy for every map/set occurrence in the cddl

@lehins lehins added this to Conway May 21, 2024
@github-project-automation github-project-automation bot moved this to To do in Conway May 21, 2024
@lehins lehins added the conway label May 21, 2024
@lehins lehins added the cddl Issues related to cddl specification label Aug 8, 2024
@lisicky
Copy link

lisicky commented Sep 5, 2024

@lehins, could you also provide documentation on how map duplicates are handled in each case? Additionally, could you explain how the discard logic will work? Will it retain the first or the last value, and will it be sorted, etc.?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cddl Issues related to cddl specification conway
Projects
Status: To do
Development

No branches or pull requests

3 participants