Skip to content

Commit 36be6ca

Browse files
authored
Merge pull request #5461 from IntersectMBO/f-f/5447
Swap Mempool/Ledger predicate failures in Dijkstra
2 parents 6059ffa + cfc0cc1 commit 36be6ca

File tree

40 files changed

+339
-141
lines changed

40 files changed

+339
-141
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
* Change sets containing errors into `NonEmptySet` for `AllegraUtxoPredFailure`
67
* Change all lists into `NonEmpty` for `AllegraUtxoPredFailure`
78
* Add `cddl` sub-library, and `generate-cddl` executable.

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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ import Cardano.Ledger.Allegra.TxBody
1919
import Cardano.Ledger.Coin
2020
import Cardano.Ledger.Genesis (NoGenesis (..))
2121
import Cardano.Ledger.Shelley.PParams (Update (..))
22+
import Cardano.Ledger.Shelley.Rules (
23+
ShelleyDelegsPredFailure (DelegateeNotRegisteredDELEG),
24+
ShelleyLedgerPredFailure (DelegsFailure),
25+
)
2226
import Cardano.Ledger.Shelley.Scripts
2327
import Cardano.Slotting.Slot
2428
import Data.Proxy
@@ -44,6 +48,9 @@ import Test.Cardano.Ledger.Shelley.Examples (
4448
ledgerExamples :: LedgerExamples AllegraEra
4549
ledgerExamples =
4650
mkLedgerExamples
51+
( AllegraApplyTxError . pure . DelegsFailure $
52+
DelegateeNotRegisteredDELEG @AllegraEra (mkKeyHash 1)
53+
)
4754
(mkWitnessesPreAlonzo (Proxy @AllegraEra))
4855
exampleCoin
4956
(exampleAllegraTxBody exampleCoin)

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
* Renamed:
67
- `appMinFeeA` -> `appTxFeePerByte`
78
- `appMinFeeB` -> `appTxFeeFixed`

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: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module Test.Cardano.Ledger.Alonzo.Examples (
1313
exampleAlonzoGenesis,
1414
) where
1515

16-
import Cardano.Ledger.Alonzo (AlonzoEra)
16+
import Cardano.Ledger.Alonzo (AlonzoEra, ApplyTxError (AlonzoApplyTxError))
1717
import Cardano.Ledger.Alonzo.Core
1818
import Cardano.Ledger.Alonzo.Genesis (AlonzoGenesis (..))
1919
import Cardano.Ledger.Alonzo.Plutus.Context (EraPlutusTxInfo)
@@ -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,7 +41,10 @@ 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+
ShelleyDelegsPredFailure (..),
46+
ShelleyLedgerPredFailure (..),
47+
)
4648
import Cardano.Ledger.Shelley.Scripts
4749
import Cardano.Ledger.TxIn (mkTxInPartial)
4850
import Cardano.Slotting.Slot (EpochNo (..), SlotNo (..))
@@ -75,7 +77,7 @@ import Test.Cardano.Ledger.Shelley.Examples (
7577
ledgerExamples :: LedgerExamples AlonzoEra
7678
ledgerExamples =
7779
mkLedgerExamples
78-
( ApplyTxError $
80+
( AlonzoApplyTxError $
7981
pure $
8082
DelegsFailure $
8183
DelegateeNotRegisteredDELEG @AlonzoEra (mkKeyHash 1)

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
* Renamed:
67
- `bppMinFeeA` -> `bppTxFeePerByte`
78
- `bppMinFeeB` -> `bppTxFeeFixed`

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)