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

Map and debug PlutusFailure cases of ApplyTx #1789

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ changes.
- Overall this results in transactions still to be submitted once per client,
but requires signifanctly less book-keeping on the client-side.

- Auto-debug and provide more information on `PlutusFailure` when validating transactions on L2 ledger.

- Bump docusaurus version

- Add blockfrost support to `hydra-chain-observer`, to follow the chain via Blockfrost API.
Expand Down
1 change: 1 addition & 0 deletions hydra-node/hydra-node.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ library
, cardano-ledger-api
, cardano-ledger-babbage
, cardano-ledger-babbage:testlib
, cardano-ledger-conway
, cardano-ledger-conway:testlib
, cardano-ledger-core
, cardano-ledger-core:testlib
Expand Down
22 changes: 21 additions & 1 deletion hydra-node/src/Hydra/Ledger/Cardano.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,18 @@ import Hydra.Ledger.Cardano.Builder

import Cardano.Api.UTxO (fromPairs, pairs)
import Cardano.Api.UTxO qualified as UTxO
import Cardano.Ledger.Alonzo.Rules (
FailureDescription (..),
TagMismatchDescription (FailedUnexpectedly),
)
import Cardano.Ledger.BaseTypes qualified as Ledger
import Cardano.Ledger.Conway.Rules (
ConwayLedgerPredFailure (ConwayUtxowFailure),
ConwayUtxoPredFailure (UtxosFailure),
ConwayUtxosPredFailure (ValidationTagMismatch),
ConwayUtxowPredFailure (UtxoFailure),
)
import Cardano.Ledger.Plutus (debugPlutus)
import Cardano.Ledger.Shelley.API.Mempool qualified as Ledger
import Cardano.Ledger.Shelley.Genesis qualified as Ledger
import Cardano.Ledger.Shelley.LedgerState qualified as Ledger
Expand Down Expand Up @@ -68,7 +79,16 @@ cardanoLedger globals ledgerEnv =
Right (Ledger.LedgerState{Ledger.lsUTxOState = us}, _validatedTx) ->
Right . fromLedgerUTxO $ Ledger.utxosUtxo us
where
toValidationError = ValidationError . show
-- As we use applyTx we only expect one ledger rule to run and one tx to
-- fail validation, hence using the heads of non empty lists is fine.
toValidationError (Ledger.ApplyTxError (e :| _)) = case e of
(ConwayUtxowFailure (UtxoFailure (UtxosFailure (ValidationTagMismatch _ (FailedUnexpectedly (PlutusFailure msg ctx :| _)))))) ->
ValidationError $
"Plutus validation failed: "
<> msg
<> "Debug info: "
<> show (debugPlutus @StandardCrypto (decodeUtf8 ctx))
_ -> ValidationError $ show e

env' = ledgerEnv{Ledger.ledgerSlotNo = fromIntegral slot}

Expand Down
Loading