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

Improve translation errors #2848

Merged
merged 8 commits into from
Jun 8, 2022
Merged

Conversation

lehins
Copy link
Collaborator

@lehins lehins commented Jun 7, 2022

While looking at #2825 and #2836 I realized that TranslationError was a new type in Babbage and thus we can in fact improve it before the release, so the node can use it to produce better errors to the users. I started at the point of the #2825 PR, since it seemed like a sensible cleanup.

While working on improving the type I found a few problems:

  • All error constructors could use with some extra information about the piece of transaction that is at fault for the error. The most common information was about problems with TxOuts, but in order to indicate which TxOut is the offender I moved as well as renamed and improved the TxOutSource (previously OutputSource). This will be enough to point at the offender.
  • TranslationLogicErrorDoubleDatum was an error that could never happen in practice, but it was impossible to avoid without some changes to the way inline datums are being extracted from TxOut in a general way. Thus is the addition of getTxOutDatum and removal of less powerful HasField "datum" instances.

Two more problems found, that haven't have been resolved yet:

  1. In the PR Alonzo tools cleanup #2825 we remove basicValidation, which is redundant for Babbage, however for Alonzo txInfo check does not verify presence of inputs in the utxo, it simply filters them out. Will now produce TranslationLogicMissingInput
  2. Test "attempt calculate ExUnits with invalid tx" is totally wrong.

KtorZ and others added 4 commits June 7, 2022 01:51
…LogicErrorInput

  The 'BasicFailure' was initially introduced as an extra sanity check to make
  sure that inputs referenced in the transaction were also present in the
  provided UTxO.

  Now however, this is done regardless in the `txInfoIn` function which is used
  to construct the 'PV1.TxInInfo' for both Alonzo & Babbage transactions:

  ```hs
  case Map.lookup txin mp of
    Nothing -> Left TranslationLogicErrorInput
    Just txout -> case transTxOutAddr txout of
  ```

  Thus, the `TranslationLogicErrorInput` branch from `TranslationError` makes
  the `UnknownInputs` branch redundant, and consequently, `BasicFailure`
  redundant completely. To be 100% equivalent, `TranslationLogicErrorInput`
  should be modified to also contain the missing inputs. I didn't do to that
  extend here because `TranslationError` seems to be use as a kind of _enum_,
  with only 0-ary constructors.
…xOutDatum. Avoid the impossible state in TxInfo where both DataHash and inline datum are supplied in TxOut
@lehins lehins marked this pull request as draft June 7, 2022 01:06
This is necessary because `basicValidation` has been removed in #2825
@lehins lehins marked this pull request as ready for review June 7, 2022 11:36
Previously it was simply checking if the txin was not present in an
empty UTxO. Which was more of a test for `txInfo`, rather than
`evaluateTransactionExecutionUnits`
@lehins lehins force-pushed the lehins/improve-translation-errors branch from a07dbea to 49d71b0 Compare June 7, 2022 11:41
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.

Nice! Thanks for improving the errors.

@@ -150,25 +122,19 @@ evaluateTransactionExecutionUnits ::
SystemStart ->
-- | The array of cost models, indexed by the supported languages.
Array Language CostModel ->
-- | If the transaction meets basic validation, we return a map from
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉

dec n = Invalid n

data TranslationError crypto
= ByronTxOutInContext !(TxOutSource crypto)
Copy link
Contributor

Choose a reason for hiding this comment

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

👍


-- | Datum can be described by a either a data hash or binary data, but not
-- both. It can also be neither one of them.
data Datum era
Copy link
Contributor

Choose a reason for hiding this comment

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

much better place 🙌

Copy link
Contributor

@JaredCorduan JaredCorduan left a comment

Choose a reason for hiding this comment

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

Thank you @lehins for improving these errors, this is extremely helpful. The changes all look good to me (though it was a bit tricky makings sure we didn't change the Alonzo semantics). We review the subtle parts of this PR in a call, which I went back and confirmed to myself.

@lehins lehins force-pushed the lehins/improve-translation-errors branch from c53b085 to 451cb52 Compare June 8, 2022 13:36
failBecause (CollectErrors alonzoFailures)
| otherwise -> pure ()
where
-- BadTranslation was introduced in Babbage, thus we need to filter those failures out.
Copy link
Contributor

Choose a reason for hiding this comment

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

🙏

@lehins lehins force-pushed the lehins/improve-translation-errors branch from 451cb52 to 9276e2d Compare June 8, 2022 14:58
@JaredCorduan
Copy link
Contributor

@lehins the "failed" CI job is yet another instance of the tests actually passing after a re-run, but not reporting properly. With your 👍 I'd like to merge this great PR :)

@lehins lehins merged commit 2c6e211 into master Jun 8, 2022
@iohk-bors iohk-bors bot deleted the lehins/improve-translation-errors branch June 8, 2022 17:44
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.

4 participants