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

New debug transaction echo command #709

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

newhoggy
Copy link
Contributor

@newhoggy newhoggy commented Apr 9, 2024

Changelog

- description: |
    New `debug transaction echo` command
# uncomment types applicable to the change:
  type:
  - feature        # introduces a new feature
  # - breaking       # the API has changed in a breaking way
  # - compatible     # the API has changed but is non-breaking
  # - optimisation   # measurable performance improvements
  # - improvement    # QoL changes e.g. refactoring
  # - bugfix         # fixes a defect
  # - test           # fixes/modifies tests
  # - maintenance    # not directly related to the code
  # - release        # related to a new release preparation
  # - documentation  # change in code docs, haddocks...

Context

New command is useful for testing if decode/encode roundtrip has problems.

How to trust this PR

Highlight important bits of the PR that will make the review faster. If there are commands the reviewer can run to observe the new behavior, describe them.

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

@newhoggy newhoggy marked this pull request as ready for review April 9, 2024 12:08
@newhoggy newhoggy force-pushed the newhoggy/new-transaction-echo-command branch from 0accede to 73045d3 Compare April 9, 2024 12:09
, Just
$ subParser "echo"
$ Opt.info pTransactionEcho
$ Opt.progDesc "Echo a transaction"
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you provide more context as to when this command is useful?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, I don't understand why we need this command.

Copy link
Contributor

Choose a reason for hiding this comment

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

I gather that's verifying that we're capable of reading the transaction and saving it again. I don't know if saving can fail in this scenario, but reading should be verifiable with transaction view imo.

Copy link
Contributor Author

@newhoggy newhoggy Apr 10, 2024

Choose a reason for hiding this comment

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

Yes, reading and saving the transaction again and verifying that the new transaction is byte-wise identical to the old.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@carbolymer carbolymer Apr 10, 2024

Choose a reason for hiding this comment

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

Sooo... what's the advantage over transaction view ? 😃

Copy link
Contributor Author

@newhoggy newhoggy May 26, 2024

Choose a reason for hiding this comment

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

transaction view doesn't do a roundtrip. It reads a transaction and writes it in some other format.

Using transaction view doesn't give us any information about whether the tx could have been generated by cardano-api or cardano-cli.

Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like a thing we should have a property test for.

Copy link
Contributor

Choose a reason for hiding this comment

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

So should we have a roundtrip test instead of a command?

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess both? The command could be useful too I think.

@smelc
Copy link
Contributor

smelc commented Apr 9, 2024

Code looks fine to me 👍

Not approving to give a chance to @Jimbo4350 and @CarlosLopezDeLara to chime in on the design.

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.

@newhoggy newhoggy requested a review from carbolymer April 10, 2024 10:27
Copy link

This PR is stale because it has been open 45 days with no activity.

@github-actions github-actions bot added Stale and removed Stale labels May 26, 2024
)
--out-file FILE

Echo a transaction
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs more explanation what does this command exactly do.

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, but it needs more explanation why an user would like to use this command. Also I'm not sure if it wouldn't be better to make this command live under debug hierarchy, since it's not very useful in normal transaction processing.

@newhoggy newhoggy force-pushed the newhoggy/new-transaction-echo-command branch 2 times, most recently from c288b0e to e264596 Compare June 18, 2024 14:20
@newhoggy newhoggy changed the title New transaction echo command New debug transaction echo command Jun 18, 2024
@newhoggy newhoggy requested a review from smelc June 18, 2024 14:24
]
, subParser "echo"
$ Opt.info (DebugTransactionCmds <$> pDebugTransactionEcho)
$ Opt.progDesc "Echo a transaction"
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add more info why specifically we are adding this? I can approve after.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was going to say the same. Something like "it parses and rewrites the transaction" or "it deserialises and then reserialises a transaction" or "it re-formats the transaction". And it would be nice to say why this may be useful too, e.g: "because we may want to update/reformat the transaction using the format of the current version of the cli".

Copy link
Contributor

@palas palas left a comment

Choose a reason for hiding this comment

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

This should be very useful to work with changes to transaction format. I have included a couple of suggestions that I think could improve clarity

]
, subParser "echo"
$ Opt.info (DebugTransactionCmds <$> pDebugTransactionEcho)
$ Opt.progDesc "Echo a transaction"
Copy link
Contributor

Choose a reason for hiding this comment

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

I was going to say the same. Something like "it parses and rewrites the transaction" or "it deserialises and then reserialises a transaction" or "it re-formats the transaction". And it would be nice to say why this may be useful too, e.g: "because we may want to update/reformat the transaction using the format of the current version of the cli".

Comment on lines 40 to 51
unwitnessed <- firstExceptT DebugCmdTextEnvCddlError . newExceptT $ readFileTxBody txbodyFile

case unwitnessed of
IncompleteCddlTxBody anyTxBody -> do
InAnyShelleyBasedEra sbe txbody <- pure anyTxBody

