11{-# LANGUAGE AllowAmbiguousTypes #-}
22{-# LANGUAGE DataKinds #-}
3+ {-# LANGUAGE DefaultSignatures #-}
34{-# LANGUAGE DeriveGeneric #-}
45{-# LANGUAGE DerivingVia #-}
56{-# LANGUAGE FlexibleContexts #-}
910{-# LANGUAGE LambdaCase #-}
1011{-# LANGUAGE MultiParamTypeClasses #-}
1112{-# LANGUAGE NamedFieldPuns #-}
13+ {-# LANGUAGE NumericUnderscores #-}
1214{-# LANGUAGE OverloadedStrings #-}
1315{-# LANGUAGE RankNTypes #-}
1416{-# LANGUAGE RecordWildCards #-}
1517{-# LANGUAGE ScopedTypeVariables #-}
1618{-# LANGUAGE StandaloneDeriving #-}
1719{-# LANGUAGE TypeApplications #-}
1820{-# LANGUAGE TypeFamilies #-}
21+ {-# LANGUAGE TypeOperators #-}
1922{-# LANGUAGE UndecidableInstances #-}
2023{-# LANGUAGE UndecidableSuperClasses #-}
2124{-# OPTIONS_GHC -Wno-orphans #-}
@@ -77,14 +80,13 @@ module Cardano.Ledger.Conway.PParams (
7780 DRepGroup (.. ),
7881 PPGroups (.. ),
7982 StakePoolGroup (.. ),
80- conwayModifiedPPGroups ,
8183 pvtHardForkInitiationL ,
8284 pvtMotionNoConfidenceL ,
83- conwayApplyPPUpdates ,
8485 emptyConwayPParams ,
8586 emptyConwayPParamsUpdate ,
8687 asNaturalHKD ,
8788 asBoundedIntegralHKD ,
89+ ppGroup ,
8890) where
8991
9092import Cardano.Ledger.Alonzo.PParams
@@ -99,12 +101,16 @@ import Cardano.Ledger.Babbage (BabbageEra)
99101import Cardano.Ledger.Babbage.Core
100102import Cardano.Ledger.Babbage.PParams
101103import Cardano.Ledger.BaseTypes (
104+ BoundedRational (.. ),
102105 EpochInterval (.. ),
103106 NonNegativeInterval ,
107+ NonZero ,
108+ PositiveInterval ,
104109 ProtVer (ProtVer ),
105110 ToKeyValuePairs (.. ),
106111 UnitInterval ,
107112 integralToBounded ,
113+ knownNonZeroBounded ,
108114 strictMaybeToMaybe ,
109115 )
110116import Cardano.Ledger.Binary (
@@ -141,22 +147,31 @@ import Data.Foldable (foldlM)
141147import Data.Functor.Identity (Identity )
142148import qualified Data.IntMap as IntMap
143149import qualified Data.Map.Strict as Map
144- import Data.Maybe (mapMaybe )
150+ import Data.Maybe (fromJust , mapMaybe )
145151import Data.Maybe.Strict (StrictMaybe (.. ))
146152import Data.Proxy
147153import Data.Set (Set )
148154import qualified Data.Set as Set
149155import Data.Typeable
150156import Data.Word (Word16 , Word32 )
151- import GHC.Generics (Generic )
157+ import GHC.Generics (Generic ( .. ), K1 ( .. ), M1 ( .. ), (:*:) ( .. ) )
152158import GHC.Stack (HasCallStack )
153- import Lens.Micro
159+ import Lens.Micro (Lens' , SimpleGetter , lens , set , (^.) )
160+ import qualified Lens.Micro as L
154161import NoThunks.Class (NoThunks (.. ))
155162import Numeric.Natural (Natural )
156163import qualified PlutusLedgerApi.Common as P (Data (.. ))
157164
158165class BabbageEraPParams era => ConwayEraPParams era where
159166 modifiedPPGroups :: PParamsUpdate era -> Set PPGroups
167+ default modifiedPPGroups ::
168+ forall a.
169+ ( Generic (PParamsHKD StrictMaybe era)
170+ , CollectModifiedPPGroups (Rep (PParamsHKD StrictMaybe era) a)
171+ ) =>
172+ PParamsUpdate era ->
173+ Set PPGroups
174+ modifiedPPGroups (PParamsUpdate ppu) = collectModifiedPPGroups $ from @ _ @ a ppu
160175 ppuWellFormed :: ProtVer -> PParamsUpdate era -> Bool
161176
162177 hkdPoolVotingThresholdsL :: HKDFunctor f => Lens' (PParamsHKD f era ) (HKD f PoolVotingThresholds )
@@ -169,6 +184,10 @@ class BabbageEraPParams era => ConwayEraPParams era where
169184 hkdDRepActivityL :: HKDFunctor f => Lens' (PParamsHKD f era ) (HKD f EpochInterval )
170185 hkdMinFeeRefScriptCostPerByteL ::
171186 HKDFunctor f => Lens' (PParamsHKD f era ) (HKD f NonNegativeInterval )
187+ ppMaxRefScriptSizePerTxG :: SimpleGetter (PParams era ) Word32
188+ ppMaxRefScriptSizePerBlockG :: SimpleGetter (PParams era ) Word32
189+ ppRefScriptCostMultiplierG :: SimpleGetter (PParams era ) PositiveInterval
190+ ppRefScriptCostStrideG :: SimpleGetter (PParams era ) (NonZero Word32 )
172191
173192instance ConwayEraPParams era => ToPlutusData (PParamsUpdate era ) where
174193 toPlutusData ppu = P. Map $ mapMaybe ppToData (eraPParams @ era )
@@ -798,7 +817,7 @@ instance EraPParams ConwayEra where
798817 hkdMinPoolCostL = lens (unTHKD . cppMinPoolCost) $ \ pp x -> pp {cppMinPoolCost = THKD x}
799818 ppProtocolVersionL = ppLensHKD . lens cppProtocolVersion (\ pp x -> pp {cppProtocolVersion = x})
800819
801- ppDG = to (const minBound )
820+ ppDG = L. to (const minBound )
802821 ppuProtocolVersionL = notSupportedInThisEraL
803822 hkdDL = notSupportedInThisEraL
804823 hkdExtraEntropyL = notSupportedInThisEraL
@@ -838,7 +857,22 @@ instance EraPParams ConwayEra where
838857 , ppMinFeeRefScriptCostPerByte
839858 ]
840859
860+ emptyConwayUpgradePParamsUpdate :: UpgradePParams StrictMaybe ConwayEra
861+ emptyConwayUpgradePParamsUpdate =
862+ UpgradeConwayPParams
863+ SNothing
864+ SNothing
865+ SNothing
866+ SNothing
867+ SNothing
868+ SNothing
869+ SNothing
870+ SNothing
871+ SNothing
872+ SNothing
873+
841874instance AlonzoEraPParams ConwayEra where
875+ emptyUpgradePParamsUpdate = emptyConwayUpgradePParamsUpdate
842876 hkdCoinsPerUTxOWordL = notSupportedInThisEraL
843877 hkdCostModelsL = lens (unTHKD . cppCostModels) $ \ pp x -> pp {cppCostModels = THKD x}
844878 hkdPricesL = lens (unTHKD . cppPrices) $ \ pp x -> pp {cppPrices = THKD x}
@@ -871,7 +905,6 @@ instance BabbageEraPParams ConwayEra where
871905 lens (unTHKD . cppCoinsPerUTxOByte) $ \ pp x -> pp {cppCoinsPerUTxOByte = THKD x}
872906
873907instance ConwayEraPParams ConwayEra where
874- modifiedPPGroups (PParamsUpdate ppu) = conwayModifiedPPGroups ppu
875908 ppuWellFormed pv ppu =
876909 and
877910 [ -- Numbers
@@ -918,6 +951,10 @@ instance ConwayEraPParams ConwayEra where
918951 lens (unTHKD . cppDRepActivity) $ \ pp x -> pp {cppDRepActivity = THKD x}
919952 hkdMinFeeRefScriptCostPerByteL =
920953 lens (unTHKD . cppMinFeeRefScriptCostPerByte) $ \ pp x -> pp {cppMinFeeRefScriptCostPerByte = THKD x}
954+ ppMaxRefScriptSizePerTxG = L. to . const $ 200 * 1024
955+ ppMaxRefScriptSizePerBlockG = L. to . const $ 1024 * 1024
956+ ppRefScriptCostMultiplierG = L. to . const . fromJust $ boundRational 1.2
957+ ppRefScriptCostStrideG = L. to . const $ knownNonZeroBounded @ 25_600
921958
922959-- | Returns a basic "empty" `PParams` structure with all zero values.
923960emptyConwayPParams :: forall era . Era era => ConwayPParams Identity era
@@ -1173,73 +1210,30 @@ conwayApplyPPUpdates pp ppu =
11731210 THKD SNothing -> cppGet pp
11741211 THKD (SJust ppNewValue) -> THKD ppNewValue
11751212
1176- conwayModifiedPPGroups :: ConwayPParams StrictMaybe era -> Set PPGroups
1177- conwayModifiedPPGroups
1178- ( ConwayPParams
1179- p01
1180- p02
1181- p03
1182- p04
1183- p05
1184- p06
1185- p07
1186- p08
1187- p09
1188- p10
1189- p11
1190- p12
1191- _protocolVersion
1192- p14
1193- p15
1194- p16
1195- p17
1196- p18
1197- p19
1198- p20
1199- p21
1200- p22
1201- p23
1202- p24
1203- p25
1204- p26
1205- p27
1206- p28
1207- p29
1208- p30
1209- p31
1210- ) =
1211- mconcat
1212- [ ppGroup p01
1213- , ppGroup p02
1214- , ppGroup p03
1215- , ppGroup p04
1216- , ppGroup p05
1217- , ppGroup p06
1218- , ppGroup p07
1219- , ppGroup p08
1220- , ppGroup p09
1221- , ppGroup p10
1222- , ppGroup p11
1223- , ppGroup p12
1224- , ppGroup p14
1225- , ppGroup p15
1226- , ppGroup p16
1227- , ppGroup p17
1228- , ppGroup p18
1229- , ppGroup p19
1230- , ppGroup p20
1231- , ppGroup p21
1232- , ppGroup p22
1233- , ppGroup p23
1234- , ppGroup p24
1235- , ppGroup p25
1236- , ppGroup p26
1237- , ppGroup p27
1238- , ppGroup p28
1239- , ppGroup p29
1240- , ppGroup p30
1241- , ppGroup p31
1242- ]
1213+ class CollectModifiedPPGroups x where
1214+ collectModifiedPPGroups :: x -> Set PPGroups
1215+
1216+ instance
1217+ ( CollectModifiedPPGroups (x u )
1218+ , CollectModifiedPPGroups (y u )
1219+ ) =>
1220+ CollectModifiedPPGroups ((x :*: y ) u )
1221+ where
1222+ collectModifiedPPGroups (x :*: y) = collectModifiedPPGroups x <> collectModifiedPPGroups y
1223+
1224+ instance
1225+ ( ToDRepGroup g
1226+ , ToStakePoolGroup h
1227+ ) =>
1228+ CollectModifiedPPGroups (K1 i (THKD ('PPGroups g h ) StrictMaybe a ) p )
1229+ where
1230+ collectModifiedPPGroups (K1 x) = ppGroup x
1231+
1232+ instance CollectModifiedPPGroups (K1 i (NoUpdate a ) p ) where
1233+ collectModifiedPPGroups _ = mempty
1234+
1235+ instance CollectModifiedPPGroups (a u ) => CollectModifiedPPGroups (M1 i c a u ) where
1236+ collectModifiedPPGroups (M1 x) = collectModifiedPPGroups x
12431237
12441238-- | Care should be taken to not apply this function to signed values, otherwise it will result in
12451239-- an `ArithmeticUnderflow` exception for negative numbers.
0 commit comments