-
Notifications
You must be signed in to change notification settings - Fork 155
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
Use Cuddle to define CDDL in Shelley #4552
Conversation
b890871
to
c788d10
Compare
Now that the CDDL is defined with Cuddle, we can begin to properly modularise it. As a first step, we move the common crypto and utility types into the core package.
- Switch existing tests to using the generated CDDL - Add additional Huddle based tests for Shelley types - Add a tool to regenerate the Shelley CDDL from Huddle - Move additional core types to the core CDDL - Make a few fixes in the Shelley Huddle spec There is one unusual thing here: the size bound on the max block header size in the protocol param update. This does not reflect the original CDDL, but it is consistent with the FromCBOR instance and the underlying data type in PParams. I can only assume that the CDDL generator wasn't exploring the whole range and thus never found this error.
Now that Shelley is defined using Huddle, we can rely on the relevant parts from Conway.
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 looks awesome. I am loving seeing CDDL specified in Haskell 😄
protocol_param_update = {? 0 : uint | ||
, ? 1 : uint | ||
, ? 2 : uint | ||
, ? 3 : uint | ||
, ? 4 : uint .size 2 | ||
, ? 5 : coin | ||
, ? 6 : coin | ||
, ? 7 : epoch | ||
, ? 8 : uint | ||
, ? 9 : nonnegative_interval | ||
, ? 10 : unit_interval | ||
, ? 11 : unit_interval | ||
, ? 12 : unit_interval | ||
, ? 13 : nonce | ||
, ? 14 : [protocol_version] |
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.
All of the comments have disappeared, which were very useful
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.
Most of the comments will come back with #4553. But yes, at the moment, comments are only supported on rules, not on arbitrary CDDL sections. I will have a think about how best to bring this back - input-output-hk/cuddle#36
-- the real bounded_bytes does not have this limit. it instead has a different | ||
-- limit which cannot be expressed in CDDL. | ||
-- The limit is as follows: | ||
-- - bytes with a definite-length encoding are limited to size 0..64 | ||
-- - for bytes with an indefinite-length CBOR encoding, each chunk is | ||
-- limited to size 0..64 | ||
-- ( reminder: in CBOR, the indefinite-length encoding of bytestrings | ||
-- consists of a token #2.31 followed by a sequence of definite-length | ||
-- encoded bytestrings and a stop code ) | ||
|
||
-- a type for distinct values. | ||
-- The type parameter must support .size, for example: bytes or 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.
Convert this into CDDL comment
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.
Done in #4553
unit_interval :: Rule | ||
unit_interval = "unit_interval" =:= tag 30 (arr [1, 2]) | ||
|
||
-- unit_interval = tag 0 [uint, uint] | ||
-- | ||
-- Comment above depicts the actual definition for `unit_interval`. | ||
-- | ||
-- Unit interval is a number in the range between 0 and 1, which | ||
-- means there are two extra constraints: | ||
-- \* numerator <= denominator | ||
-- \* denominator > 0 | ||
-- | ||
-- Relation between numerator and denominator cannot be expressed in CDDL, which | ||
-- poses a problem for testing. We need to be able to generate random valid data | ||
-- for testing implementation of our encoders/decoders. Which means we cannot use | ||
-- the actual definition here and we hard code the value to 1/2 |
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.
Convert it to CDDL comment
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.
Done in #4553
set :: IsType0 t0 => t0 -> GRuleCall | ||
set = binding $ \x -> "set" =:= tag 258 (arr [0 <+ a x]) / sarr [0 <+ a x] |
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 definition should live in cardano-ledger-conway
, since it is not valid for all previous eras.
More over it will also change in the next era, because tag 258 will become mandatory
-- Conway era introduces an optional 258 tag for sets, which will become mandatory in the | ||
-- second era after Conway. We recommend all the tooling to account for this future breaking | ||
-- change sooner rather than later, in order to provide a smooth transition for their users. |
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.
Convert to CDDL comment
|
||
pool_metadata = [url, metadata_hash] | ||
|
||
pool_params = (pool_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.
Am I right in assuming that key+value syntax is not supported by huddle?
pool_params = (pool_keyhash | |
pool_params = (operator: pool_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.
It is supported, but not for named groups (only for maps). input-output-hk/cuddle#32
, ? 10 : unit_interval | ||
, ? 11 : unit_interval | ||
, ? 12 : unit_interval | ||
, ? 13 : nonce |
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 don't remember the distinction between the two, but this has changed from previous spec. Was this desired?
, ? 13 : nonce | |
, ? 13 : $nonce |
|
||
vkeywitness = [ $vkey, $signature ] | ||
multi_host_name = (2, dns_name) |
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.
Lost comment
|
||
transaction_index = uint .size 2 | ||
$hash32 = 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.
What is the difference in syntax between =
and /=
?
$hash32 = bytes .size 32 | |
$hash32 /= 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.
For both type choices and group choices, additional alternatives can
be added to a rule later in separate rules by using "/=" and "//=",
respectively, instead of "=":
attire /= "swimwear"
delivery //= (
lat: float, long: float, drone-type: tstr
)
It is not an error if a name is first used with a "/=" or "//="
(there is no need to "create it" with "=").
So basically CDDL supports ad-hoc extending choices. Huddle does not support this. In any case, these definitions are the only definitions, so the use of /=
is meaningless.
import Data.Word (Word64) | ||
import GHC.Num (Integer) | ||
import GHC.Show (Show (show)) | ||
import Test.Cardano.Ledger.Core.Binary.CDDL |
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.
We've just made a release, so addition of a new module will require a minor version bump for:
cardano-ledger-shelley-1.13.1.0
cardano-ledger-conway-1.16.2.0
cardano-ledger-core-1.14.1.0
Also, the lower bounds will need to be adjusted accordingly
Closing this in favour of #4553 |
Description
This addresses issue #4462
One unexpected change: the huddle definition for
protocol_param_updates
has a size limit on the max block header size. This is consistent with the Haskell serialisers and data structure.Checklist
CHANGELOG.md
for the affected packages.New section is never added with the code changes. (See RELEASING.md)
.cabal
andCHANGELOG.md
files according to theversioning process.
.cabal
files for all affected packages are updated.If you change the bounds in a cabal file, that package itself must have a version increase. (See RELEASING.md)
fourmolu
(usescripts/fourmolize.sh
)scripts/cabal-format.sh
)hie.yaml
has been updated (usescripts/gen-hie.sh
)