Skip to content

Commit 9f98a9e

Browse files
Lucsanszkylehins
andauthored
Convert CertState to a type family (#4861)
Resolves #4693 Co-authored-by: Alexey Kuleshevich <alexey.kuleshevich@iohk.io>
1 parent 2ff5fa4 commit 9f98a9e

File tree

168 files changed

+1654
-898
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

168 files changed

+1654
-898
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.7.0.0
44

5+
* Converted `CertState` to a type family
56
* Made the fields of predicate failures and environments lazy
67
* Add `Era era` constraint to `NoThunks` instance for `TimeLock`
78
* Remove `Era era` constraint from:

eras/allegra/impl/cardano-ledger-allegra.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ library
3434

3535
hs-source-dirs: src
3636
other-modules:
37+
Cardano.Ledger.Allegra.CertState
3738
Cardano.Ledger.Allegra.Era
3839
Cardano.Ledger.Allegra.PParams
3940
Cardano.Ledger.Allegra.Rules.Bbody
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{-# LANGUAGE DataKinds #-}
2+
{-# LANGUAGE TypeFamilies #-}
3+
{-# OPTIONS_GHC -Wno-orphans #-}
4+
5+
module Cardano.Ledger.Allegra.CertState () where
6+
7+
import Cardano.Ledger.Allegra.Era (AllegraEra)
8+
import Cardano.Ledger.CertState
9+
import Cardano.Ledger.Shelley.CertState
10+
import Data.Coerce (coerce)
11+
12+
instance EraCertState AllegraEra where
13+
type CertState AllegraEra = ShelleyCertState AllegraEra
14+
15+
mkCertState = mkShelleyCertState
16+
17+
upgradeCertState = coerce
18+
19+
certDStateL = shelleyCertDStateL
20+
{-# INLINE certDStateL #-}
21+
22+
certVStateL = shelleyCertVStateL
23+
{-# INLINE certVStateL #-}
24+
25+
certPStateL = shelleyCertPStateL
26+
{-# INLINE certPStateL #-}
27+
28+
obligationCertState = shelleyObligationCertState
29+
30+
certsTotalDepositsTxBody = shelleyCertsTotalDepositsTxBody
31+
32+
certsTotalRefundsTxBody = shelleyCertsTotalRefundsTxBody

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import Cardano.Ledger.BaseTypes (
3939
)
4040
import Cardano.Ledger.Binary (DecCBOR (..), EncCBOR (..), serialize)
4141
import Cardano.Ledger.Binary.Coders
42-
import Cardano.Ledger.CertState (certDState, dsGenDelegs)
42+
import Cardano.Ledger.CertState (EraCertState (..))
4343
import Cardano.Ledger.Coin (Coin)
4444
import Cardano.Ledger.Rules.ValidationMode (Test, runTest)
4545
import qualified Cardano.Ledger.Shelley.LedgerState as Shelley
@@ -175,13 +175,14 @@ utxoTransition ::
175175
, InjectRuleFailure "UTXO" AllegraUtxoPredFailure era
176176
, InjectRuleFailure "UTXO" Shelley.ShelleyUtxoPredFailure era
177177
, EraRule "UTXO" era ~ AllegraUTXO era
178+
, EraCertState era
178179
) =>
179180
TransitionRule (EraRule "UTXO" era)
180181
utxoTransition = do
181182
TRC (Shelley.UtxoEnv slot pp certState, utxos, tx) <- judgmentContext
182183
let Shelley.UTxOState utxo _ _ ppup _ _ = utxos
183184
txBody = tx ^. bodyTxL
184-
genDelegs = dsGenDelegs (certDState certState)
185+
genDelegs = certState ^. Shelley.certDStateL . Shelley.dsGenDelegsL
185186

186187
{- ininterval slot (txvld tx) -}
187188
runTest $ validateOutsideValidityIntervalUTxO slot txBody
@@ -308,6 +309,7 @@ instance
308309
, GovState era ~ ShelleyGovState era
309310
, InjectRuleFailure "UTXO" AllegraUtxoPredFailure era
310311
, InjectRuleFailure "UTXO" Shelley.ShelleyUtxoPredFailure era
312+
, EraCertState era
311313
) =>
312314
STS (AllegraUTXO era)
313315
where

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import Cardano.Ledger.Allegra.Core
1414
import Cardano.Ledger.Allegra.Era (AllegraEra, AllegraUTXOW)
1515
import Cardano.Ledger.Allegra.Rules.Utxo (AllegraUTXO, AllegraUtxoPredFailure)
1616
import Cardano.Ledger.BaseTypes
17+
import Cardano.Ledger.CertState
1718
import Cardano.Ledger.Shelley.LedgerState (UTxOState)
1819
import Cardano.Ledger.Shelley.Rules (
1920
ShelleyPpupPredFailure,
@@ -58,6 +59,7 @@ instance
5859
, Signal (EraRule "UTXO" era) ~ Tx era
5960
, EraRule "UTXOW" era ~ AllegraUTXOW era
6061
, InjectRuleFailure "UTXOW" ShelleyUtxowPredFailure era
62+
, EraCertState era
6163
) =>
6264
STS (AllegraUTXOW era)
6365
where

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

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

66
module Cardano.Ledger.Allegra.Transition (TransitionConfig (..)) where
77

8+
import Cardano.Ledger.Allegra.CertState ()
89
import Cardano.Ledger.Allegra.Era
910
import Cardano.Ledger.Allegra.Translation ()
1011
import Cardano.Ledger.Genesis (NoGenesis (..))

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@
1212

1313
module Cardano.Ledger.Allegra.Translation (shelleyToAllegraAVVMsToDelete) where
1414

15+
import Cardano.Ledger.Allegra.CertState ()
1516
import Cardano.Ledger.Allegra.Era (AllegraEra)
1617
import Cardano.Ledger.Allegra.Tx ()
1718
import Cardano.Ledger.Binary (DecoderError)
1819
import Cardano.Ledger.CertState (CommitteeState (..))
1920
import Cardano.Ledger.Genesis (NoGenesis (..))
2021
import Cardano.Ledger.Shelley (ShelleyEra)
22+
import Cardano.Ledger.Shelley.CertState (ShelleyCertState)
2123
import Cardano.Ledger.Shelley.Core
2224
import Cardano.Ledger.Shelley.LedgerState (
23-
CertState (..),
2425
DState (..),
2526
EpochState (..),
2627
LedgerState (..),
@@ -143,14 +144,7 @@ instance TranslateEra AllegraEra VState where
143144
instance TranslateEra AllegraEra PState where
144145
translateEra _ PState {..} = pure PState {..}
145146

146-
instance TranslateEra AllegraEra CertState where
147-
translateEra ctxt ls =
148-
pure
149-
CertState
150-
{ certDState = translateEra' ctxt $ certDState ls
151-
, certPState = translateEra' ctxt $ certPState ls
152-
, certVState = translateEra' ctxt $ certVState ls
153-
}
147+
instance TranslateEra AllegraEra ShelleyCertState
154148

155149
instance TranslateEra AllegraEra LedgerState where
156150
translateEra ctxt ls =

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

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

77
module Cardano.Ledger.Allegra.UTxO () where
88

9+
import Cardano.Ledger.Allegra.CertState ()
910
import Cardano.Ledger.Allegra.Core
1011
import Cardano.Ledger.Allegra.Era (AllegraEra)
1112
import Cardano.Ledger.Shelley.UTxO (

eras/alonzo/impl/CHANGELOG.md

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

33
## 1.13.0.0
44

5+
* Converted `CertState` to a type family
56
* Remove `reapplyAlonzoTx` as no longer needed.
67
* Add `TxInfoResult` data family, `mkTxInfoResult` and `lookupTxInfoResult` to `EraPlutusContext`
78
* Add `lookupTxInfoResultImpossible` helper
@@ -15,6 +16,7 @@
1516

1617
### `testlib`
1718

19+
* Converted `CertState` to a type family
1820
* Expose `alonzoFixupFees`
1921

2022
## 1.12.0.0

eras/alonzo/impl/cardano-ledger-alonzo.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ library
4848

4949
hs-source-dirs: src
5050
other-modules:
51+
Cardano.Ledger.Alonzo.CertState
5152
Cardano.Ledger.Alonzo.Era
5253
Cardano.Ledger.Alonzo.Rules.Bbody
5354
Cardano.Ledger.Alonzo.Rules.Deleg

0 commit comments

Comments
 (0)