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

Convert CertState to a type family #4861

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions eras/allegra/impl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 1.7.0.0

* Converted `CertState` to a type family
* Made the fields of predicate failures and environments lazy
* Add `Era era` constraint to `NoThunks` instance for `TimeLock`
* Remove `Era era` constraint from:
Expand Down
1 change: 1 addition & 0 deletions eras/allegra/impl/cardano-ledger-allegra.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ library

hs-source-dirs: src
other-modules:
Cardano.Ledger.Allegra.CertState
Cardano.Ledger.Allegra.Era
Cardano.Ledger.Allegra.PParams
Cardano.Ledger.Allegra.Rules.Bbody
Expand Down
39 changes: 39 additions & 0 deletions eras/allegra/impl/src/Cardano/Ledger/Allegra/CertState.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -Wno-orphans #-}

module Cardano.Ledger.Allegra.CertState (
ShelleyCertState (..),
toCertStatePairs,
) where

import Cardano.Ledger.Allegra.Era (AllegraEra)
import Cardano.Ledger.CertState
import Cardano.Ledger.Shelley.CertState
import Data.Coerce (coerce)

instance EraCertState AllegraEra where
type CertState AllegraEra = ShelleyCertState AllegraEra

mkCertState = mkShelleyCertState

upgradeCertState = coerce

certDStateL = shelleyCertDStateL
{-# INLINE certDStateL #-}

certVStateL = shelleyCertVStateL
{-# INLINE certVStateL #-}

certPStateL = shelleyCertPStateL
{-# INLINE certPStateL #-}

obligationCertState = shelleyObligationCertState

certsTotalDepositsTxBody = shelleyCertsTotalDepositsTxBody

certsTotalRefundsTxBody = shelleyCertsTotalRefundsTxBody
6 changes: 4 additions & 2 deletions eras/allegra/impl/src/Cardano/Ledger/Allegra/Rules/Utxo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import Cardano.Ledger.BaseTypes (
)
import Cardano.Ledger.Binary (DecCBOR (..), EncCBOR (..), serialize)
import Cardano.Ledger.Binary.Coders
import Cardano.Ledger.CertState (certDState, dsGenDelegs)
import Cardano.Ledger.CertState (EraCertState (..))
import Cardano.Ledger.Coin (Coin)
import Cardano.Ledger.Rules.ValidationMode (Test, runTest)
import qualified Cardano.Ledger.Shelley.LedgerState as Shelley
Expand Down Expand Up @@ -175,13 +175,14 @@ utxoTransition ::
, InjectRuleFailure "UTXO" AllegraUtxoPredFailure era
, InjectRuleFailure "UTXO" Shelley.ShelleyUtxoPredFailure era
, EraRule "UTXO" era ~ AllegraUTXO era
, EraCertState era
) =>
TransitionRule (EraRule "UTXO" era)
utxoTransition = do
TRC (Shelley.UtxoEnv slot pp certState, utxos, tx) <- judgmentContext
let Shelley.UTxOState utxo _ _ ppup _ _ = utxos
txBody = tx ^. bodyTxL
genDelegs = dsGenDelegs (certDState certState)
genDelegs = certState ^. Shelley.certDStateL . Shelley.dsGenDelegsL

{- ininterval slot (txvld tx) -}
runTest $ validateOutsideValidityIntervalUTxO slot txBody
Expand Down Expand Up @@ -308,6 +309,7 @@ instance
, GovState era ~ ShelleyGovState era
, InjectRuleFailure "UTXO" AllegraUtxoPredFailure era
, InjectRuleFailure "UTXO" Shelley.ShelleyUtxoPredFailure era
, EraCertState era
) =>
STS (AllegraUTXO era)
where
Expand Down
2 changes: 2 additions & 0 deletions eras/allegra/impl/src/Cardano/Ledger/Allegra/Rules/Utxow.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Cardano.Ledger.Allegra.Core
import Cardano.Ledger.Allegra.Era (AllegraEra, AllegraUTXOW)
import Cardano.Ledger.Allegra.Rules.Utxo (AllegraUTXO, AllegraUtxoPredFailure)
import Cardano.Ledger.BaseTypes
import Cardano.Ledger.CertState
import Cardano.Ledger.Shelley.LedgerState (UTxOState)
import Cardano.Ledger.Shelley.Rules (
ShelleyPpupPredFailure,
Expand Down Expand Up @@ -58,6 +59,7 @@ instance
, Signal (EraRule "UTXO" era) ~ Tx era
, EraRule "UTXOW" era ~ AllegraUTXOW era
, InjectRuleFailure "UTXOW" ShelleyUtxowPredFailure era
, EraCertState era
) =>
STS (AllegraUTXOW era)
where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

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

import Cardano.Ledger.Allegra.CertState ()
import Cardano.Ledger.Allegra.Era
import Cardano.Ledger.Allegra.Translation ()
import Cardano.Ledger.Genesis (NoGenesis (..))
Expand Down
12 changes: 3 additions & 9 deletions eras/allegra/impl/src/Cardano/Ledger/Allegra/Translation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@

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

import Cardano.Ledger.Allegra.CertState ()
import Cardano.Ledger.Allegra.Era (AllegraEra)
import Cardano.Ledger.Allegra.Tx ()
import Cardano.Ledger.Binary (DecoderError)
import Cardano.Ledger.CertState (CommitteeState (..))
import Cardano.Ledger.Genesis (NoGenesis (..))
import Cardano.Ledger.Shelley (ShelleyEra)
import Cardano.Ledger.Shelley.CertState (ShelleyCertState)
import Cardano.Ledger.Shelley.Core
import Cardano.Ledger.Shelley.LedgerState (
CertState (..),
DState (..),
EpochState (..),
LedgerState (..),
Expand Down Expand Up @@ -143,14 +144,7 @@ instance TranslateEra AllegraEra VState where
instance TranslateEra AllegraEra PState where
translateEra _ PState {..} = pure PState {..}

instance TranslateEra AllegraEra CertState where
translateEra ctxt ls =
pure
CertState
{ certDState = translateEra' ctxt $ certDState ls
, certPState = translateEra' ctxt $ certPState ls
, certVState = translateEra' ctxt $ certVState ls
}
instance TranslateEra AllegraEra ShelleyCertState

instance TranslateEra AllegraEra LedgerState where
translateEra ctxt ls =
Expand Down
1 change: 1 addition & 0 deletions eras/allegra/impl/src/Cardano/Ledger/Allegra/UTxO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

module Cardano.Ledger.Allegra.UTxO () where

import Cardano.Ledger.Allegra.CertState ()
import Cardano.Ledger.Allegra.Core
import Cardano.Ledger.Allegra.Era (AllegraEra)
import Cardano.Ledger.Shelley.UTxO (
Expand Down
2 changes: 2 additions & 0 deletions eras/alonzo/impl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 1.13.0.0

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

### `testlib`

* Converted `CertState` to a type family
* Expose `alonzoFixupFees`

## 1.12.0.0
Expand Down
1 change: 1 addition & 0 deletions eras/alonzo/impl/cardano-ledger-alonzo.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ library

hs-source-dirs: src
other-modules:
Cardano.Ledger.Alonzo.CertState
Lucsanszky marked this conversation as resolved.
Show resolved Hide resolved
Cardano.Ledger.Alonzo.Era
Cardano.Ledger.Alonzo.Rules.Bbody
Cardano.Ledger.Alonzo.Rules.Deleg
Expand Down
39 changes: 39 additions & 0 deletions eras/alonzo/impl/src/Cardano/Ledger/Alonzo/CertState.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -Wno-orphans #-}

module Cardano.Ledger.Alonzo.CertState (
ShelleyCertState (..),
toCertStatePairs,
) where

import Cardano.Ledger.Alonzo.Era (AlonzoEra)
import Cardano.Ledger.CertState
import Cardano.Ledger.Shelley.CertState
import Data.Coerce (coerce)

instance EraCertState AlonzoEra where
type CertState AlonzoEra = ShelleyCertState AlonzoEra

mkCertState = mkShelleyCertState

upgradeCertState = coerce

certDStateL = shelleyCertDStateL
{-# INLINE certDStateL #-}

certVStateL = shelleyCertVStateL
{-# INLINE certVStateL #-}

certPStateL = shelleyCertPStateL
{-# INLINE certPStateL #-}

obligationCertState = shelleyObligationCertState

certsTotalDepositsTxBody = shelleyCertsTotalDepositsTxBody

certsTotalRefundsTxBody = shelleyCertsTotalRefundsTxBody
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ import Cardano.Ledger.Alonzo.Rules.Utxos (AlonzoUtxosPredFailure)
import Cardano.Ledger.Alonzo.Rules.Utxow (AlonzoUTXOW, AlonzoUtxowEvent, AlonzoUtxowPredFailure)
import Cardano.Ledger.Alonzo.Tx (AlonzoEraTx (..), AlonzoTx (..), IsValid (..))
import Cardano.Ledger.BaseTypes (ShelleyBase)
import Cardano.Ledger.CertState (EraCertState)
import Cardano.Ledger.Shelley.Core
import Cardano.Ledger.Shelley.LedgerState (
CertState (..),
CertState,
LedgerState (..),
UTxOState (..),
)
Expand Down Expand Up @@ -166,6 +167,7 @@ instance
, State (EraRule "DELEGS" era) ~ CertState era
, Signal (EraRule "DELEGS" era) ~ Seq (TxCert era)
, ProtVerAtMost era 8
, EraCertState era
) =>
STS (AlonzoLEDGER era)
where
Expand Down
3 changes: 3 additions & 0 deletions eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Rules/Utxo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import Cardano.Ledger.Binary.Coders (
(!>),
(<!),
)
import Cardano.Ledger.CertState (EraCertState)
import Cardano.Ledger.Coin (Coin (unCoin), DeltaCoin, rationalToCoinViaCeiling, toDeltaCoin)
import Cardano.Ledger.Core
import Cardano.Ledger.Credential (Credential (..))
Expand Down Expand Up @@ -484,6 +485,7 @@ utxoTransition ::
, Environment (EraRule "UTXOS" era) ~ UtxoEnv era
, State (EraRule "UTXOS" era) ~ UTxOState era
, Signal (EraRule "UTXOS" era) ~ Tx era
, EraCertState era
) =>
TransitionRule (EraRule "UTXO" era)
utxoTransition = do
Expand Down Expand Up @@ -571,6 +573,7 @@ instance
, InjectRuleFailure "UTXO" AlonzoUtxoPredFailure era
, InjectRuleFailure "UTXO" AllegraUtxoPredFailure era
, ProtVerAtMost era 8
, EraCertState era
) =>
STS (AlonzoUTXO era)
where
Expand Down
7 changes: 5 additions & 2 deletions eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Rules/Utxos.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import Cardano.Ledger.Binary (
)
import Cardano.Ledger.Binary.Coders
import qualified Cardano.Ledger.Binary.Plain as Plain
import Cardano.Ledger.CertState (certDState, dsGenDelegs)
import Cardano.Ledger.CertState (EraCertState (..))
import Cardano.Ledger.Coin (Coin)
import Cardano.Ledger.Plutus.Evaluate (
PlutusWithContext,
Expand Down Expand Up @@ -125,6 +125,7 @@ instance
, Eq (EraRuleFailure "PPUP" era)
, Show (EraRuleFailure "PPUP" era)
, EraPlutusContext era
, EraCertState era
) =>
STS (AlonzoUTXOS era)
where
Expand Down Expand Up @@ -192,6 +193,7 @@ utxosTransition ::
, Eq (EraRuleFailure "PPUP" era)
, Show (EraRuleFailure "PPUP" era)
, EraPlutusContext era
, EraCertState era
) =>
TransitionRule (AlonzoUTXOS era)
utxosTransition =
Expand Down Expand Up @@ -249,13 +251,14 @@ alonzoEvalScriptsTxValid ::
, GovState era ~ ShelleyGovState era
, State (EraRule "PPUP" era) ~ ShelleyGovState era
, EraPlutusContext era
, EraCertState era
) =>
TransitionRule (AlonzoUTXOS era)
alonzoEvalScriptsTxValid = do
TRC (UtxoEnv slot pp certState, utxos@(UTxOState utxo _ _ pup _ _), tx) <-
judgmentContext
let txBody = tx ^. bodyTxL
genDelegs = dsGenDelegs (certDState certState)
genDelegs = certState ^. certDStateL . Shelley.dsGenDelegsL

() <- pure $! Debug.traceEvent validBegin ()

Expand Down
6 changes: 4 additions & 2 deletions eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Rules/Utxow.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import Cardano.Ledger.BaseTypes (
)
import Cardano.Ledger.Binary (DecCBOR (..), EncCBOR (..))
import Cardano.Ledger.Binary.Coders
import Cardano.Ledger.CertState (certDState, dsGenDelegs)
import Cardano.Ledger.CertState (EraCertState (..), dsGenDelegsL)
import Cardano.Ledger.Rules.ValidationMode (Test, runTest, runTestOnSignal)
import Cardano.Ledger.Shelley.LedgerState (UTxOState (..))
import Cardano.Ledger.Shelley.Rules (
Expand Down Expand Up @@ -324,6 +324,7 @@ alonzoStyleWitness ::
, Environment (EraRule "UTXO" era) ~ UtxoEnv era
, State (EraRule "UTXO" era) ~ UTxOState era
, Signal (EraRule "UTXO" era) ~ Tx era
, EraCertState era
) =>
TransitionRule (EraRule "UTXOW" era)
alonzoStyleWitness = do
Expand Down Expand Up @@ -370,7 +371,7 @@ alonzoStyleWitness = do
-- check genesis keys signatures for instantaneous rewards certificates
{- genSig := { hashKey gkey | gkey ∈ dom(genDelegs)} ∩ witsKeyHashes -}
{- { c ∈ txcerts txb ∩ TxCert_mir} ≠ ∅ ⇒ (|genSig| ≥ Quorum) ∧ (d pp > 0) -}
let genDelegs = dsGenDelegs (certDState certState)
let genDelegs = certState ^. certDStateL . dsGenDelegsL
coreNodeQuorum <- liftSTS $ asks quorum
runTest $
Shelley.validateMIRInsufficientGenesisSigs genDelegs coreNodeQuorum witsKeyHashes tx
Expand Down Expand Up @@ -416,6 +417,7 @@ instance
, Environment (EraRule "UTXO" era) ~ UtxoEnv era
, State (EraRule "UTXO" era) ~ UTxOState era
, Signal (EraRule "UTXO" era) ~ Tx era
, EraCertState era
) =>
STS (AlonzoUTXOW era)
where
Expand Down
15 changes: 5 additions & 10 deletions eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Translation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@

