Skip to content

Commit 0121730

Browse files
committed
Swap Mempool/Ledger predicate failures in Dijkstra
To get there we need to move the `ApplyTxError era` type to be a data family in the ApplyTx class
1 parent 79ecb1c commit 0121730

File tree

36 files changed

+342
-138
lines changed

36 files changed

+342
-138
lines changed

eras/allegra/impl/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## 1.9.0.0
44

5+
* Add `AllegraApplyTxError` constructor for `ApplyTxError era`
56
* Add `cddl` sub-library, and `generate-cddl` executable.
67
* Remove deprecated type `Allegra`
78
* Remove deprecated type `TimelockConstr`

eras/allegra/impl/src/Cardano/Ledger/Allegra.hs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
{-# LANGUAGE DataKinds #-}
2+
{-# LANGUAGE DerivingStrategies #-}
23
{-# LANGUAGE FlexibleInstances #-}
4+
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
35
{-# LANGUAGE ScopedTypeVariables #-}
46
{-# LANGUAGE TypeApplications #-}
7+
{-# LANGUAGE TypeFamilies #-}
58
{-# LANGUAGE UndecidableInstances #-}
69
{-# OPTIONS_GHC -Wno-orphans #-}
710

811
module Cardano.Ledger.Allegra (
912
AllegraEra,
1013
Tx (..),
14+
ApplyTxError (..),
1115
) where
1216

1317
import Cardano.Ledger.Allegra.BlockBody ()
@@ -20,13 +24,22 @@ import Cardano.Ledger.Allegra.Transition ()
2024
import Cardano.Ledger.Allegra.Translation ()
2125
import Cardano.Ledger.Allegra.Tx (Tx (..))
2226
import Cardano.Ledger.Allegra.UTxO ()
27+
import Cardano.Ledger.Binary (DecCBOR, EncCBOR)
2328
import Cardano.Ledger.Shelley.API
29+
import Cardano.Ledger.Shelley.Rules (ShelleyLedgerPredFailure)
30+
import Data.Bifunctor (Bifunctor (first))
31+
import Data.List.NonEmpty (NonEmpty)
2432

2533
--------------------------------------------------------------------------------
2634
-- Mempool instances
2735
--------------------------------------------------------------------------------
2836

2937
instance ApplyTx AllegraEra where
30-
applyTxValidation = ruleApplyTxValidation @"LEDGER"
38+
newtype ApplyTxError AllegraEra = AllegraApplyTxError (NonEmpty (ShelleyLedgerPredFailure AllegraEra))
39+
deriving (Eq, Show)
40+
deriving newtype (EncCBOR, DecCBOR)
41+
applyTxValidation validationPolicy globals env state tx =
42+
first AllegraApplyTxError $
43+
ruleApplyTxValidation @"LEDGER" validationPolicy globals env state tx
3144

3245
instance ApplyBlock AllegraEra

eras/allegra/impl/testlib/Test/Cardano/Ledger/Allegra/Arbitrary.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module Test.Cardano.Ledger.Allegra.Arbitrary (
1919
maxTimelockDepth,
2020
) where
2121

22-
import Cardano.Ledger.Allegra (AllegraEra, Tx (..))
22+
import Cardano.Ledger.Allegra (AllegraEra, ApplyTxError (..), Tx (..))
2323
import Cardano.Ledger.Allegra.Rules (AllegraUtxoPredFailure)
2424
import Cardano.Ledger.Allegra.Scripts (
2525
AllegraEraScript (..),
@@ -132,3 +132,5 @@ instance Arbitrary ValidityInterval where
132132
deriving newtype instance Arbitrary (TransitionConfig AllegraEra)
133133

134134
deriving newtype instance Arbitrary (Tx TopTx AllegraEra)
135+
136+
deriving newtype instance Arbitrary (ApplyTxError AllegraEra)

eras/allegra/impl/testlib/Test/Cardano/Ledger/Allegra/Examples.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import Test.Cardano.Ledger.Shelley.Examples (
4141
mkWitnessesPreAlonzo,
4242
)
4343

44-
ledgerExamples :: LedgerExamples AllegraEra
44+
ledgerExamples :: LedgerExamples "LEDGER" AllegraEra
4545
ledgerExamples =
4646
mkLedgerExamples
4747
(mkWitnessesPreAlonzo (Proxy @AllegraEra))

eras/alonzo/impl/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## 1.15.0.0
44

5+
* Add `AlonzoApplyTxError` constructor for `ApplyTxError era`
56
* Changed the type of `dappMinUTxOValue` to `CompactForm Coin` in `DowngradeAlonzoPParams`
67
* Changed the type of the following fields to `CompactForm Coin` in `AlonzoPParams`:
78
- `appMinFeeA`

eras/alonzo/impl/src/Cardano/Ledger/Alonzo.hs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
{-# LANGUAGE DataKinds #-}
2+
{-# LANGUAGE DerivingStrategies #-}
23
{-# LANGUAGE FlexibleContexts #-}
34
{-# LANGUAGE FlexibleInstances #-}
5+
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
46
{-# LANGUAGE PatternSynonyms #-}
57
{-# LANGUAGE ScopedTypeVariables #-}
68
{-# LANGUAGE TypeApplications #-}
9+
{-# LANGUAGE TypeFamilies #-}
710
{-# LANGUAGE UndecidableInstances #-}
811
{-# OPTIONS_GHC -Wno-orphans #-}
912

@@ -15,6 +18,7 @@ module Cardano.Ledger.Alonzo (
1518
AlonzoScript,
1619
AlonzoTxAuxData,
1720
Tx (..),
21+
ApplyTxError (..),
1822
) where
1923

2024
import Cardano.Ledger.Alonzo.BlockBody ()
@@ -31,13 +35,22 @@ import Cardano.Ledger.Alonzo.TxAuxData (AlonzoTxAuxData)
3135
import Cardano.Ledger.Alonzo.TxBody (AlonzoTxOut, TxBody (AlonzoTxBody))
3236
import Cardano.Ledger.Alonzo.TxWits ()
3337
import Cardano.Ledger.Alonzo.UTxO ()
38+
import Cardano.Ledger.Binary (DecCBOR, EncCBOR)
3439
import Cardano.Ledger.Mary.Value (MaryValue)
3540
import Cardano.Ledger.Plutus.Data ()
3641
import Cardano.Ledger.Shelley.API
42+
import Cardano.Ledger.Shelley.Rules (ShelleyLedgerPredFailure)
43+
import Data.Bifunctor (Bifunctor (first))
44+
import Data.List.NonEmpty (NonEmpty)
3745

3846
-- =====================================================
3947

4048
instance ApplyTx AlonzoEra where
41-
applyTxValidation = ruleApplyTxValidation @"LEDGER"
49+
newtype ApplyTxError AlonzoEra = AlonzoApplyTxError (NonEmpty (ShelleyLedgerPredFailure AlonzoEra))
50+
deriving (Eq, Show)
51+
deriving newtype (EncCBOR, DecCBOR)
52+
applyTxValidation validationPolicy globals env state tx =
53+
first AlonzoApplyTxError $
54+
ruleApplyTxValidation @"LEDGER" validationPolicy globals env state tx
4255

4356
instance ApplyBlock AlonzoEra

eras/alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo/Arbitrary.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module Test.Cardano.Ledger.Alonzo.Arbitrary (
3232
genAlonzoPlutusPurposePointer,
3333
) where
3434

35-
import Cardano.Ledger.Alonzo (AlonzoEra, Tx (..))
35+
import Cardano.Ledger.Alonzo (AlonzoEra, ApplyTxError (..), Tx (..))
3636
import Cardano.Ledger.Alonzo.Core
3737
import Cardano.Ledger.Alonzo.Genesis (AlonzoExtraConfig (..), AlonzoGenesis (..))
3838
import Cardano.Ledger.Alonzo.PParams (
@@ -468,6 +468,8 @@ instance Arbitrary (TransitionConfig AlonzoEra) where
468468

469469
deriving newtype instance Arbitrary (Tx TopTx AlonzoEra)
470470

471+
deriving newtype instance Arbitrary (ApplyTxError AlonzoEra)
472+
471473
instance
472474
( EraBlockBody era
473475
, AlonzoEraTx era

eras/alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo/Examples.hs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import Cardano.Ledger.Mary.Value (MaryValue (..))
3333
import Cardano.Ledger.Plutus.Data (Data (..), hashData)
3434
import Cardano.Ledger.Plutus.Language (Language (..))
3535
import Cardano.Ledger.Shelley.API (
36-
ApplyTxError (..),
3736
Credential (..),
3837
Network (..),
3938
NewEpochState (..),
@@ -42,11 +41,16 @@ import Cardano.Ledger.Shelley.API (
4241
TxId (..),
4342
Update (..),
4443
)
45-
import Cardano.Ledger.Shelley.Rules (ShelleyDelegsPredFailure (..), ShelleyLedgerPredFailure (..))
44+
import Cardano.Ledger.Shelley.Rules (
45+
PredicateFailure,
46+
ShelleyDelegsPredFailure (..),
47+
ShelleyLedgerPredFailure (..),
48+
)
4649
import Cardano.Ledger.Shelley.Scripts
4750
import Cardano.Ledger.TxIn (mkTxInPartial)
4851
import Cardano.Slotting.Slot (EpochNo (..), SlotNo (..))
4952
import Data.Default (def)
53+
import Data.List.NonEmpty (NonEmpty)
5054
import qualified Data.Map.Strict as Map
5155
import qualified Data.Sequence.Strict as StrictSeq
5256
import qualified Data.Set as Set
@@ -72,13 +76,12 @@ import Test.Cardano.Ledger.Shelley.Examples (
7276
testShelleyGenesis,
7377
)
7478

75-
ledgerExamples :: LedgerExamples AlonzoEra
79+
ledgerExamples :: LedgerExamples "LEDGER" AlonzoEra
7680
ledgerExamples =
7781
mkLedgerExamples
78-
( ApplyTxError $
79-
pure $
80-
DelegsFailure $
81-
DelegateeNotRegisteredDELEG @AlonzoEra (mkKeyHash 1)
82+
( pure $
83+
DelegsFailure $
84+
DelegateeNotRegisteredDELEG @AlonzoEra (mkKeyHash 1)
8285
)
8386
exampleAlonzoNewEpochState
8487
exampleTxAlonzo
@@ -87,11 +90,11 @@ ledgerExamples =
8790
mkLedgerExamples ::
8891
forall era.
8992
AlonzoEraPParams era =>
90-
ApplyTxError era ->
93+
NonEmpty (PredicateFailure (EraRule "LEDGER" era)) ->
9194
NewEpochState era ->
9295
Tx TopTx era ->
9396
TranslationContext era ->
94-
LedgerExamples era
97+
LedgerExamples "LEDGER" era
9598
mkLedgerExamples
9699
applyTxError
97100
newEpochState

eras/babbage/impl/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## 1.13.0.0
44

5+
* Add `BabbageApplyTxError` constructor for `ApplyTxError era`
56
* Add `babbageUtxoValidation`
67
* Add `babbageUtxoTests`
78
* Changed the type of the following fields to `CompactForm Coin` in `BabbagePParams`:

eras/babbage/impl/src/Cardano/Ledger/Babbage.hs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
{-# LANGUAGE DataKinds #-}
2+
{-# LANGUAGE DerivingStrategies #-}
23
{-# LANGUAGE FlexibleInstances #-}
4+
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
35
{-# LANGUAGE ScopedTypeVariables #-}
46
{-# LANGUAGE TypeApplications #-}
7+
{-# LANGUAGE TypeFamilies #-}
58
{-# LANGUAGE UndecidableInstances #-}
69
{-# OPTIONS_GHC -Wno-orphans #-}
710

@@ -10,6 +13,7 @@ module Cardano.Ledger.Babbage (
1013
BabbageTxOut,
1114
TxBody (BabbageTxBody),
1215
Tx (..),
16+
ApplyTxError (..),
1317
AlonzoScript,
1418
AlonzoTxAuxData,
1519
) where
@@ -26,11 +30,20 @@ import Cardano.Ledger.Babbage.Tx (Tx (..))
2630
import Cardano.Ledger.Babbage.TxBody (BabbageTxOut, TxBody (BabbageTxBody))
2731
import Cardano.Ledger.Babbage.TxInfo ()
2832
import Cardano.Ledger.Babbage.UTxO ()
33+
import Cardano.Ledger.Binary (DecCBOR, EncCBOR)
2934
import Cardano.Ledger.Shelley.API
35+
import Cardano.Ledger.Shelley.Rules (ShelleyLedgerPredFailure)
36+
import Data.Bifunctor (Bifunctor (first))
37+
import Data.List.NonEmpty (NonEmpty)
3038

3139
-- =====================================================
3240

3341
instance ApplyTx BabbageEra where
34-
applyTxValidation = ruleApplyTxValidation @"LEDGER"
42+
newtype ApplyTxError BabbageEra = BabbageApplyTxError (NonEmpty (ShelleyLedgerPredFailure BabbageEra))
43+
deriving (Eq, Show)
44+
deriving newtype (EncCBOR, DecCBOR)
45+
applyTxValidation validationPolicy globals env state tx =
46+
first BabbageApplyTxError $
47+
ruleApplyTxValidation @"LEDGER" validationPolicy globals env state tx
3548

3649
instance ApplyBlock BabbageEra

0 commit comments

Comments
 (0)