Skip to content

Commit

Permalink
Rebase to master
Browse files Browse the repository at this point in the history
  • Loading branch information
Soupstraw committed Dec 2, 2022
1 parent 064acb8 commit ecb54fc
Show file tree
Hide file tree
Showing 24 changed files with 912 additions and 113 deletions.
7 changes: 7 additions & 0 deletions eras/conway/impl/cardano-ledger-conway.cabal
Expand Up @@ -43,6 +43,11 @@ library
Cardano.Ledger.Conway.Translation
Cardano.Ledger.Conway.Scripts
Cardano.Ledger.Conway
Cardano.Ledger.Conway.Rules
Cardano.Ledger.Conway.Rules.Utxo
Cardano.Ledger.Conway.Rules.Utxos
Cardano.Ledger.Conway.Core
Cardano.Ledger.Conway.Delegation.Certificates
other-modules:
Cardano.Ledger.Conway.Era
Cardano.Ledger.Conway.UTxO
Expand All @@ -57,8 +62,10 @@ library
cardano-ledger-mary,
cardano-ledger-shelley,
containers,
deepseq,
microlens,
nothunks,
small-steps,
cardano-strict-containers,
hs-source-dirs:
src
11 changes: 3 additions & 8 deletions eras/conway/impl/src/Cardano/Ledger/Conway.hs
Expand Up @@ -14,24 +14,20 @@ module Cardano.Ledger.Conway
)
where

import Cardano.Ledger.Alonzo (reapplyAlonzoTx)
import Cardano.Ledger.Alonzo.Genesis (AlonzoGenesis)
import Cardano.Ledger.Alonzo.TxInfo (ExtendedUTxO (..))
import Cardano.Ledger.Babbage.Core (BabbageEraTxBody (..))
import Cardano.Ledger.Babbage.Rules ()
import Cardano.Ledger.Babbage.Tx (babbageTxScripts, getDatumBabbage)
import Cardano.Ledger.Babbage.TxInfo (babbageTxInfo)
import Cardano.Ledger.Binary (sizedValue)
import Cardano.Ledger.Conway.Era (ConwayEra)
import Cardano.Ledger.Conway.Genesis (extendPPWithGenesis)
import Cardano.Ledger.Conway.PParams (BabbagePParamsHKD (..))
import Cardano.Ledger.Conway.Translation ()
import Cardano.Ledger.Conway.Tx ()
import Cardano.Ledger.Conway.TxBody (BabbageEraTxBody (..))
import Cardano.Ledger.Conway.TxOut (AlonzoEraTxOut (..))
import Cardano.Ledger.Conway.UTxO ()
import Cardano.Ledger.Crypto (Crypto, StandardCrypto)
import Cardano.Ledger.Hashes (EraIndependentTxBody)
import Cardano.Ledger.Keys (DSignable, Hash)
import qualified Cardano.Ledger.Shelley.API as API
import Cardano.Ledger.UTxO (UTxO (..))
import Data.Foldable (toList)
Expand All @@ -44,10 +40,9 @@ type Conway = ConwayEra StandardCrypto

-- =====================================================

instance (Crypto c, DSignable c (Hash c EraIndependentTxBody)) => API.ApplyTx (ConwayEra c) where
reapplyTx = reapplyAlonzoTx
-- instance (Crypto c, DSignable c (Hash c EraIndependentTxBody)) => API.ApplyTx (ConwayEra c) where

instance (Crypto c, DSignable c (Hash c EraIndependentTxBody)) => API.ApplyBlock (ConwayEra c)
-- instance (Crypto c, DSignable c (Hash c EraIndependentTxBody)) => API.ApplyBlock (ConwayEra c)

