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

Deprecate serialiseTxLedgerCddl #534

Merged
merged 8 commits into from
Jun 6, 2024
Merged

Conversation

palas
Copy link
Contributor

@palas palas commented May 13, 2024

Changelog

- description: |
    Added deprecation warning to function `serialiseTxLedgerCddl`
  type:
   - breaking

Context

In the past, we had an intermediate tx body format (sometimes called the intermediate cli format). This format did not adhere to the CDDL format in the ledger. So serialiseTxLedgerCddl was introduced to remedy this, with the aim of dropping the "intermediate cli format".

We have completely dropped the "intermediate cli format" so both functions will serialize txs that adhere to the ledger's CDDL format.

Therefore serialiseTxLedgerCddl is no longer necessary.

This PR deprecates it and reimplements serialiseTxLedgerCddl to use serialiseToTextEnvelope, which causes slight changes to the formats, see How to trust this PR below for more detail.

cardano-api

cardano-cli

cardano-node

How to trust this PR

Make sure that the message makes sense, that the functions deprecated are the one we want to deprecate, and that there are no other functions associated that we want to deprecate. Also that we want to override the deprecation in the tests (which makes sense to me, but maybe we want to remove or adapt the tests instead).

Also make sure the amount of backwards compatibility adaptors is adequate and in the right places.

Migrating to using serialiseToTextEnvelope changes the serialization format in three ways:

  • description: is provided by current functions but is a parameter to serialiseToTextEnvelope:
    • This is not a problem for deserialiseFromTextEnvelope because it ignores the field, so we get compatibility for free.
    • We pass the old descriptions to serialiseToTextEnvelope to ensure old functions keep producing the same description just to avoid breaking golden tests at this point.
  • type: is deduced from the HasTextEnvelope instance of the serialised type, but serialiseTxLedgerCddl has hardcoded types which do not match HasTextEnvelop instances:
    • This PR modified deserialiseToTextEnvelope to loosely compare types (see legacyComparison function) allowing for support for the serialiseTxLedgerCddl versions.
    • We keep the old types in serialiseTxLedgerCddl by wrapping serialiseToTextEnvelope and patch the output to produce the old types too. This is, again, just to avoid breaking golden tests at this point.
  • rawCBOR: is serialised pretty much identically by serialiseToTextEnvelope with one exception:
    • serialiseWitnessLedgerCddl encodes KeyWitness slightly differently than serialiseToTextEnvelope. In fact, deserialiseWitnessLedgerCddl relies on description to decide on the constructor to deserialise to of KeyWitness. This is a breaking change in the format and is not parsable by deserialiseFromTextEnvelope because it ignores the description. Changing deserialiseFromTextEnvelope to support this would be very patchy. So, this PR:
      • Modifies serialiseWitnessLedgerCddl to directly use serialiseToTextEnvelope (while keeping descriptions).
      • Modifies deserialiseWitnessLedgerCddl to use deserialiseFromTextEnvelope and to use the old decoding when that fails (this is done by the sub-function legacyDecoding).

These decisions provide a fair level of backwards compatibility but, at the same time, CBOR produced after the PR will be compatible with deserialiseFromTextEnvelope so functions in SerialiseLedgerCddl will become less necessary over time.

Also, to check these claims, you can see the results of running the tests in cardano-testnet and cardano-cli that are in the PRs linked in the Context section above.

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated. See Running tests for more details
  • Self-reviewed the diff

@palas palas self-assigned this May 13, 2024
@palas palas marked this pull request as draft May 13, 2024 22:31
@palas palas force-pushed the deprecate-serialiseTxLedgerCddl branch from 4782bcb to b4d72e8 Compare May 13, 2024 22:55
@palas palas marked this pull request as ready for review May 13, 2024 22:57
Copy link
Contributor

@Jimbo4350 Jimbo4350 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good but we should take this a little further.

@@ -134,6 +134,7 @@ instance Error TextEnvelopeCddlError where
TextEnvelopeCddlErrByronKeyWitnessUnsupported ->
"TextEnvelopeCddl error: Byron key witnesses are currently unsupported."

{-# DEPRECATED serialiseTxLedgerCddl "Use 'serialiseToTextEnvelope' from 'Cardano.Api.SerialiseTextEnvelope' instead." #-}
serialiseTxLedgerCddl :: ShelleyBasedEra era -> Tx era -> TextEnvelopeCddl
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can go further here. We can have serialiseTxLedgerCddl call serialiseToTextEnvelope and remove some of the additional unnecessary types e.g TextEnvelopeCddl

Copy link
Contributor Author

@palas palas May 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like in this commit?

It looks like this is likely a breaking change. Is that ok?

@palas palas force-pushed the deprecate-serialiseTxLedgerCddl branch 2 times, most recently from b773202 to 39eb80f Compare May 17, 2024 23:59
@palas palas requested a review from Jimbo4350 May 18, 2024 00:00
Copy link
Contributor

@carbolymer carbolymer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Can you make sure that tests in cardano-testnet and cardano-cli pass prior to merge?

@palas palas force-pushed the deprecate-serialiseTxLedgerCddl branch from c74c589 to 5743a60 Compare May 28, 2024 19:38
@palas palas changed the title Add deprecation warning to serialiseTxLedgerCddl Deprecate serialiseTxLedgerCddl May 29, 2024
@palas palas requested a review from a team as a code owner June 6, 2024 20:08
@palas palas force-pushed the deprecate-serialiseTxLedgerCddl branch from 128e9e6 to c95aad2 Compare June 6, 2024 20:09
@palas palas enabled auto-merge June 6, 2024 20:19
@palas palas force-pushed the deprecate-serialiseTxLedgerCddl branch 2 times, most recently from c73d277 to 0266459 Compare June 6, 2024 22:44
@palas palas disabled auto-merge June 6, 2024 22:44
@palas palas merged commit 3d885dc into main Jun 6, 2024
41 of 51 checks passed
@palas palas deleted the deprecate-serialiseTxLedgerCddl branch June 6, 2024 22:47
Copy link
Contributor

@Jimbo4350 Jimbo4350 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work 👍

-- | This is a backwards-compatibility patch to ensure that old envelopes
-- generated by 'serialiseTxLedgerCddl' can be deserialised after switching
-- to the 'serialiseToTextEnvelope'.
legacyComparison :: TextEnvelopeType -> TextEnvelopeType -> Bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍 . What we want to do is complain in the cli when a "legacy" text envelope type is used. The complaint would instruct them to convert the type field to the "correct" type. However before we do this, we should decide on a type format. I.e should we use the Witnesses vs Unwitnessed distinction or use the previous Tx $era format? You could start a discussion in discord on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants