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

Debug output for transaction submit #3819

Closed

Conversation

newhoggy
Copy link
Contributor

@newhoggy newhoggy commented Apr 25, 2022

  • A scripts/plutus/example-txin-locking-plutus-script-fail.sh to trigger the error message.
  • New New transaction submit --error-detail-out option
  • ToJSON instances for this feature
  • Carefully annotate types so of values so it's easy to trace dependencies between ToJSON instances

@newhoggy newhoggy marked this pull request as draft April 25, 2022 00:32
@newhoggy newhoggy force-pushed the newhoggy/debug-output-for-transaction-submit branch 2 times, most recently from 19e9cb7 to 055f872 Compare April 26, 2022 12:49
@newhoggy newhoggy force-pushed the newhoggy/debug-output-for-transaction-submit branch 3 times, most recently from 7c15cc5 to 195c118 Compare May 7, 2022 14:18
@newhoggy newhoggy marked this pull request as ready for review May 7, 2022 14:19
@newhoggy
Copy link
Contributor Author

newhoggy commented May 7, 2022

Sample run:

scripts/plutus/example-txin-locking-plutus-script-fail.sh
Socket path: example/node-bft1/node.sock
Socket path: /Users/jky/wrk/iohk/cardano-node
srwxr-xr-x  1 jky  staff  0  8 May 00:19 example/node-bft1/node.sock
Always succeeds Plutus script in use. Any datum and redeemer combination will succeed.
Script at: ./scripts/plutus/scripts/always-succeeds-spending.plutus
{
    "7ca831d2e870a434505d43e2d57f62a0dfc99a5868562ab1b8c88921933e3f25#0": {
        "address": "addr_test1vrpu544ueucqukajy09lr7g2ukre8y2l6xk0nw4qafxj29ggz6dk4",
        "datum": null,
        "datumhash": null,
        "value": {
            "lovelace": 900000000000
        }
    }
}Estimated transaction fee: Lovelace 169197
Transaction successfully submitted.
Pausing for 5 seconds...
{
    "a2d9e0c74e1e7e14d2a60cd1534897919b6edf77c8b89ed935eb1d801e9f380d#0": {
        "address": "addr_test1vrpu544ueucqukajy09lr7g2ukre8y2l6xk0nw4qafxj29ggz6dk4",
        "datum": null,
        "datumhash": null,
        "value": {
            "lovelace": 299999830803
        }
    },
    "a2d9e0c74e1e7e14d2a60cd1534897919b6edf77c8b89ed935eb1d801e9f380d#2": {
        "address": "addr_test1vrpu544ueucqukajy09lr7g2ukre8y2l6xk0nw4qafxj29ggz6dk4",
        "datum": null,
        "datumhash": null,
        "value": {
            "lovelace": 300000000000
        }
    }
}Plutus txin
a2d9e0c74e1e7e14d2a60cd1534897919b6edf77c8b89ed935eb1d801e9f380d#1|
Collateral
a2d9e0c74e1e7e14d2a60cd1534897919b6edf77c8b89ed935eb1d801e9f380d#0|
Submit the tx with plutus script and wait 5 seconds...
Command failed: transaction submit  Error: Error while submitting tx: ShelleyTxValidationError ShelleyBasedEraAlonzo (ApplyTxError [UtxowFailure (WrappedShelleyEraFailure (UtxoFailure (UtxosFailure (ValidationTagMismatch (IsValid True) (FailedUnexpectedly (PlutusFailure "\nThe 3 arg plutus script (PlutusScript PlutusV1 ScriptHash \"67f33146617a5e61936081db3b2117cbf59bd2123748f58ac9678656\") fails.\nCekError An error has occurred:  User error:\nThe budget was overspent. Final negative state: ({ cpu: -99 | mem: -99 })\nThe protocol version is: ProtVer {pvMajor = 2, pvMinor = 0}\nThe data is: I 42\nThe redeemer is: I 42\nThe context is:\nPurpose: Spending (TxOutRef {txOutRefId = a2d9e0c74e1e7e14d2a60cd1534897919b6edf77c8b89ed935eb1d801e9f380d, txOutRefIdx = 1})\nTxInfo:\n  TxId: b17390563d5a04c460aafa53d1308aaef544e16bdaf7a139c97b1b7501c7506b\n  Inputs: [ a2d9e0c74e1e7e14d2a60cd1534897919b6edf77c8b89ed935eb1d801e9f380d!1 -> - Value (Map [(,Map [(\"\",300000000000)])]) addressed to\n                                                                                    ScriptCredential: 67f33146617a5e61936081db3b2117cbf59bd2123748f58ac9678656 (no staking credential) ]\n  Outputs: [ - Value (Map [(,Map [(\"\",299980000000)])]) addressed to\n               PubKeyCredential: 4088059bbeb6add02eecd0c6a2a52c06910f2a6b4ba0029e9fe6ed13 (no staking credential) ]\n  Fee: Value (Map [(,Map [(\"\",20000000)])])\n  Value minted: Value (Map [])\n  DCerts: []\n  Wdrl: []\n  Valid range: (-\8734 , +\8734)\n  Signatories: []\n  Datums: [ ( 9e1199a988ba72ffd6e9c269cadb3b53b5f360ff99f112d9b2ee30c4d74ad88b\n          , 42 ) ]\n" "hgCYphoAAwJZAAEBGgAGC8cZAm0AARoAAknwGQPoAAEaAAJJ8BggGgAlzqgZcfcEGXRNGGQZdE0YZBl0TRhkGXRNGGQZdE0YZBl0TRhkGGQYZBl0TRhkGgACSfAYIBoAAknwGCAaAAJJ8BggGgACSfAZA+gAARoAAknwGCAaAAJJ8BkD6AAIGgACQiAaAAZ+Ixh2AAEBGgACSfAZA+gACBoAAknwGgABt5gY9wEaAAJJ8BknEAEaAAIVXhkFLgEZA+gaAAJJ8BkD6AEaAAJJ8BggGgACSfAYIBoAAknwGCABARoAAknwARoAAknwBBoAAZSvGPgBGgABlK8Y+AEaAAI3fBkFVgEaAAK96hkB8QEaAAJJ8BggGgACSfAYIBoAAknwGCAaAAJJ8BggGgACSfAYIBoAAknwGCAaAAJCIBoABn4jGHYAAQEZ8EwZK9IAARoAAknwGCAaAAJCIBoABn4jGHYAAQEaAAJCIBoABn4jGHYAAQEaACXOqBlx9wQAGgABQbsEGgACSfAZE4gAARoAAknwGCAaAAMCWQABARoAAknwGCAaAAJJ8BggGgACSfAYIBoAAknwGCAaAAJJ8BggGgACSfAYIBoAAknwGCAaADMNpwEBggEBTk0BAAAzIiIgBRIAEgARnxgqGCrYeZ/YeZ+f2Hmf2Hmf2HmfWCCi2eDHTh5+FNKmDNFTSJeRm27fd8i4ntk16x2AHp84Df8B/9h5n9h5n9h6n1gcZ/MxRmF6XmGTYIHbOyEXy/Wb0hI3SPWKyWeGVv/YeoD/oUChQBsAAABF2WS4ANh5n1ggnhGZqYi6cv/W6cJpyts7U7XzYP+Z8RLZsu4wxNdK2Iv/////n9h5n9h5n9h5n1gcQIgFm762rdAu7NDGoqUsBpEPKmtLoAKen+btE//YeoD/oUChQBsAAABF2DOLANh6gP//oUChQBoBMS0AoUChQACAgNh5n9h5n9h5gNh6gP/YeZ/Ye4DYeoD//4Cf2HmfWCCeEZmpiLpy/9bpwmnK2ztTtfNg/5nxEtmy7jDE10rYixgq///YeZ9YILFzkFY9WgTEYKr6U9Ewiq71ROFr2vehOcl7G3UBx1Br///Yep/YeZ/YeZ9YIKLZ4MdOHn4U0qYM0VNIl5Gbbt93yLie2TXrHYAenzgN/wH/////ggIA" :| []))))))])

@newhoggy
Copy link
Contributor Author

newhoggy commented May 7, 2022

Sample JSON output:

error-detail.json.gz

@newhoggy newhoggy changed the title Newhoggy/debug output for transaction submit Debug output for transaction submit May 7, 2022
@Jimbo4350
Copy link
Contributor

Jimbo4350 commented May 9, 2022

A few things:

  • We shouldn't create another module for orphan JSON instances in cardano-api. We have Cardano.Api.Orphans for orphan instances.
  • Command failed: transaction submit Error: Error while submitting tx: ShelleyTxValidationError ShelleyBasedEraAlonzo (ApplyTxError [UtxowFailure (WrappedShelleyEraFailure (UtxoFailure (UtxosFailure (ValidationTagMismatch (IsValid True) (FailedUnexpectedly (PlutusFailure "\nThe 3 arg plutus script (PlutusScript PlutusV1 ScriptHash... is a poorly formatted error message. It is poorly formatted because we are calling show in renderShelleyTxCmdError. We should also render the JSON here
    Alonzo.PlutusFailure t bs -> object
      [ "kind"                  .= String "FailureDescription"
      , "error"                 .= String "PlutusFailure"
      , "description"           .= t
      , "reconstructionDetail"  .= Alonzo.debugPlutus (BSU.toString bs)
      ]

We should not render t in the description field because it can't (easily) control the formatting and all the information we want exists in PlutusDebugInfo anyways. We should only render reconstructionDetail as you have done.

Lets start with the above and I'll have another look.

@newhoggy newhoggy force-pushed the newhoggy/debug-output-for-transaction-submit branch 2 times, most recently from 20dffe2 to a5a779f Compare May 15, 2022 14:11
@newhoggy newhoggy force-pushed the newhoggy/debug-output-for-transaction-submit branch 6 times, most recently from ac79543 to d78820e Compare May 18, 2022 02:40
@newhoggy newhoggy requested a review from Jimbo4350 May 18, 2022 13:24
@newhoggy newhoggy force-pushed the newhoggy/debug-output-for-transaction-submit branch 2 times, most recently from 2b4c72d to 2ebf82e Compare May 18, 2022 14:13
@newhoggy
Copy link
Contributor Author

I removed the Render module. Of the render functions, I converted some to ToJSON instances where that made sense. Others, I inlined, and the remainder, I put at the end of the Orphans module.

@newhoggy newhoggy force-pushed the newhoggy/debug-output-for-transaction-submit branch from 68ab868 to 862cbd2 Compare May 22, 2022 13:18
@newhoggy newhoggy requested a review from mgmeier as a code owner May 22, 2022 13:18
@newhoggy newhoggy force-pushed the newhoggy/debug-output-for-transaction-submit branch 5 times, most recently from 3d49a63 to 555f88b Compare May 26, 2022 11:08
@newhoggy newhoggy force-pushed the newhoggy/debug-output-for-transaction-submit branch 3 times, most recently from 3a0cc45 to 3634496 Compare June 4, 2022 13:20
@newhoggy newhoggy force-pushed the newhoggy/debug-output-for-transaction-submit branch from 3634496 to 19c3526 Compare June 6, 2022 23:47
@newhoggy newhoggy force-pushed the newhoggy/debug-output-for-transaction-submit branch from 19c3526 to 29aa164 Compare August 22, 2022 09:45
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.

Couple of changes.

@@ -24,14 +33,20 @@ module Cardano.Api.InMode (
fromConsensusApplyTxErr,
) where

import Prelude

import Cardano.Api.Eras
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the move of all the Cardano.Api.x modules?

ShelleyTxValidationError ShelleyBasedEraAllegra (Consensus.ApplyTxError predicateFailures) -> toJSON (fmap toJSON predicateFailures)
ShelleyTxValidationError ShelleyBasedEraMary (Consensus.ApplyTxError predicateFailures) -> toJSON (fmap toJSON predicateFailures)
ShelleyTxValidationError ShelleyBasedEraAlonzo (Consensus.ApplyTxError predicateFailures) -> toJSON (fmap toJSON predicateFailures)
ShelleyTxValidationError ShelleyBasedEraBabbage (Consensus.ApplyTxError _predicateFailures) -> Aeson.Null -- TODO implement
Copy link
Contributor

Choose a reason for hiding this comment

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

-- TODO implement

We should deal with this now

import Data.Aeson (FromJSON (..), ToJSON (..), object, (.=))
import qualified Data.Aeson as Aeson
import Cardano.Api.Script
import Cardano.Ledger.Alonzo.Rules.Bbody (AlonzoBbodyPredFail)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please follow the import formatting of other Cardano.Api.x modules

@@ -1,74 +1,169 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BlockArguments #-}
Copy link
Contributor

Choose a reason for hiding this comment

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

😢

, "failures" .= do map toJSON fs :: [Value]
]

instance ToJSON ChainPredicateFailure where
Copy link
Contributor

Choose a reason for hiding this comment

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

So for example this ToJSON instance should not be necessary. Why? Because ToObject ChainPredicateFailure exists and the ToObject class has a ToJSON constraint: https://github.com/input-output-hk/iohk-monitoring-framework/blob/066f7002aac5a0efc20e49643fea45454f226caa/iohk-monitoring/src/Cardano/BM/Data/Tracer.lhs#L217
Can you double check that the orphan instances you have added are needed?

let errorAsText = Text.pack $ show err
forM_ mErrorDetailFp $ \errorDetailFp ->
liftIO $ LBS.writeFile errorDetailFp (Aeson.encode err)
left $ ShelleyTxCmdTxSubmitError errorAsText
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also default the stdout to JSON? Ask QA what they think about this.

@@ -0,0 +1,136 @@
#!/usr/bin/env bash

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure we want to add a new shell script just to see the failure.

@newhoggy newhoggy force-pushed the newhoggy/debug-output-for-transaction-submit branch 5 times, most recently from 45f2bfa to e2fd35b Compare March 29, 2023 15:36
@newhoggy newhoggy force-pushed the newhoggy/debug-output-for-transaction-submit branch from e2fd35b to eb4a92c Compare April 11, 2023 05:15
New transaction submit --error-detail-out option
Fail plutus script
@newhoggy newhoggy force-pushed the newhoggy/debug-output-for-transaction-submit branch from eb4a92c to f2ef588 Compare May 11, 2023 02:01
@newhoggy newhoggy closed this Dec 9, 2023
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.

2 participants