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

Fully remove the cli intermediate TxBody format #4713

Closed

Conversation

Jimbo4350
Copy link
Contributor

@Jimbo4350 Jimbo4350 commented Dec 14, 2022

Resolves #4814

In this PR we fully remove support for the intermediate cli tx body format. As a result we make the following changes:

  • We extend the HasTextEnvelope type class as follows: textEnvelopeType :: AsType a -> TextEnvelopeType -> textEnvelopeType :: AsType a -> [TextEnvelopeType]. We do this so we can have backwards compatibility for the TextEnvelopeTypes that were introduced when we had to differentiate between the intermediate format and the CDDL format.
  • We delete Cardano.Api.SerialiseLedgerCddl as we do not want to maintain a separate type for the CDDL format. We should default to the CDDL format via the TextEnvelope type
  • We introduce the Cardano.Api.TxBodyInstances module because the "trick" we use to avoid the txbody intermediate format, is to convert the TxBody into an unsigned Tx.

@newhoggy
Copy link
Contributor

There are some golden test failures.

@Jimbo4350 Jimbo4350 changed the title Full remove the cli intermediate TxBody format Fully remove the cli intermediate TxBody format Dec 19, 2022
@Jimbo4350 Jimbo4350 force-pushed the jordan/fully-remove-cli-txbody-intermediate-format branch from 2c5e96e to a52fa5e Compare December 19, 2022 18:32
@Jimbo4350
Copy link
Contributor Author

There are some golden test failures.

Fixed

@Jimbo4350 Jimbo4350 force-pushed the jordan/fully-remove-cli-txbody-intermediate-format branch 3 times, most recently from 8e29465 to 053db1c Compare December 21, 2022 19:08
@Jimbo4350 Jimbo4350 added the WIP Work In Progress (cannot be merged yet) label Dec 21, 2022
@Jimbo4350 Jimbo4350 force-pushed the jordan/fully-remove-cli-txbody-intermediate-format branch from 053db1c to 93097ab Compare January 4, 2023 16:47
@Jimbo4350 Jimbo4350 force-pushed the jordan/fully-remove-cli-txbody-intermediate-format branch from 93097ab to ec4cb25 Compare January 11, 2023 17:41
@Jimbo4350 Jimbo4350 force-pushed the jordan/fully-remove-cli-txbody-intermediate-format branch from ec4cb25 to 34ad3dd Compare January 11, 2023 19:25
@Jimbo4350 Jimbo4350 removed the WIP Work In Progress (cannot be merged yet) label Jan 12, 2023
@Jimbo4350 Jimbo4350 force-pushed the jordan/fully-remove-cli-txbody-intermediate-format branch from 34ad3dd to 8182666 Compare January 12, 2023 19:56
, teDescription = fromMaybe (textEnvelopeDefaultDescr a) mbDescr
, teRawCBOR = serialiseToCBOR a
}
where
teType :: [TextEnvelopeType] -> TextEnvelopeType
teType [] = ""
teType (x : _) = x
Copy link
Contributor

Choose a reason for hiding this comment

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

Paraphrasing, the teType is the first in the list or the empty string. If there original list had more than one, what is the significance of the ordering?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will default to the first in the list. When reading a TextEnvelope file, it will check for all the types in the list hence preserving backwards compatibility. However when producing a TextEnvelope we simply default to the first in the list if there is more than one teType.

decodeKeyOrBootstrapWitness era bs =
case CBOR.decodeAnnotator "KeyWitness" fromCBOR (LBS.fromStrict bs) of
Right keyWit -> return $ ShelleyKeyWitness era keyWit
Left{} ->
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the reason for ignoring Left payload?

Copy link
Contributor Author

@Jimbo4350 Jimbo4350 Jan 16, 2023

Choose a reason for hiding this comment

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

So that we can try to deserialize a bootstrap witness

Comment on lines 103 to 104
("roundtrip " <> (fromString . Text.unpack $ renderEra aEra) <> " TxBody envelope")
("roundtrip " <> (fromString . Text.unpack $ renderEra aEra) <> " TxBody envelope")
Copy link
Contributor

@newhoggy newhoggy Jan 13, 2023

Choose a reason for hiding this comment

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

Prefer:

      ("roundtrip " <> fromString (Text.unpack (renderEra aEra)) <> " TxBody envelope")
      ("roundtrip " <> fromString (Text.unpack (renderEra aEra)) <> " TxBody envelope")

or:

      ("roundtrip " <> fromString (Text.unpack $ renderEra aEra) <> " TxBody envelope")
      ("roundtrip " <> fromString (Text.unpack $ renderEra aEra) <> " TxBody envelope")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Done

