Repository navigation
Conversation
… minor) pair the ledger encodes protocol_version was declared as Fraction, which made the action unusable end to end: __post_init__ unpacks it as a (major, minor) pair (a Fraction raises TypeError), serialising a pair raises a field-type error, and parsing a real [major, minor] array raises DeserializeException. The Conway CDDL encodes protocol_version as [major_protocol_version, uint .size 4] with major in 0..12, while __post_init__ also enforced a stale 1..10 bound that rejects the protocol version live on mainnet today (11). - governance.py: type protocol_version as Tuple[int, int] and validate major against the CDDL range 0..12. - serialization.py: teach _restore_typed_primitive to restore Tuple[...] fields, mirroring the existing List branch, so a parsed [major, minor] array comes back as a tuple. - test_governance.py: update the stale-bound test to the CDDL range and add CBOR round-trip tests asserting the exact wire bytes for a hard-fork initiation to protocol version 11.
Author
|
One extra data point from verifying this branch: the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
HardForkInitiationActionis unusable end to end. Itsprotocol_versionfield is declared asFraction, but the Conway CDDL encodes the field as a two-element array:That one wrong type breaks every direction:
__post_init__unpacks the value as a pair, soHardForkInitiationAction(None, Fraction(11, 1))raisesTypeError: cannot unpack non-iterable Fraction object.(10, 0), then callingto_cbor()raisesTypeError: Field 'protocol_version' should be of type <class 'fractions.Fraction'>.ProposalProcedurecarrying a real wire-form action[1, <gov_action_id>, [10, 0]]raisesDeserializeException; no hard-fork initiation proposal on chain can be decoded into this class.__post_init__enforces major 1..10, rejecting 11, the protocol version live on mainnet today, and 0, both inside the CDDL's 0..12 range. (The existing test even enshrines this, asserting(11, 0)raises.)I ran into this while building a Conway governance-proposals decoder against the CDDL: every other gov action round-tripped through pycardano, this one could not be represented at all.
Fix
governance.py: typeprotocol_versionasTuple[int, int](the same conventionpycardano.utilsuses for version pairs) and validate the major version against the CDDL range 0..12.serialization.py: teach_restore_typed_primitiveto restoreTuple[...]fields, mirroring the existingListbranch (includingTuple[X, ...]), so a parsed[major, minor]array comes back as a tuple. Previously any tuple-typed field fell through toDeserializeException, so this cannot change the behaviour of any field that deserialises today.test_governance.py: update the stale-bound test to the CDDL range (13 now raises) and add CBOR round-trip tests — including the exact wire bytes for an initiation to protocol version 11 (8301f6820b00) and one carrying a previous-action id.Verification
main; after it, construction, serialisation and parsing all work, and a CDDL-builtProposalProcedurewith a[10, 0]hard-fork action parses and re-serialises byte-for-byte.Submitted by Kyle Cox — @Kshot9000 (https://x.com/kshot9000) · github.com/Kshot3000
Support: ADA addr1q8hnl6vl5a6k3rw3n5g3jtte696zcl76kfatzv7gpswa9r0dj7fma6klq55y4ffm7tf0em09udnyhuk4ah92pl5x9jpqjae44v