module Cardano.Ledger.Alonzo.Translation where

import Cardano.Ledger.Alonzo.CertState ()
import Cardano.Ledger.Alonzo.Core hiding (Tx)
import qualified Cardano.Ledger.Alonzo.Core as Core
import Cardano.Ledger.Alonzo.Era (AlonzoEra)
import Cardano.Ledger.Alonzo.Genesis (AlonzoGenesis (..))
import Cardano.Ledger.Alonzo.PParams ()
import Cardano.Ledger.Alonzo.Tx (AlonzoTx (..), IsValid (..))
import Cardano.Ledger.Binary (DecoderError)
import Cardano.Ledger.CertState (CommitteeState (..), PState (..), VState (..))
import Cardano.Ledger.CertState (CommitteeState (..), EraCertState (..), PState (..), VState (..))
import Cardano.Ledger.Shelley.CertState (ShelleyCertState)
import Cardano.Ledger.Shelley.LedgerState (
CertState (..),
DState (..),
EpochState (..),
LedgerState (..),
Expand Down Expand Up @@ -116,14 +117,8 @@ instance TranslateEra AlonzoEra VState where
instance TranslateEra AlonzoEra PState where
translateEra _ PState {..} = pure PState {..}

instance TranslateEra AlonzoEra CertState where
translateEra ctxt ls =
pure
CertState
{ certDState = translateEra' ctxt $ certDState ls
, certPState = translateEra' ctxt $ certPState ls
, certVState = translateEra' ctxt $ certVState ls
}
instance TranslateEra AlonzoEra ShelleyCertState where
translateEra (AlonzoGenesisWrapper _scs) = pure . upgradeCertState

instance TranslateEra AlonzoEra LedgerState where
translateEra ctxt ls =
Expand Down
5 changes: 3 additions & 2 deletions eras/alonzo/impl/src/Cardano/Ledger/Alonzo/UTxO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ module Cardano.Ledger.Alonzo.UTxO (
)
where

import Cardano.Ledger.Alonzo.CertState ()
import Cardano.Ledger.Alonzo.Core
import Cardano.Ledger.Alonzo.Era (AlonzoEra)
import Cardano.Ledger.Alonzo.Scripts (lookupPlutusScript, plutusScriptLanguage)
import Cardano.Ledger.Alonzo.TxWits (unTxDats)
import Cardano.Ledger.BaseTypes (StrictMaybe (..))
import Cardano.Ledger.CertState (CertState)
import Cardano.Ledger.CertState (EraCertState (..))
import Cardano.Ledger.Credential (credScriptHash)
import Cardano.Ledger.Mary.UTxO (getConsumedMaryValue, getProducedMaryValue)
import Cardano.Ledger.Mary.Value (PolicyID (..))
Expand Down Expand Up @@ -314,7 +315,7 @@ getMintingScriptsNeeded txBody =
-- | Just like `getShelleyWitsVKeyNeeded`, but also requires `reqSignerHashesTxBodyL`.
getAlonzoWitsVKeyNeeded ::
forall era.
(EraTx era, AlonzoEraTxBody era, ShelleyEraTxBody era) =>
(EraTx era, AlonzoEraTxBody era, ShelleyEraTxBody era, EraCertState era) =>
CertState era ->
UTxO era ->
TxBody era ->
Expand Down
Loading
Loading