let tx = makeSignedTransaction [] txbody

firstExceptT DebugCmdWriteFileError . newExceptT
$ writeLazyByteStringFile outTxFile
$ shelleyBasedEraConstraints sbe
$ textEnvelopeToJSON Nothing tx
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
unwitnessed <- firstExceptT DebugCmdTextEnvCddlError . newExceptT $ readFileTxBody txbodyFile
case unwitnessed of
IncompleteCddlTxBody anyTxBody -> do
InAnyShelleyBasedEra sbe txbody <- pure anyTxBody
let tx = makeSignedTransaction [] txbody
firstExceptT DebugCmdWriteFileError . newExceptT
$ writeLazyByteStringFile outTxFile
$ shelleyBasedEraConstraints sbe
$ textEnvelopeToJSON Nothing tx
IncompleteCddlTxBody (InAnyShelleyBasedEra sbe txbody)
<- firstExceptT DebugCmdTextEnvCddlError . newExceptT $ readFileTxBody txbodyFile
let tx = makeSignedTransaction [] txbody
firstExceptT DebugCmdWriteFileError . newExceptT
$ writeLazyByteStringFile outTxFile
$ shelleyBasedEraConstraints sbe
$ textEnvelopeToJSON Nothing tx

This case is unnecessary because it only has one option (it is a newtype)

Comment on lines 31 to 33
anyTx <- lift (readFileTx inputTxFile) & onLeft (left . DebugCmdTextEnvCddlError)

InAnyShelleyBasedEra sbe tx <- pure anyTx
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
anyTx <- lift (readFileTx inputTxFile) & onLeft (left . DebugCmdTextEnvCddlError)
InAnyShelleyBasedEra sbe tx <- pure anyTx
InAnyShelleyBasedEra sbe tx <- lift (readFileTx inputTxFile) & onLeft (left . DebugCmdTextEnvCddlError)

I was thinking that this would be equivalent to:

let InAnyShelleyBasedEra sbe tx = anyTx

But it is not. The let version doesn't compile, interesting 🤔
But still can do the suggestion, unless you are doing it for clarity.

Comment on lines 1212 to 1214
anyTx <- lift (readFileTx inputTxFile) & onLeft (left . TxCmdTextEnvCddlError)

InAnyShelleyBasedEra sbe tx <- pure anyTx
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
anyTx <- lift (readFileTx inputTxFile) & onLeft (left . TxCmdTextEnvCddlError)
InAnyShelleyBasedEra sbe tx <- pure anyTx
InAnyShelleyBasedEra sbe tx <- lift (readFileTx inputTxFile) & onLeft (left . TxCmdTextEnvCddlError)

Same here

Comment on lines 1221 to 1232
unwitnessed <- firstExceptT TxCmdTextEnvCddlError . newExceptT $ readFileTxBody txbodyFile

case unwitnessed of
IncompleteCddlTxBody anyTxBody -> do
InAnyShelleyBasedEra sbe txbody <- pure anyTxBody

let tx = makeSignedTransaction [] txbody

firstExceptT TxCmdWriteFileError . newExceptT
$ writeLazyByteStringFile outTxFile
$ shelleyBasedEraConstraints sbe
$ textEnvelopeToJSON Nothing tx
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
unwitnessed <- firstExceptT TxCmdTextEnvCddlError . newExceptT $ readFileTxBody txbodyFile
case unwitnessed of
IncompleteCddlTxBody anyTxBody -> do
InAnyShelleyBasedEra sbe txbody <- pure anyTxBody
let tx = makeSignedTransaction [] txbody
firstExceptT TxCmdWriteFileError . newExceptT
$ writeLazyByteStringFile outTxFile
$ shelleyBasedEraConstraints sbe
$ textEnvelopeToJSON Nothing tx
IncompleteCddlTxBody (InAnyShelleyBasedEra sbe txbody)
<- firstExceptT TxCmdTextEnvCddlError . newExceptT $ readFileTxBody txbodyFile
let tx = makeSignedTransaction [] txbody
firstExceptT TxCmdWriteFileError . newExceptT
$ writeLazyByteStringFile outTxFile
$ shelleyBasedEraConstraints sbe
$ textEnvelopeToJSON Nothing tx

And here

@palas
Copy link
Contributor

palas commented Jul 15, 2024

@palas palas force-pushed the newhoggy/new-transaction-echo-command branch from e264596 to 1bba1f5 Compare July 15, 2024 22:45
@palas
Copy link
Contributor

palas commented Jul 15, 2024

FYI: I have rebased your branch because we have done changes to the formatting. I have made a copy of the unrebased branch that you can find in my previous comment in this PR.

Copy link

This PR is stale because it has been open 45 days with no activity.

@github-actions github-actions bot added the Stale label Aug 30, 2024
@github-actions github-actions bot removed the Stale label Oct 15, 2024
Copy link

This PR is stale because it has been open 45 days with no activity.

@github-actions github-actions bot added the Stale label Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants