Skip to content

Commit eea5610

Browse files
authored
Merge pull request #1103 from IntersectMBO/jordan/remove-ProtocolParametersUpdate
Remove ProtocolParametersUpdate
2 parents ab1b173 + ae75973 commit eea5610

9 files changed

Lines changed: 302 additions & 732 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
project: cardano-api
2+
pr: 1103
3+
kind:
4+
- breaking
5+
description: |
6+
Remove the deprecated `ProtocolParametersUpdate` type and the `toLedgerPParamsUpdate` conversion function. Use `EraBasedProtocolParametersUpdate` instead.
7+
8+
The `toLedgerUpdate`, `fromLedgerUpdate`, `toLedgerProposedPPUpdates`, `fromLedgerProposedPPUpdates` and `fromLedgerPParamsUpdate` functions are kept but their signatures are now era-indexed: they operate on `UpdateProposal era` / `EraBasedProtocolParametersUpdate era` instead of the removed type, and require a `ShelleyBasedEra era` argument.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
project: cardano-api
2+
pr: 1103
3+
kind:
4+
- bugfix
5+
- breaking
6+
description: |
7+
Implement the previously-stubbed `ToCBOR`/`FromCBOR` instances for
8+
`EraBasedProtocolParametersUpdate` by routing through the ledger's
9+
`PParamsUpdate` encoding. The instance constraint changes from
10+
`Typeable era` to `IsShelleyBasedEra era`, which propagates to the
11+
`ToCBOR`, `FromCBOR` and `HasTextEnvelope` instances of `UpdateProposal`.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
project: cardano-api
2+
pr: 1103
3+
kind:
4+
- breaking
5+
description: |
6+
Remove the unused `TxBodyProtocolParamsConversionError` constructor of `TxBodyError`.

