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,6 +101,7 @@ 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 ,
104107 ProtVer (ProtVer ),
@@ -141,22 +144,31 @@ import Data.Foldable (foldlM)
141144import Data.Functor.Identity (Identity )
142145import qualified Data.IntMap as IntMap
143146import qualified Data.Map.Strict as Map
144- import Data.Maybe (mapMaybe )
147+ import Data.Maybe (fromJust , mapMaybe )
145148import Data.Maybe.Strict (StrictMaybe (.. ))
146149import Data.Proxy
147150import Data.Set (Set )
148151import qualified Data.Set as Set
149152import Data.Typeable
150153import Data.Word (Word16 , Word32 )
151- import GHC.Generics (Generic )
154+ import GHC.Generics (Generic ( .. ), K1 ( .. ), M1 ( .. ), (:*:) ( .. ) )
152155import GHC.Stack (HasCallStack )
153- import Lens.Micro
156+ import Lens.Micro (Lens' , SimpleGetter , lens , set , (^.) )
157+ import qualified Lens.Micro as L
154158import NoThunks.Class (NoThunks (.. ))
155159import Numeric.Natural (Natural )
156160import qualified PlutusLedgerApi.Common as P (Data (.. ))
157161
158162class BabbageEraPParams era => ConwayEraPParams era where
159163 modifiedPPGroups :: PParamsUpdate era -> Set PPGroups
164+ default modifiedPPGroups ::
165+ forall a.
166+ ( Generic (PParamsHKD StrictMaybe era)
167+ , CollectModifiedPPGroups (Rep (PParamsHKD StrictMaybe era) a)
168+ ) =>
169+ PParamsUpdate era ->
170+ Set PPGroups
171+ modifiedPPGroups (PParamsUpdate ppu) = collectModifiedPPGroups $ from @ _ @ a ppu
160172 ppuWellFormed :: ProtVer -> PParamsUpdate era -> Bool
161173
162174 hkdPoolVotingThresholdsL :: HKDFunctor f => Lens' (PParamsHKD f era ) (HKD f PoolVotingThresholds )
@@ -169,6 +181,10 @@ class BabbageEraPParams era => ConwayEraPParams era where
169181 hkdDRepActivityL :: HKDFunctor f => Lens' (PParamsHKD f era ) (HKD f EpochInterval )
170182 hkdMinFeeRefScriptCostPerByteL ::
171183 HKDFunctor f => Lens' (PParamsHKD f era ) (HKD f NonNegativeInterval )
184+ ppMaxRefScriptSizePerTxG :: SimpleGetter (PParams era ) Word32
185+ ppMaxRefScriptSizePerBlockG :: SimpleGetter (PParams era ) Word32
186+ ppRefScriptCostMultiplierG :: SimpleGetter (PParams era ) NonNegativeInterval
187+ ppRefScriptCostStrideG :: SimpleGetter (PParams era ) Word32
172188
173189instance ConwayEraPParams era => ToPlutusData (PParamsUpdate era ) where
174190 toPlutusData ppu = P. Map $ mapMaybe ppToData (eraPParams @ era )
@@ -798,7 +814,7 @@ instance EraPParams ConwayEra where
798814 hkdMinPoolCostL = lens (unTHKD . cppMinPoolCost) $ \ pp x -> pp {cppMinPoolCost = THKD x}
799815 ppProtocolVersionL = ppLensHKD . lens cppProtocolVersion (\ pp x -> pp {cppProtocolVersion = x})
800816
801- ppDG = to (const minBound )
817+ ppDG = L. to (const minBound )
802818 ppuProtocolVersionL = notSupportedInThisEraL
803819 hkdDL = notSupportedInThisEraL
804820 hkdExtraEntropyL = notSupportedInThisEraL
@@ -871,7 +887,6 @@ instance BabbageEraPParams ConwayEra where
871887 lens (unTHKD . cppCoinsPerUTxOByte) $ \ pp x -> pp {cppCoinsPerUTxOByte = THKD x}
872888
873889instance ConwayEraPParams ConwayEra where
874- modifiedPPGroups (PParamsUpdate ppu) = conwayModifiedPPGroups ppu
875890 ppuWellFormed pv ppu =
876891 and
877892 [ -- Numbers
@@ -918,6 +933,10 @@ instance ConwayEraPParams ConwayEra where
918933 lens (unTHKD . cppDRepActivity) $ \ pp x -> pp {cppDRepActivity = THKD x}
919934 hkdMinFeeRefScriptCostPerByteL =
920935 lens (unTHKD . cppMinFeeRefScriptCostPerByte) $ \ pp x -> pp {cppMinFeeRefScriptCostPerByte = THKD x}
936+ ppMaxRefScriptSizePerTxG = L. to . const $ 200 * 1024
937+ ppMaxRefScriptSizePerBlockG = L. to . const $ 1024 * 1024
938+ ppRefScriptCostMultiplierG = L. to . const . fromJust $ boundRational 1.2
939+ ppRefScriptCostStrideG = L. to $ const 25_600
921940
922941-- | Returns a basic "empty" `PParams` structure with all zero values.
923942emptyConwayPParams :: forall era . Era era => ConwayPParams Identity era
@@ -1173,73 +1192,30 @@ conwayApplyPPUpdates pp ppu =
11731192 THKD SNothing -> cppGet pp
11741193 THKD (SJust ppNewValue) -> THKD ppNewValue
11751194
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- ]
1195+ class CollectModifiedPPGroups x where
1196+ collectModifiedPPGroups :: x -> Set PPGroups
1197+
1198+ instance
1199+ ( CollectModifiedPPGroups (x u )
1200+ , CollectModifiedPPGroups (y u )
1201+ ) =>
1202+ CollectModifiedPPGroups ((x :*: y ) u )
1203+ where
1204+ collectModifiedPPGroups (x :*: y) = collectModifiedPPGroups x <> collectModifiedPPGroups y
1205+
1206+ instance
1207+ ( ToDRepGroup g
1208+ , ToStakePoolGroup h
1209+ ) =>
1210+ CollectModifiedPPGroups (K1 i (THKD ('PPGroups g h ) StrictMaybe a ) p )
1211+ where
1212+ collectModifiedPPGroups (K1 x) = ppGroup x
1213+
1214+ instance CollectModifiedPPGroups (K1 i (NoUpdate a ) p ) where
1215+ collectModifiedPPGroups _ = mempty
1216+
1217+ instance CollectModifiedPPGroups (a u ) => CollectModifiedPPGroups (M1 i c a u ) where
1218+ collectModifiedPPGroups (M1 x) = collectModifiedPPGroups x
12431219
12441220-- | Care should be taken to not apply this function to signed values, otherwise it will result in
12451221-- an `ArithmeticUnderflow` exception for negative numbers.
0 commit comments