Skip to content

Commit 5e87a58

Browse files
Soupstrawlehins
andcommitted
Added DijkstraPParams
Co-authored-by: Alexey Kuleshevich <alexey.kuleshevich@iohk.io>
1 parent e250c6a commit 5e87a58

File tree

23 files changed

+811
-210
lines changed

23 files changed

+811
-210
lines changed

eras/alonzo/impl/CHANGELOG.md

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

33
## 1.14.0.0
44

5+
* Add `emptyUpgradePParamsUpdate` method to `AlonzoEraPParams`
56
* Rename `alonzoEqTxRaw` to `alonzoTxEqRaw`
67
* Add `Generic` instance to `TransactionScriptFailure`
78
* Add `Generic` instance for `AlonzoBbodyEvent`

eras/alonzo/impl/src/Cardano/Ledger/Alonzo/PParams.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{-# LANGUAGE AllowAmbiguousTypes #-}
22
{-# LANGUAGE DataKinds #-}
3+
{-# LANGUAGE DefaultSignatures #-}
34
{-# LANGUAGE DeriveAnyClass #-}
45
{-# LANGUAGE DeriveGeneric #-}
56
{-# LANGUAGE DerivingStrategies #-}
@@ -17,6 +18,7 @@
1718
{-# LANGUAGE StandaloneDeriving #-}
1819
{-# LANGUAGE TypeApplications #-}
1920
{-# LANGUAGE TypeFamilies #-}
21+
{-# LANGUAGE TypeOperators #-}
2022
{-# LANGUAGE UndecidableInstances #-}
2123
{-# LANGUAGE UndecidableSuperClasses #-}
2224
{-# OPTIONS_GHC -Wno-orphans #-}
@@ -147,6 +149,11 @@ class EraPParams era => AlonzoEraPParams era where
147149

148150
hkdMaxCollateralInputsL :: HKDFunctor f => Lens' (PParamsHKD f era) (HKD f Natural)
149151

152+
emptyUpgradePParamsUpdate :: UpgradePParams StrictMaybe era
153+
default emptyUpgradePParamsUpdate ::
154+
UpgradePParams StrictMaybe era ~ () => UpgradePParams StrictMaybe era
155+
emptyUpgradePParamsUpdate = ()
156+
150157
ppCoinsPerUTxOWordL ::
151158
forall era.
152159
(AlonzoEraPParams era, ExactEra AlonzoEra era) =>
@@ -359,6 +366,7 @@ instance EraPParams AlonzoEra where
359366
]
360367

361368
instance AlonzoEraPParams AlonzoEra where
369+
emptyUpgradePParamsUpdate = emptyAlonzoUpgradePParamsUpdate
362370
hkdCoinsPerUTxOWordL = lens appCoinsPerUTxOWord $ \pp x -> pp {appCoinsPerUTxOWord = x}
363371
hkdCostModelsL = lens appCostModels $ \pp x -> pp {appCostModels = x}
364372
hkdPricesL = lens appPrices $ \pp x -> pp {appPrices = x}
@@ -420,6 +428,10 @@ data UpgradeAlonzoPParams f = UpgradeAlonzoPParams
420428
}
421429
deriving (Generic)
422430

431+
emptyAlonzoUpgradePParamsUpdate :: UpgradeAlonzoPParams StrictMaybe
432+
emptyAlonzoUpgradePParamsUpdate =
433+
UpgradeAlonzoPParams SNothing SNothing SNothing SNothing SNothing SNothing SNothing SNothing
434+
423435
deriving instance Eq (UpgradeAlonzoPParams Identity)
424436

425437
deriving instance Show (UpgradeAlonzoPParams Identity)

eras/conway/impl/CHANGELOG.md

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

33
## 1.20.0.0
44

5+
* Removed:
6+
* `maxRefScriptSizePerTx`
7+
* `maxRefScriptSizePerBlock`
8+
* `refScriptCostMultiplier`
9+
* `refScriptCostStride`
10+
* Added:
11+
* `ppMaxRefScriptSizePerTxG`
12+
* `ppMaxRefScriptSizePerBlockG`
13+
* `ppRefScriptCostMultiplierG`
14+
* `ppRefScriptCostStrideG`
515
* Add `AlonzoEraTx` constraint to `STS` instance for `ConwayBBODY`
616
* Add `totalRefScriptSizeInBlock`
717
* Move some hard-fork triggers and export them from `Cardano.Ledger.Conway` module.

eras/conway/impl/src/Cardano/Ledger/Conway/PParams.hs

Lines changed: 68 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{-# LANGUAGE AllowAmbiguousTypes #-}
22
{-# LANGUAGE DataKinds #-}
3+
{-# LANGUAGE DefaultSignatures #-}
34
{-# LANGUAGE DeriveGeneric #-}
45
{-# LANGUAGE DerivingVia #-}
56
{-# LANGUAGE FlexibleContexts #-}
@@ -9,13 +10,15 @@
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

9092
import Cardano.Ledger.Alonzo.PParams
@@ -99,12 +101,16 @@ import Cardano.Ledger.Babbage (BabbageEra)
99101
import Cardano.Ledger.Babbage.Core
100102
import Cardano.Ledger.Babbage.PParams
101103
import 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
)
110116
import Cardano.Ledger.Binary (
@@ -141,22 +147,31 @@ import Data.Foldable (foldlM)
141147
import Data.Functor.Identity (Identity)
142148
import qualified Data.IntMap as IntMap
143149
import qualified Data.Map.Strict as Map
144-
import Data.Maybe (mapMaybe)
150+
import Data.Maybe (fromJust, mapMaybe)
145151
import Data.Maybe.Strict (StrictMaybe (..))
146152
import Data.Proxy
147153
import Data.Set (Set)
148154
import qualified Data.Set as Set
149155
import Data.Typeable
150156
import Data.Word (Word16, Word32)
151-
import GHC.Generics (Generic)
157+
import GHC.Generics (Generic (..), K1 (..), M1 (..), (:*:) (..))
152158
import GHC.Stack (HasCallStack)
153-
import Lens.Micro
159+
import Lens.Micro (Lens', SimpleGetter, lens, set, (^.))
160+
import qualified Lens.Micro as L
154161
import NoThunks.Class (NoThunks (..))
155162
import Numeric.Natural (Natural)
156163
import qualified PlutusLedgerApi.Common as P (Data (..))
157164

158165
class 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

173192
instance 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+
841874
instance 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

873907
instance 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.
923960
emptyConwayPParams :: 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.

eras/conway/impl/src/Cardano/Ledger/Conway/Rules/Bbody.hs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,12 @@
1919
module Cardano.Ledger.Conway.Rules.Bbody (
2020
ConwayBBODY,
2121
ConwayBbodyPredFailure (..),
22-
maxRefScriptSizePerBlock,
2322
alonzoToConwayBbodyPredFailure,
2423
shelleyToConwayBbodyPredFailure,
2524
totalRefScriptSizeInBlock,
2625
) where
2726

2827
import Cardano.Ledger.Allegra.Rules (AllegraUtxoPredFailure)
29-
import Cardano.Ledger.Alonzo.PParams (AlonzoEraPParams)
3028
import Cardano.Ledger.Alonzo.Rules (
3129
AlonzoBbodyEvent (..),
3230
AlonzoBbodyPredFailure (ShelleyInAlonzoBbodyPredFailure),
@@ -56,6 +54,7 @@ import Cardano.Ledger.Binary (DecCBOR (..), EncCBOR (..))
5654
import Cardano.Ledger.Binary.Coders (Decode (..), Encode (..), decode, encode, (!>), (<!))
5755
import Cardano.Ledger.Block (Block (..))
5856
import Cardano.Ledger.Conway.Era (ConwayBBODY, ConwayEra)
57+
import Cardano.Ledger.Conway.PParams (ConwayEraPParams (..))
5958
import Cardano.Ledger.Conway.Rules.Cert (ConwayCertPredFailure)
6059
import Cardano.Ledger.Conway.Rules.Certs (ConwayCertsPredFailure)
6160
import Cardano.Ledger.Conway.Rules.Deleg (ConwayDelegPredFailure)
@@ -97,16 +96,11 @@ import Data.Monoid (Sum (getSum))
9796
import qualified Data.Monoid as Monoid (Sum (..))
9897
import Data.Sequence (Seq)
9998
import Data.Sequence.Strict (StrictSeq (..))
99+
import Data.Word (Word32)
100100
import GHC.Generics (Generic)
101101
import Lens.Micro ((^.))
102102
import NoThunks.Class (NoThunks (..))
103103

104-
-- | In the next era this will become a proper protocol parameter.
105-
-- For now this is a hard coded limit on the total number of bytes of all reference scripts
106-
-- combined from all transactions within a block.
107-
maxRefScriptSizePerBlock :: Int
108-
maxRefScriptSizePerBlock = 1024 * 1024 -- 1MiB
109-
110104
data ConwayBbodyPredFailure era
111105
= WrongBlockBodySizeBBODY (Mismatch 'RelEQ Int)
112106
| InvalidBodyHashBBODY (Mismatch 'RelEQ (Hash HASH EraIndependentBlockBody))
@@ -252,7 +246,7 @@ instance
252246
, AlonzoEraTxWits era
253247
, TxSeq era ~ AlonzoTxSeq era
254248
, EraSegWits era
255-
, AlonzoEraPParams era
249+
, ConwayEraPParams era
256250
, InjectRuleFailure "BBODY" AlonzoBbodyPredFailure era
257251
, InjectRuleFailure "BBODY" ConwayBbodyPredFailure era
258252
, EraRule "BBODY" era ~ ConwayBBODY era
@@ -287,6 +281,7 @@ conwayBbodyTransition ::
287281
, InjectRuleFailure "BBODY" ConwayBbodyPredFailure era
288282
, AlonzoEraTx era
289283
, BabbageEraTxBody era
284+
, ConwayEraPParams era
290285
) =>
291286
TransitionRule (EraRule "BBODY" era)
292287
conwayBbodyTransition = do
@@ -300,6 +295,7 @@ conwayBbodyTransition = do
300295
let utxo = utxosUtxo (lsUTxOState ls)
301296
txs = txSeqTxns txsSeq
302297
totalRefScriptSize = totalRefScriptSizeInBlock (pp ^. ppProtocolVersionL) txs utxo
298+
maxRefScriptSizePerBlock = fromIntegral @Word32 @Int $ pp ^. ppMaxRefScriptSizePerBlockG
303299
totalRefScriptSize
304300
<= maxRefScriptSizePerBlock
305301
?! injectFailure

0 commit comments

Comments
 (0)