cardano-api/gen/Test/Gen/Cardano/Api/ProtocolParameters.hs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
{-# LANGUAGE GADTs #-}
2+
13
module Test.Gen.Cardano.Api.ProtocolParameters where
24

35
import Cardano.Api
46
import Cardano.Api.Ledger
57

6-
import Test.Gen.Cardano.Api.Typed (genCostModels)
7-
88
import Test.Cardano.Ledger.Alonzo.Arbitrary ()
99
import Test.Cardano.Ledger.Conway.Arbitrary ()
1010

@@ -51,9 +51,9 @@ genShelleyToAlonzoPParams =
5151

5252
genAlonzoOnwardsPParams :: MonadGen m => m (AlonzoOnwardsPParams era)
5353
genAlonzoOnwardsPParams =
54-
AlonzoOnwardsPParams
55-
<$> genStrictMaybe genCostModels
56-
<*> genStrictMaybe Q.arbitrary
54+
-- Cost models don't roundtrip through CBOR, hence SNothing
55+
AlonzoOnwardsPParams SNothing
56+
<$> genStrictMaybe Q.arbitrary
5757
<*> genStrictMaybe Q.arbitrary
5858
<*> genStrictMaybe Q.arbitrary
5959
<*> genStrictMaybe Q.arbitrary
@@ -76,6 +76,24 @@ genIntroducedInConwayPParams =
7676
<*> genStrictMaybe Q.arbitrary
7777
<*> genStrictMaybe Q.arbitrary
7878

79+
genEraBasedProtocolParametersUpdate
80+
:: MonadGen m
81+
=> CardanoEra era
82+
-> m (EraBasedProtocolParametersUpdate era)
83+
genEraBasedProtocolParametersUpdate era =
84+
case era of
85+
ByronEra ->
86+
error
87+
"genEraBasedProtocolParametersUpdate: ByronEra does not support \
88+
\protocol parameter updates"
89+
ShelleyEra -> genShelleyEraBasedProtocolParametersUpdate
90+
AllegraEra -> genAllegraEraBasedProtocolParametersUpdate
91+
MaryEra -> genMaryEraBasedProtocolParametersUpdate
92+
AlonzoEra -> genAlonzoEraBasedProtocolParametersUpdate
93+
BabbageEra -> genBabbageEraBasedProtocolParametersUpdate
94+
ConwayEra -> genConwayEraBasedProtocolParametersUpdate
95+
DijkstraEra -> error "TODO Dijkstra: genEraBasedProtocolParametersUpdate: era not supported"
96+
7997
genShelleyEraBasedProtocolParametersUpdate
8098
:: MonadGen m => m (EraBasedProtocolParametersUpdate ShelleyEra)
8199
genShelleyEraBasedProtocolParametersUpdate =

cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs

Lines changed: 60 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
{-# LANGUAGE NamedFieldPuns #-}
66
{-# LANGUAGE OverloadedStrings #-}
77
{-# LANGUAGE RankNTypes #-}
8-
{-# LANGUAGE RecordWildCards #-}
98
{-# LANGUAGE ScopedTypeVariables #-}
109
{-# LANGUAGE TupleSections #-}
1110
{-# LANGUAGE TypeApplications #-}
@@ -28,6 +27,8 @@ module Test.Gen.Cardano.Api.Typed
2827
, genCostModel
2928
, genCostModels
3029
, genMaybePraosNonce
30+
, genTxUpdateProposal
31+
, genUpdateProposal
3132
, genPraosNonce
3233
, genValidProtocolParameters
3334
, genValueNestedRep
@@ -107,15 +108,12 @@ module Test.Gen.Cardano.Api.Typed
107108
, genValueDefault
108109
, genVerificationKey
109110
, genVerificationKeyHash
110-
, genUpdateProposal
111-
, genProtocolParametersUpdate
112111
, genTxOutDatumHashTxContext
113112
, genTxOutDatumHashUTxOContext
114113
, genTxOutValue
115114
, genTxReturnCollateral
116115
, genTxScriptValidity
117116
, genTxTotalCollateral
118-
, genTxUpdateProposal
119117
, genTxValidityLowerBound
120118
, genTxValidityUpperBound
121119
, genTxWithdrawals
@@ -165,12 +163,10 @@ import Cardano.Api.Parser.Text qualified as P
165163
import Cardano.Api.Tx qualified as A
166164

167165
import Cardano.Binary qualified as CBOR
168-
import Cardano.Crypto.DSIGN.Class qualified as Crypto
169166
import Cardano.Crypto.Hash qualified as Crypto
170167
import Cardano.Crypto.Hash.Class qualified as CRYPTO
171168
import Cardano.Crypto.Seed qualified as Crypto
172169
import Cardano.Ledger.Alonzo.Scripts qualified as Alonzo
173-
import Cardano.Ledger.BaseTypes qualified as Ledger
174170
import Cardano.Ledger.Core qualified as Ledger
175171
import Cardano.Ledger.Hashes (unsafeMakeSafeHash)
176172
import Cardano.Ledger.Plutus.Language qualified as L
@@ -187,17 +183,19 @@ import Data.Maybe
187183
import Data.Ratio (Ratio, (%))
188184
import Data.String
189185
import Data.Typeable
190-
import Data.Word (Word16, Word32, Word64)
186+
import Data.Word (Word32, Word64)
191187
import GHC.Exts (IsList (..))
192188
import GHC.Stack
193189
import Numeric.Natural (Natural)
194190

195191
import Test.Gen.Cardano.Api.Era (conwayEraOnwardsTestConstraints, shelleyBasedEraTestConstraints)
196192
import Test.Gen.Cardano.Api.Hardcoded
197193
import Test.Gen.Cardano.Api.Metadata (genTxMetadata)
194+
import Test.Gen.Cardano.Api.ProtocolParameters (genEraBasedProtocolParametersUpdate)
198195

199196
import Test.Cardano.Chain.UTxO.Gen (genVKWitness)
200197
import Test.Cardano.Crypto.Gen (genProtocolMagicId)
198+
import Test.Cardano.Ledger.Alonzo.Arbitrary ()
201199
import Test.Cardano.Ledger.Conway.Arbitrary ()
202200
import Test.Cardano.Ledger.Core.Arbitrary ()
203201

@@ -655,15 +653,6 @@ genPaymentCredential = do
655653
vKey <- genVerificationKey AsPaymentKey
656654
return . PaymentCredentialByKey $ verificationKeyHash vKey
657655

658-
genSigningKey :: Key keyrole => AsType keyrole -> Gen (SigningKey keyrole)
659-
genSigningKey roletoken = do
660-
seed <- genSeed (fromIntegral seedSize)
661-
let sk = deterministicSigningKey roletoken seed
662-
return sk
663-
where
664-
seedSize :: Word
665-
seedSize = deterministicSigningKeySeedSize roletoken
666-
667656
genStakeAddress :: Gen StakeAddress
668657
genStakeAddress = makeStakeAddress <$> genNetworkId <*> genStakeCredential
669658

@@ -955,15 +944,6 @@ genMirCertificateRequirements w =
955944
shelleyToBabbageEraConstraints w $
956945
MirCertificateRequirements w <$> Q.arbitrary <*> Q.arbitrary
957946

958-
genTxUpdateProposal :: CardanoEra era -> Gen (TxUpdateProposal era)
959-
genTxUpdateProposal sbe =
960-
Gen.choice $
961-
catMaybes
962-
[ Just $ pure TxUpdateProposalNone
963-
, forEraInEon sbe Nothing $ \w ->
964-
Just $ TxUpdateProposal w <$> genUpdateProposal (toCardanoEra w)
965-
]
966-
967947
genTxMintValue :: CardanoEra era -> Gen (TxMintValue BuildTx era)
968948
genTxMintValue =
969949
inEonForEra
@@ -1183,23 +1163,6 @@ genWitnesses sbe = do
11831163
keyWits <- Gen.list (Range.constant 0 10) (genShelleyKeyWitness sbe)
11841164
return $ bsWits ++ keyWits
11851165

1186-
genVerificationKey
1187-
:: ()
1188-
=> HasTypeProxy keyrole
1189-
=> Key keyrole
1190-
=> AsType keyrole
1191-
-> Gen (VerificationKey keyrole)
1192-
genVerificationKey roletoken = getVerificationKey <$> genSigningKey roletoken
1193-
1194-
genVerificationKeyHash
1195-
:: ()
1196-
=> HasTypeProxy keyrole
1197-
=> Key keyrole
1198-
=> AsType keyrole
1199-
-> Gen (Hash keyrole)
1200-
genVerificationKeyHash roletoken =
1201-
verificationKeyHash <$> genVerificationKey roletoken
1202-
12031166
genByronKeyWitness :: Gen (KeyWitness ByronEra)
12041167
genByronKeyWitness = do
12051168
pmId <- genProtocolMagicId
@@ -1260,18 +1223,9 @@ genCardanoKeyWitness
12601223
-> Gen (KeyWitness era)
12611224
genCardanoKeyWitness = genShelleyWitness
12621225

1263-
genSeed :: Int -> Gen Crypto.Seed
1264-
genSeed n = Crypto.mkSeedFromBytes <$> Gen.bytes (Range.singleton n)
1265-
12661226
genNat :: Gen Natural
12671227
genNat = Gen.integral (Range.linear 0 10)
12681228

1269-
genWord16 :: Gen Word16
1270-
genWord16 = Gen.integral (Range.linear 0 10)
1271-
1272-
genWord32 :: Gen Word32
1273-
genWord32 = Gen.integral (Range.linear 0 10)
1274-
12751229
genRational :: Gen Rational
12761230
genRational =
12771231
(\d -> ratioToRational (1 % d)) <$> genDenominator
@@ -1294,12 +1248,6 @@ genRationalInt64 =
12941248
ratioToRational :: Ratio Int64 -> Rational
12951249
ratioToRational = toRational
12961250

1297-
genEpochNo :: Gen EpochNo
1298-
genEpochNo = EpochNo <$> Gen.word64 (Range.linear 0 10)
1299-
1300-
genEpochInterval :: Gen Ledger.EpochInterval
1301-
genEpochInterval = Ledger.EpochInterval <$> Gen.word32 (Range.linear 0 10)
1302-
13031251
genPraosNonce :: Gen PraosNonce
13041252
genPraosNonce = makePraosNonce <$> Gen.bytes (Range.linear 0 32)
13051253

@@ -1313,56 +1261,9 @@ genValidProtocolParameters sbe =
13131261
shelleyBasedEraTestConstraints sbe $
13141262
LedgerProtocolParameters <$> Q.arbitrary
13151263

1316-
genProtocolParametersUpdate :: CardanoEra era -> Gen ProtocolParametersUpdate
1317-
genProtocolParametersUpdate era = do
1318-
protocolUpdateProtocolVersion <- Gen.maybe ((,) <$> genNat <*> genNat)
1319-
protocolUpdateDecentralization <- Gen.maybe genRational
1320-
protocolUpdateExtraPraosEntropy <- Gen.maybe genMaybePraosNonce
1321-
protocolUpdateMaxBlockHeaderSize <- Gen.maybe genWord16
1322-
protocolUpdateMaxBlockBodySize <- Gen.maybe genWord32
1323-
protocolUpdateMaxTxSize <- Gen.maybe genWord32
1324-
protocolUpdateTxFeeFixed <- Gen.maybe genLovelace
1325-
protocolUpdateTxFeePerByte <- Gen.maybe genLovelace
1326-
protocolUpdateMinUTxOValue <- Gen.maybe genLovelace
1327-
protocolUpdateStakeAddressDeposit <- Gen.maybe genLovelace
1328-
protocolUpdateStakePoolDeposit <- Gen.maybe genLovelace
1329-
protocolUpdateMinPoolCost <- Gen.maybe genLovelace
1330-
protocolUpdatePoolRetireMaxEpoch <- Gen.maybe genEpochInterval
1331-
protocolUpdateStakePoolTargetNum <- Gen.maybe genWord16
1332-
protocolUpdatePoolPledgeInfluence <- Gen.maybe genRationalInt64
1333-
protocolUpdateMonetaryExpansion <- Gen.maybe genRational
1334-
protocolUpdateTreasuryCut <- Gen.maybe genRational
1335-
let protocolUpdateCostModels = mempty -- genCostModels
1336-
-- TODO: Babbage figure out how to deal with
1337-
-- asymmetric cost model JSON instances
1338-
protocolUpdatePrices <- Gen.maybe genExecutionUnitPrices
1339-
protocolUpdateMaxTxExUnits <- Gen.maybe genExecutionUnits
1340-
protocolUpdateMaxBlockExUnits <- Gen.maybe genExecutionUnits
1341-
protocolUpdateMaxValueSize <- Gen.maybe genWord32
1342-
protocolUpdateCollateralPercent <- Gen.maybe genWord16
1343-
protocolUpdateMaxCollateralInputs <- Gen.maybe genWord16
1344-
protocolUpdateUTxOCostPerByte <-
1345-
inEonForEra @BabbageEraOnwards (pure Nothing) (const (Just <$> genLovelace)) era
1346-
1347-
pure ProtocolParametersUpdate{..}
1348-
1349-
genUpdateProposal :: CardanoEra era -> Gen UpdateProposal
1350-
genUpdateProposal era =
1351-
UpdateProposal
1352-
<$> Gen.map
1353-
(Range.constant 1 3)
1354-
( (,)
1355-
<$> genVerificationKeyHash AsGenesisKey
1356-
<*> genProtocolParametersUpdate era
1357-
)
1358-
<*> genEpochNo
1359-
13601264
genCostModel :: MonadGen m => m Alonzo.CostModel
13611265
genCostModel = Q.arbitrary
13621266

1363-
genCostModels :: MonadGen m => m Alonzo.CostModels
1364-
genCostModels = Q.arbitrary
1365-
13661267
genExecutionUnits :: Gen ExecutionUnits
13671268
genExecutionUnits =
13681269
ExecutionUnits
@@ -1733,3 +1634,58 @@ genChainPoint =
17331634
genChainPointAt :: SlotNo -> Gen ChainPoint
17341635
genChainPointAt s =
17351636
ChainPoint s <$> genBlockHeaderHash
1637+
1638+
genEpochNo :: Gen EpochNo
1639+
genEpochNo = EpochNo <$> Gen.word64 (Range.linear 0 10)
1640+
1641+
genCostModels :: MonadGen m => m Alonzo.CostModels
1642+
genCostModels = Q.arbitrary
1643+
1644+
genVerificationKeyHash
1645+
:: ()
1646+
=> HasTypeProxy keyrole
1647+
=> Key keyrole
1648+
=> AsType keyrole
1649+
-> Gen (Hash keyrole)
1650+
genVerificationKeyHash roletoken =
1651+
verificationKeyHash <$> genVerificationKey roletoken
1652+
1653+
genVerificationKey
1654+
:: ()
1655+
=> HasTypeProxy keyrole
1656+
=> Key keyrole
1657+
=> AsType keyrole
1658+
-> Gen (VerificationKey keyrole)
1659+
genVerificationKey roletoken = getVerificationKey <$> genSigningKey roletoken
1660+
1661+
genSigningKey :: Key keyrole => AsType keyrole -> Gen (SigningKey keyrole)
1662+
genSigningKey roletoken = do
1663+
seed <- genSeed (fromIntegral seedSize)
1664+
let sk = deterministicSigningKey roletoken seed
1665+
return sk
1666+
where
1667+
seedSize :: Word
1668+
seedSize = deterministicSigningKeySeedSize roletoken
1669+
1670+
genSeed :: Int -> Gen Crypto.Seed
1671+
genSeed n = Crypto.mkSeedFromBytes <$> Gen.bytes (Range.singleton n)
1672+
1673+
genTxUpdateProposal :: CardanoEra era -> Gen (TxUpdateProposal era)
1674+
genTxUpdateProposal sbe =
1675+
Gen.choice $
1676+
catMaybes
1677+
[ Just $ pure TxUpdateProposalNone
1678+
, forEraInEon sbe Nothing $ \w ->
1679+
Just $ TxUpdateProposal w <$> genUpdateProposal (toCardanoEra w)
1680+
]
1681+
1682+
genUpdateProposal :: CardanoEra era -> Gen (UpdateProposal era)
1683+
genUpdateProposal era =
1684+
UpdateProposal
1685+
<$> Gen.map
1686+
(Range.constant 1 3)
1687+
( (,)
1688+
<$> genVerificationKeyHash AsGenesisKey
1689+
<*> genEraBasedProtocolParametersUpdate era
1690+
)
1691+
<*> genEpochNo

cardano-api/src/Cardano/Api/Compatible/Tx.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import Lens.Micro hiding (ix)
5050
data AnyProtocolUpdate era where
5151
ProtocolUpdate
5252
:: ShelleyToBabbageEra era
53-
-> UpdateProposal
53+
-> UpdateProposal era
5454
-> AnyProtocolUpdate era
5555
ProposalProcedures
5656
:: ConwayEraOnwards era
@@ -84,8 +84,8 @@ createCompatibleTx sbe ins outs txFee' anyProtocolUpdate anyVote txCertificates'
8484
(updateTxBody, extraScriptWitnesses) <-
8585
case anyProtocolUpdate of
8686
ProtocolUpdate shelleyToBabbageEra updateProposal -> do
87-
ledgerPParamsUpdate <- toLedgerUpdate sbe updateProposal
88-
let updateTxBody :: Endo (L.TxBody L.TopTx (ShelleyLedgerEra era)) =
87+
let ledgerPParamsUpdate = toLedgerUpdate sbe updateProposal
88+
updateTxBody :: Endo (L.TxBody L.TopTx (ShelleyLedgerEra era)) =
8989
shelleyToBabbageEraConstraints shelleyToBabbageEra $
9090
Endo $ \txb ->
9191
txb & L.updateTxBodyL .~ SJust ledgerPParamsUpdate

0 commit comments

Comments
 (0)