instance Crypto c => API.CanStartFromGenesis (ConwayEra c) where
type AdditionalGenesisConfig (ConwayEra c) = AlonzoGenesis
Expand Down
54 changes: 54 additions & 0 deletions eras/conway/impl/src/Cardano/Ledger/Conway/Core.hs
@@ -0,0 +1,54 @@
{-# LANGUAGE DeriveGeneric #-}

module Cardano.Ledger.Conway.Core
( ConwayEraTxBody (..),
GovernanceAction,
Vote,
)
where

import Cardano.Ledger.Babbage.Core (BabbageEraTxBody, Era, EraTxBody (..))
import Cardano.Ledger.Binary (FromCBOR (..), ToCBOR (..))
import Control.DeepSeq (NFData)
import Data.Sequence.Strict (StrictSeq)
import GHC.Generics (Generic)
import Lens.Micro (Lens')
import NoThunks.Class (NoThunks)

class BabbageEraTxBody era => ConwayEraTxBody era where
govActionsL :: Lens' (TxBody era) (StrictSeq (GovernanceAction era))
votesL :: Lens' (TxBody era) (StrictSeq (Vote era))

----- PLACEHOLDERS -----

data GovernanceAction era = GovernanceAction
deriving (Generic, Eq)

instance NoThunks (GovernanceAction era)

instance NFData (GovernanceAction era)

instance Show (GovernanceAction era) where
show = undefined

instance Era era => FromCBOR (GovernanceAction era) where
fromCBOR = undefined

instance Era era => ToCBOR (GovernanceAction era) where
toCBOR = undefined

data Vote era = Vote
deriving (Generic, Eq)

instance NoThunks (Vote era)

instance NFData (Vote era)

instance Show (Vote era) where
show = undefined

instance Era era => FromCBOR (Vote era) where
fromCBOR = undefined

instance Era era => ToCBOR (Vote era) where
toCBOR = undefined
102 changes: 102 additions & 0 deletions eras/conway/impl/src/Cardano/Ledger/Conway/Delegation/Certificates.hs
@@ -0,0 +1,102 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE LambdaCase #-}

module Cardano.Ledger.Conway.Delegation.Certificates
( ConwayDCert (..),
transDCert,
)
where

import Cardano.Ledger.BaseTypes (invalidKey)
import Cardano.Ledger.Binary
( FromCBOR (..),
FromCBORGroup (..),
ToCBOR (..),
ToCBORGroup (..),
decodeRecordSum,
encodeListLen,
listLenInt,
)
import qualified Cardano.Ledger.Crypto as CC
import Cardano.Ledger.Shelley.Delegation.Certificates (DCert (..), DelegCert (..), Delegation (..), GenesisDelegCert (..), PoolCert (..))
import Cardano.Ledger.Slot (EpochNo (..))
import Control.DeepSeq (NFData)
import Data.Word (Word8)
import GHC.Generics (Generic)
import NoThunks.Class (NoThunks)

data ConwayDCert c
= ConwayDCertDeleg !(DelegCert c)
| ConwayDCertPool !(PoolCert c)
| ConwayDCertGenesis !(GenesisDelegCert c)
deriving (Show, Generic, Eq)

instance NFData (ConwayDCert c)

instance NoThunks (ConwayDCert c)

instance CC.Crypto c => FromCBOR (ConwayDCert c) where
fromCBOR = decodeRecordSum "ConwayDCert c" $
\case
0 -> do
x <- fromCBOR
pure (2, ConwayDCertDeleg . RegKey $ x)
1 -> do
x <- fromCBOR
pure (2, ConwayDCertDeleg . DeRegKey $ x)
2 -> do
a <- fromCBOR
b <- fromCBOR
pure (3, ConwayDCertDeleg $ Delegate (Delegation a b))
3 -> do
group <- fromCBORGroup
pure (fromIntegral (1 + listLenInt group), ConwayDCertPool (RegPool group))
4 -> do
a <- fromCBOR
b <- fromCBOR
pure (3, ConwayDCertPool $ RetirePool a (EpochNo b))
5 -> do
a <- fromCBOR
b <- fromCBOR
c <- fromCBOR
pure (4, ConwayDCertGenesis $ GenesisDelegCert a b c)
k -> invalidKey k

instance CC.Crypto c => ToCBOR (ConwayDCert c) where
toCBOR = \case
-- DCertDeleg
ConwayDCertDeleg (RegKey cred) ->
encodeListLen 2
<> toCBOR (0 :: Word8)
<> toCBOR cred
ConwayDCertDeleg (DeRegKey cred) ->
encodeListLen 2
<> toCBOR (1 :: Word8)
<> toCBOR cred
ConwayDCertDeleg (Delegate (Delegation cred poolkh)) ->
encodeListLen 3
<> toCBOR (2 :: Word8)
<> toCBOR cred
<> toCBOR poolkh
-- DCertPool
ConwayDCertPool (RegPool poolParams) ->
encodeListLen (1 + listLen poolParams)
<> toCBOR (3 :: Word8)
<> toCBORGroup poolParams
ConwayDCertPool (RetirePool vk epoch) ->
encodeListLen 3
<> toCBOR (4 :: Word8)
<> toCBOR vk
<> toCBOR epoch
-- DCertGenesis
ConwayDCertGenesis (GenesisDelegCert gk kh vrf) ->
encodeListLen 4
<> toCBOR (5 :: Word8)
<> toCBOR gk
<> toCBOR kh
<> toCBOR vrf

transDCert :: ConwayDCert c -> DCert c
transDCert (ConwayDCertDeleg dc) = DCertDeleg dc
transDCert (ConwayDCertPool pc) = DCertPool pc
transDCert (ConwayDCertGenesis gdc) = DCertGenesis gdc
12 changes: 9 additions & 3 deletions eras/conway/impl/src/Cardano/Ledger/Conway/Era.hs
Expand Up @@ -3,11 +3,13 @@

module Cardano.Ledger.Conway.Era
( ConwayEra,
ConwayUTXO,
ConwayUTXOS,
)
where

import Cardano.Ledger.Alonzo.Rules (AlonzoBBODY)
import Cardano.Ledger.Babbage.Rules (BabbageLEDGER, BabbageUTXO, BabbageUTXOS, BabbageUTXOW)
import Cardano.Ledger.Babbage.Rules (BabbageLEDGER, BabbageUTXOW)
import Cardano.Ledger.Core
import qualified Cardano.Ledger.Crypto as CC
import Cardano.Ledger.Mary.Value (MaryValue)
Expand Down Expand Up @@ -40,9 +42,13 @@ type instance Value (ConwayEra c) = MaryValue c

-- Rules inherited from Babbage

type instance EraRule "UTXOS" (ConwayEra c) = BabbageUTXOS (ConwayEra c)
data ConwayUTXOS era

type instance EraRule "UTXO" (ConwayEra c) = BabbageUTXO (ConwayEra c)
type instance EraRule "UTXOS" (ConwayEra c) = ConwayUTXOS (ConwayEra c)

data ConwayUTXO era

type instance EraRule "UTXO" (ConwayEra c) = ConwayUTXO (ConwayEra c)

type instance EraRule "UTXOW" (ConwayEra c) = BabbageUTXOW (ConwayEra c)

Expand Down
11 changes: 11 additions & 0 deletions eras/conway/impl/src/Cardano/Ledger/Conway/Rules.hs
@@ -0,0 +1,11 @@
{-# OPTIONS_GHC -Wno-dodgy-exports #-}
{-# OPTIONS_GHC -Wno-unused-imports #-}

module Cardano.Ledger.Conway.Rules
( module Cardano.Ledger.Conway.Rules.Utxo,
module Cardano.Ledger.Conway.Rules.Utxos,
)
where

import Cardano.Ledger.Conway.Rules.Utxo
import Cardano.Ledger.Conway.Rules.Utxos
85 changes: 85 additions & 0 deletions eras/conway/impl/src/Cardano/Ledger/Conway/Rules/Utxo.hs
@@ -0,0 +1,85 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-orphans #-}

module Cardano.Ledger.Conway.Rules.Utxo () where

import Cardano.Ledger.Alonzo.Rules (AlonzoUtxoEvent (..), AlonzoUtxoPredFailure (..), AlonzoUtxosEvent, AlonzoUtxosPredFailure, AlonzoUtxowEvent (..))
import Cardano.Ledger.Alonzo.Scripts (AlonzoScript)
import Cardano.Ledger.Alonzo.Tx (AlonzoTx (..))
import Cardano.Ledger.Babbage (BabbageTxOut)
import Cardano.Ledger.Babbage.PParams (BabbagePParamsUpdate)
import Cardano.Ledger.Babbage.Rules (BabbageUTXOW, BabbageUtxoPredFailure (..), BabbageUtxowPredFailure (UtxoFailure))
import Cardano.Ledger.BaseTypes (ShelleyBase)
import Cardano.Ledger.Conway.Era (ConwayUTXO, ConwayUTXOS)
import Cardano.Ledger.Conway.Rules.Utxos ()
import Cardano.Ledger.Core
( EraPParams (..),
EraRule,
EraScript (..),
EraTx,
EraTxOut (..),
Value,
)
import Cardano.Ledger.Era (Era (..))
import Cardano.Ledger.Mary.Value (MaryValue (..))
import Cardano.Ledger.Rules.ValidationMode (Inject)
import Cardano.Ledger.Shelley.API (PPUPState (..))
import qualified Cardano.Ledger.Shelley.LedgerState as Shelley
import Cardano.Ledger.Shelley.Rules (ShelleyPpupPredFailure, ShelleyUtxowEvent (UtxoEvent), UtxoEnv (..))
import Control.State.Transition.Extended (Embed (..), STS (..))

instance
( EraTx era,
Value era ~ MaryValue era,
TxOut era ~ BabbageTxOut era,
State (EraRule "PPUP" era) ~ PPUPState era,
PredicateFailure (EraRule "UTXOS" era) ~ AlonzoUtxosPredFailure era,
PredicateFailure (EraRule "UTXO" era) ~ BabbageUtxoPredFailure era,
PredicateFailure (EraRule "PPUP" era) ~ ShelleyPpupPredFailure era
) =>
STS (ConwayUTXO era)
where
type State (ConwayUTXO era) = Shelley.UTxOState era
type Signal (ConwayUTXO era) = AlonzoTx era
type Environment (ConwayUTXO era) = UtxoEnv era
type BaseM (ConwayUTXO era) = ShelleyBase
type PredicateFailure (ConwayUTXO era) = BabbageUtxoPredFailure era
type Event (ConwayUTXO era) = AlonzoUtxoEvent era

initialRules = []
transitionRules = []

instance
( EraScript era,
PredicateFailure (EraRule "PPUP" era) ~ ShelleyPpupPredFailure era,
PredicateFailure (EraRule "UTXOS" era) ~ AlonzoUtxosPredFailure era,
Event (EraRule "UTXOS" era) ~ AlonzoUtxosEvent era,
Script era ~ AlonzoScript era,
State (EraRule "PPUP" era) ~ PPUPState era,
Value era ~ MaryValue (EraCrypto era),
TxOut era ~ BabbageTxOut era,
PParamsUpdate era ~ BabbagePParamsUpdate era,
Inject (PredicateFailure (EraRule "PPUP" era)) (PredicateFailure (EraRule "UTXOS" era))
) =>
Embed (ConwayUTXOS era) (ConwayUTXO era)
where
wrapFailed = AlonzoInBabbageUtxoPredFailure . UtxosFailure
wrapEvent = UtxosEvent

instance
( Era era,
STS (ConwayUTXO era),
PredicateFailure (EraRule "UTXO" era) ~ BabbageUtxoPredFailure era,
Event (EraRule "UTXO" era) ~ AlonzoUtxoEvent era,
BaseM (EraRule "UTXOW" era) ~ ShelleyBase,
PredicateFailure (EraRule "UTXOW" era) ~ BabbageUtxowPredFailure era,
Event (EraRule "UTXOW" era) ~ AlonzoUtxowEvent era
) =>
Embed (ConwayUTXO era) (BabbageUTXOW era)
where
wrapFailed = UtxoFailure
wrapEvent = WrappedShelleyEraEvent . UtxoEvent
42 changes: 42 additions & 0 deletions eras/conway/impl/src/Cardano/Ledger/Conway/Rules/Utxos.hs
@@ -0,0 +1,42 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-orphans #-}

module Cardano.Ledger.Conway.Rules.Utxos () where

import Cardano.Ledger.Alonzo.Rules (AlonzoUtxosEvent, AlonzoUtxosPredFailure)
import Cardano.Ledger.Alonzo.Scripts (AlonzoScript)
import Cardano.Ledger.Alonzo.Tx (AlonzoTx (..))
import Cardano.Ledger.BaseTypes (ShelleyBase)
import Cardano.Ledger.Conway.Era (ConwayUTXOS)
import Cardano.Ledger.Conway.PParams (BabbagePParamsUpdate)
import Cardano.Ledger.Conway.TxOut (BabbageTxOut (..))
import Cardano.Ledger.Core (Era (..), EraPParams (..), EraRule, EraScript (..), EraTxOut (..), Value)
import Cardano.Ledger.Mary.Value (MaryValue (..))
import Cardano.Ledger.Rules.ValidationMode (Inject)
import Cardano.Ledger.Shelley.LedgerState (PPUPState (..), UTxOState (..))
import Cardano.Ledger.Shelley.Rules (ShelleyPpupPredFailure, UtxoEnv (..))
import Control.State.Transition.Extended (STS (..))

instance
( EraScript era,
PredicateFailure (EraRule "PPUP" era) ~ ShelleyPpupPredFailure era,
TxOut era ~ BabbageTxOut era,
Value era ~ MaryValue (EraCrypto era),
Script era ~ AlonzoScript era,
State (EraRule "PPUP" era) ~ PPUPState era,
PParamsUpdate era ~ BabbagePParamsUpdate era,
Inject (PredicateFailure (EraRule "PPUP" era)) (PredicateFailure (EraRule "UTXOS" era))
) =>
STS (ConwayUTXOS era)
where
type BaseM (ConwayUTXOS era) = ShelleyBase
type Environment (ConwayUTXOS era) = UtxoEnv era
type State (ConwayUTXOS era) = UTxOState era
type Signal (ConwayUTXOS era) = AlonzoTx era
type PredicateFailure (ConwayUTXOS era) = AlonzoUtxosPredFailure era
type Event (ConwayUTXOS era) = AlonzoUtxosEvent era

transitionRules = []

0 comments on commit ecb54fc

Please sign in to comment.