-
Notifications
You must be signed in to change notification settings - Fork 165
Rename CDDL fields to better reflect their origin and be more reusable #5339
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
base: master
Are you sure you want to change the base?
Conversation
9594784 to
e2e3e15
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from the potential irregularity I commented on, this refactoring seems like it should make no difference to the CDDL.
Perhaps the test failures are due to the issue I pointed out?
| protocol_version = (major_protocol_version, uint) | ||
| protocol_version = [major_protocol_version, uint] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change from group to array seems significant. However, I don't see any change in the .hs that matches this. I wonder where it's coming from?
I saw the same difference in some of the other eras.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a first pass and left some comments.
In addition, I'm also wondering if it's beneficial to remove the distinction between the types in cddl that represent hashes vs just bytes (so the replacement of hash32 with bytes32).
Even though they boil down to the same thing, it might bring some value to distinguish them? What do you think?
| MultiSig, | ||
| ProposedPPUpdates, | ||
| Update, | ||
| -- Update, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Presumably left by accident
| -- Update, |
| pint :: Rule | ||
| pint = "pint" =:= (1 :: Integer) ... max_word64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this is an improvement, to me it seems less consistent (since we still have nonnegative_interval and positive_coin. I would prefer the longer "positive_" prefix for all of the above, but would be good to know what others think about it
| posWord32 :: Rule | ||
| posWord32 = "posWord32" =:= (1 :: Integer) ... maxWord32 | ||
| pword32 :: Rule | ||
| pword32 = "pword32" =:= (1 :: Integer) ... max_word32 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the p or positive prefix necessary for word? I would have thought it's implied that it's positive, since Word is unsigned, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Word implies that it is non-negative 😉 which is different from positive.
On a different note, I believe posWord/pos_word or even positiveWord/positive_word would be better prefixes than just p
| transaction_ix :: Rule | ||
| transaction_ix = "transaction_ix" =:= VUInt `sized` (2 :: Word64) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is better than what we have now, transaction_index. Is it in order to be more consistent with the code? Or any other reason in particular for this abbreviation?
|
|
||
| negInt64 :: Rule | ||
| negInt64 = "negInt64" =:= minInt64 ... (-1 :: Integer) | ||
| nint64 :: Rule |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as before about pint - i think negative_int64 is better, less vague, easier to find, consistent with others like nonzero-int64
| |] | ||
| $ "script_hash" =:= hash28 | ||
| shelley_epoch :: Rule | ||
| shelley_epoch = "epoch" =:= VUInt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit strange - isn't it the same for all eras? Seems more like something for core to me - any reason to have it shelley-specific?
| script_pubkey :: Named Group | ||
| script_pubkey = "script_pubkey" =:~ grp [0, a addr_keyhash] | ||
|
|
||
| epoch :: Rule | ||
| epoch = "epoch" =:= VUInt | ||
| script_all :: Named Group | ||
| script_all = "script_all" =:~ grp [1, a (arr [0 <+ a shelley_native_script])] | ||
|
|
||
| genesis_delegate_hash :: Rule | ||
| genesis_delegate_hash = "genesis_delegate_hash" =:= hash28 | ||
| script_any :: Named Group | ||
| script_any = "script_any" =:~ grp [2, a (arr [0 <+ a shelley_native_script])] | ||
|
|
||
| genesis_hash :: Rule | ||
| genesis_hash = "genesis_hash" =:= hash28 | ||
| script_n_of_k :: Named Group | ||
| script_n_of_k = "script_n_of_k" =:~ grp [3, "n" ==> VUInt, a (arr [0 <+ a shelley_native_script])] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer here to be so consistent and explicit at the cost of verbosity and use native_script prefix instead of script , both in the name of the rules and in the keys - but curious to know what others think about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
100% agree
| shelley_nonce :: Rule | ||
| shelley_nonce = "nonce" =:= arr [0] / arr [1, a (VBytes `sized` (32 :: Word64))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also seems era-generic, I think it would be better in core and called "nonce"
| allegra_script_all :: Named Group | ||
| allegra_script_all = "script_all" =:~ grp [1, a (arr [0 <+ a allegra_native_script])] | ||
|
|
||
| script_any :: Named Group | ||
| script_any = "script_any" =:~ grp [2, a (arr [0 <+ a native_script])] | ||
| allegra_script_any :: Named Group | ||
| allegra_script_any = "script_any" =:~ grp [2, a (arr [0 <+ a allegra_native_script])] | ||
|
|
||
| script_n_of_k :: Named Group | ||
| script_n_of_k = "script_n_of_k" =:~ grp [3, "n" ==> int64, a (arr [0 <+ a native_script])] | ||
| script_n_of_k = "script_n_of_k" =:~ grp [3, "n" ==> int64, a (arr [0 <+ a allegra_native_script])] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we could parameterize these rules by the native_script rule, and then use them in each era with the respenctive native_script definition
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a great idea!
| allegra_script_pubkey :: Named Group | ||
| allegra_script_pubkey = "script_pubkey" =:~ grp [0, a addr_keyhash] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the same as in shelley, don't think there is a point to redefine it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only took a quick look at this PR. I'll do a more thorough review tomorrow.
|
|
||
|
|
||
| hash32 = bytes .size 32 | ||
| bytes32 = bytes .size 32 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was hash switched to bytes? It is really good to indicate that it is not some bytes but a hash
| auxiliary_data = | ||
| metadata | ||
| / [transaction_metadata : metadata, auxiliary_scripts : auxiliary_scripts] | ||
| shelley_auxiliary_data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is incorrect. It just so happens that in Shelley auxiliary_data is set to just metadata. But metadata is it own concept: Map Word64 Metadatum
| shelley_auxiliary_data | |
| metadata |
| allegra_script_all :: Named Group | ||
| allegra_script_all = "script_all" =:~ grp [1, a (arr [0 <+ a allegra_native_script])] | ||
|
|
||
| script_any :: Named Group | ||
| script_any = "script_any" =:~ grp [2, a (arr [0 <+ a native_script])] | ||
| allegra_script_any :: Named Group | ||
| allegra_script_any = "script_any" =:~ grp [2, a (arr [0 <+ a allegra_native_script])] | ||
|
|
||
| script_n_of_k :: Named Group | ||
| script_n_of_k = "script_n_of_k" =:~ grp [3, "n" ==> int64, a (arr [0 <+ a native_script])] | ||
| script_n_of_k = "script_n_of_k" =:~ grp [3, "n" ==> int64, a (arr [0 <+ a allegra_native_script])] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a great idea!
| / sarr | ||
| [ "transaction_metadata" ==> metadata | ||
| , "auxiliary_scripts" ==> auxiliary_scripts | ||
| [ "transaction_metadata" ==> shelley_auxiliary_data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, yeah, this should be metadata
| [ "transaction_metadata" ==> shelley_auxiliary_data | |
| [ "transaction_metadata" ==> metadata |
| shelley_auxiliary_data :: Rule | ||
| shelley_auxiliary_data = | ||
| "shelley_auxiliary_data" | ||
| =:= mp [0 <+ asKey shelley_transaction_metadatum_label ==> transaction_metadatum] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is how I would write it:
| shelley_auxiliary_data :: Rule | |
| shelley_auxiliary_data = | |
| "shelley_auxiliary_data" | |
| =:= mp [0 <+ asKey shelley_transaction_metadatum_label ==> transaction_metadatum] | |
| metadatum :: Rule | |
| metadatum = | |
| "metadatum" | |
| =:= smp [0 <+ asKey metadatum ==> metadatum] | |
| / sarr [0 <+ a metadatum] | |
| / VInt | |
| / (VBytes `sized` (0 :: Word64, 64 :: Word64)) | |
| / (VText `sized` (0 :: Word64, 64 :: Word64)) | |
| metadatum_label :: Rule | |
| metadatum_label = "metadatum_label" =:= VUInt | |
| metadata :: Rule | |
| metadata = "metadata" =:= mp [0 <+ asKey metadatum_label ==> metadatum] | |
| shelley_auxiliary_data :: Rule | |
| shelley_auxiliary_data = "auxiliary_data" =:= metadata |
I'd also put metadata in core and then reuse it in other eras, instead of shelley_auxiliary_data.
| nonnegative_interval = #6.30([uint, pint]) | ||
|
|
||
| positive_int = 1 .. maxWord64 | ||
| pint = 1 .. max_word64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
positive_ is a much better prefix than p. Otherwise someone might think it is a definition for a pint of beer or something 🤣
| pint = 1 .. max_word64 | |
| positive_int = 1 .. max_word64 |
| ; "\x02" for Plutus V2 scripts | ||
| ; "\x03" for Plutus V3 scripts | ||
| script_hash = hash28 | ||
| ; "\x04" for Plutus V4 scripts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is something definitely wrong with this comment. Tags for plutus scripts should not be relevant for Allegra CDDL
Description
This addresses the initial part of #5194 .
Follow-up PRs would be to actually address the heart of #5194 to reduce duplication to a minimum.
Checklist
CHANGELOG.mdfiles updated for packages with externally visible changes.NOTE: New section is never added with the code changes. (See RELEASING.md).
.cabalandCHANGELOG.mdfiles when necessary, according to theversioning process.
.cabalfiles updated when necessary.NOTE: If bounds change in a cabal file, that package itself must have a version increase. (See RELEASING.md).
scripts/fourmolize.sh).scripts/cabal-format.sh).scripts/gen-cddl.sh)hie.yamlupdated (usescripts/gen-hie.sh).