@@ -108,7 +108,7 @@ instance FromCBOR Certificate where
fromCBOR = fromShelleyCertificate <$> fromCBOR

instance HasTextEnvelope Certificate where
textEnvelopeType _ = "CertificateShelley"
Copy link
Contributor

@MarcFontaine MarcFontaine Jan 13, 2023

Choose a reason for hiding this comment

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

"CertificateShelley" and the other textEnvelopeType names are all magic IDs and they are assumed to be unique throughout the code.
It would be better to have all those unique ID in one place.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you have in mind?

@MarcFontaine
Copy link
Contributor

There should be an issue for this PR.
Do I understand correctly, that the CLI will solely use the ledger CBOR formats for all its file formats ?
The CLI and the ledger have very different requirements.
The ledger probably wants a very compact format, but for the CLI a human readable format like JSON may be preferable.

Is there any document that captures the requirements for the CLI on-disk-formats ?
What kinds of backward compatibility does the CLI provide ?
The CLI allows users to write stuff to files and the users expect to read the files in again.
Does the CLI support reading Txs etc that where created with older CLI versions ?
Fore sure, users expect that they can read in their secret keys etc.
Some users may expect to ready in unsigned to partially signed transactions of older CLI-versions.

Reading input and writing output formats is the core functionality of the CLI.
There should be some documentation on the subject.

The CLI does different task (crate TX body, sign TX, balance TX) while the ledger only deals
with complete TXs. Why use the ledger format for intermediate CLI formats ?

@Jimbo4350 Jimbo4350 force-pushed the jordan/fully-remove-cli-txbody-intermediate-format branch from 8182666 to c4c8a63 Compare January 16, 2023 15:43
@Jimbo4350
Copy link
Contributor Author

Jimbo4350 commented Jan 19, 2023

There should be an issue for this PR

I created an issue created: #4814

Do I understand correctly, that the CLI will solely use the ledger CBOR formats for all its file formats ?

Yes.

The ledger probably wants a very compact format, but for the CLI a human readable format like JSON may be preferable.

We should stick to the CDDL format for tx ondisk. This is to allow compatibility for existing libraries that expect the transaction to be in the CDDL format. This whole issue arose out of this incompatibility (see #3370)

Is there any document that captures the requirements for the CLI on-disk-formats ?

No, but for now we are opting to not deviate from the CDDL format

What kinds of backward compatibility does the CLI provide ?

None as of this PR regarding transaction body formats.

Does the CLI support reading Txs etc that where created with older CLI versions ?

Not as of this PR

Some users may expect to ready in unsigned to partially signed transactions of older CLI-versions.

I highly doubt this

There should be some documentation on the subject.

This would be a great task for you to spearhead.

Why use the ledger format for intermediate CLI formats ?

Have a look at #3370

@Jimbo4350 Jimbo4350 force-pushed the jordan/fully-remove-cli-txbody-intermediate-format branch from c4c8a63 to 5607d15 Compare January 25, 2023 12:37
@Jimbo4350 Jimbo4350 force-pushed the jordan/fully-remove-cli-txbody-intermediate-format branch from 113bd3d to 0d89fdd Compare February 8, 2023 14:40
`TextEnvelopeType`s. This allows for easy backwards compatibility for
the `TextEnvelopeType`s that were introduced to distinguish between the
cli intermediate `TxBody` format and the CDDL format.
Implement allTxBodyEnvelopeRoundtrips which roundtrip tests the TxBody
TextEnvelope format in all eras
Update shelley era properties to check for
the correct TextEnvelopeType
Update HasTextEnvelope (Tx era) instance to be backwards compatible with
`TextEnvelopeType`s introduced to distinguish between the CDDL format
and the intermediate cli txbody format
Update the SerialiseAsCBOR (KeyWitness era) instance to use the ledger's
CDDL format
Update checkTextEnvelopeFormat to accept `[TextEnvelopeType]` as we can
now specify multiple `TextEnvelopeType`s in a given `HasTextEnvelope`
instance
@Jimbo4350 Jimbo4350 force-pushed the jordan/fully-remove-cli-txbody-intermediate-format branch from 0d89fdd to a931959 Compare February 28, 2023 15:56
@Jimbo4350 Jimbo4350 force-pushed the jordan/fully-remove-cli-txbody-intermediate-format branch from a931959 to bb69f40 Compare February 28, 2023 16:43
@Jimbo4350
Copy link
Contributor Author

Resolved by: IntersectMBO/cardano-api@e739675

@Jimbo4350 Jimbo4350 closed this Mar 28, 2024
@Jimbo4350 Jimbo4350 deleted the jordan/fully-remove-cli-txbody-intermediate-format branch May 15, 2024 20:59
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.

Remove TxBody cli intermediate format
4 participants