Skip to content

Commit def8128

Browse files
committed
Improve debugging of ScriptErrorMissingScript
1 parent 5c4c758 commit def8128

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

cardano-api/src/Cardano/Api/Experimental/Tx/Internal/Fee.hs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,11 @@ indexWitnessedTxProposalProcedures (TxProposalProcedures proposals) = do
10131013
| (ix, (proposal, anyWitness)) <- allProposalsList
10141014
]
10151015

1016+
toUnsigned :: forall era. Era era -> L.Tx (LedgerEra era) -> UnsignedTx era
1017+
toUnsigned e tx =
1018+
obtainCommonConstraints e $
1019+
UnsignedTx tx
1020+
10161021
-- | Compute the 'ExecutionUnits' required for each script in the transaction.
10171022
--
10181023
-- This process involves executing all scripts and counting the actual execution units
@@ -1072,10 +1077,13 @@ evaluateTransactionExecutionUnits systemstart epochInfo pp utxo tx =
10721077
-- the redeemer pointer will always point to a Plutus script.
10731078
L.MissingScript indexOfScriptWitnessedItem resolveable ->
10741079
let scriptWitnessedItemIndex = obtainCommonConstraints (useEra @era) $ toScriptIndex (convert useEra) indexOfScriptWitnessedItem
1075-
in ScriptErrorMissingScript scriptWitnessedItemIndex $
1076-
obtainCommonConstraints (useEra @era) $
1077-
ResolvablePointers (convert useEra) $
1078-
Map.map extractScriptBytesAndLanguage resolveable
1080+
unsigned = toUnsigned (useEra @era) tx
1081+
in ScriptErrorMissingScript
1082+
unsigned
1083+
scriptWitnessedItemIndex
1084+
$ obtainCommonConstraints (useEra @era)
1085+
$ ResolvablePointers (convert useEra)
1086+
$ Map.map extractScriptBytesAndLanguage resolveable
10791087
L.NoCostModelInLedgerState l -> ScriptErrorMissingCostModel l
10801088
L.ContextError e ->
10811089
obtainCommonConstraints (useEra @era) $ ScriptErrorTranslationError e

cardano-api/src/Cardano/Api/Tx/Internal/Fee.hs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import Cardano.Api.Era.Internal.Eon.ShelleyBasedEra
6868
import Cardano.Api.Era.Internal.Feature
6969
import Cardano.Api.Error
7070
import Cardano.Api.Experimental.Tx.Internal.Certificate qualified as Exp
71+
import Cardano.Api.Experimental.Tx.Internal.Type (UnsignedTx)
7172
import Cardano.Api.Ledger.Internal.Reexport qualified as L
7273
import Cardano.Api.Plutus
7374
import Cardano.Api.Pretty
@@ -579,7 +580,8 @@ data ScriptExecutionError
579580
-- in the transaction nor in the UTxO as a reference script"
580581
ScriptErrorRedeemerPointsToUnknownScriptHash ScriptWitnessIndex
581582
| -- | A redeemer pointer points to a script that does not exist.
582-
ScriptErrorMissingScript
583+
forall era. ScriptErrorMissingScript
584+
(UnsignedTx era)
583585
ScriptWitnessIndex -- The invalid pointer
584586
ResolvablePointers -- A mapping a pointers that are possible to resolve
585587
| -- | A cost model was missing for a language which was used.
@@ -627,11 +629,12 @@ instance Error ScriptExecutionError where
627629
[ pretty (renderScriptWitnessIndex scriptWitness)
628630
, " points to a script hash that is not known."
629631
]
630-
ScriptErrorMissingScript rdmrPtr resolveable ->
632+
ScriptErrorMissingScript tx rdmrPtr resolveable ->
631633
mconcat
632634
[ "The redeemer pointer: " <> pshow rdmrPtr <> " points to a Plutus "
633635
, "script that does not exist.\n"
634636
, "The pointers that can be resolved are: " <> pshow resolveable
637+
, "Tx: " <> pshow tx
635638
]
636639
ScriptErrorMissingCostModel language ->
637640
"No cost model was found for language " <> pshow language
@@ -772,7 +775,7 @@ evaluateTransactionExecutionUnitsShelley sbe systemstart epochInfo (LedgerProtoc
772775
-- the redeemer pointer will always point to a Plutus script.
773776
L.MissingScript indexOfScriptWitnessedItem resolveable ->
774777
let scriptWitnessedItemIndex = toScriptIndex aOnwards indexOfScriptWitnessedItem
775-
in ScriptErrorMissingScript scriptWitnessedItemIndex $
778+
in ScriptErrorMissingScript (error "ignore") scriptWitnessedItemIndex $
776779
ResolvablePointers sbe $
777780
Map.map extractScriptBytesAndLanguage resolveable
778781
L.NoCostModelInLedgerState l -> ScriptErrorMissingCostModel l

cardano-api/test/cardano-api-golden/Test/Golden/ErrorsSpec.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ test_ScriptExecutionError =
307307
,
308308
( "ScriptErrorMissingScript"
309309
, ScriptErrorMissingScript
310+
(error "ignore")
310311
(ScriptWitnessIndexMint 0)
311312
(ResolvablePointers ShelleyBasedEraBabbage Map.empty) -- TODO CIP-1694 make work in all eras
312313
)

0 commit comments

Comments
 (0)