Skip to content

Commit b400c83

Browse files
authored
Merge pull request #1598 from sgillespie/feature/test-proto-hf
Test: Hard Fork (Babbage -> Conway) with parameter update proposal
2 parents 50f6a2b + 26f9243 commit b400c83

File tree

167 files changed

+343
-164
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

167 files changed

+343
-164
lines changed

cardano-chain-gen/cardano-chain-gen.cabal

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ library
4444
Cardano.Mock.ChainDB
4545
Cardano.Mock.ChainSync.Server
4646
Cardano.Mock.ChainSync.State
47+
Cardano.Mock.Query
4748
Cardano.Mock.Forging.Crypto
4849
Cardano.Mock.Forging.Interpreter
4950
Cardano.Mock.Forging.Tx.Alonzo
@@ -63,6 +64,7 @@ library
6364
, bytestring
6465
, cardano-binary
6566
, cardano-crypto-class
67+
, cardano-db
6668
, cardano-ledger-allegra
6769
, cardano-ledger-alonzo
6870
, cardano-ledger-babbage
@@ -78,6 +80,7 @@ library
7880
, containers
7981
, contra-tracer
8082
, directory
83+
, esqueleto
8184
, extra
8285
, mtl
8386
, microlens

cardano-chain-gen/src/Cardano/Mock/Forging/Tx/Babbage.hs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
{-# LANGUAGE GADTs #-}
55
{-# LANGUAGE OverloadedStrings #-}
66
{-# LANGUAGE ScopedTypeVariables #-}
7+
{-# LANGUAGE TupleSections #-}
78
{-# LANGUAGE TypeApplications #-}
89
{-# LANGUAGE TypeOperators #-}
910
{-# OPTIONS_GHC -Wno-orphans #-}
@@ -44,6 +45,7 @@ module Cardano.Mock.Forging.Tx.Babbage (
4445
mkWitnesses,
4546
mkUTxOBabbage,
4647
mkUTxOCollBabbage,
48+
mkParamUpdateTx,
4749
mkFullTx,
4850
emptyTxBody,
4951
emptyTx,
@@ -90,6 +92,7 @@ import Lens.Micro
9092
import Ouroboros.Consensus.Cardano.Block (LedgerState)
9193
import Ouroboros.Consensus.Shelley.Eras (StandardBabbage, StandardCrypto)
9294
import Ouroboros.Consensus.Shelley.Ledger (ShelleyBlock)
95+
import Prelude hiding (map)
9396

9497
type BabbageUTxOIndex = UTxOIndex StandardBabbage
9598

@@ -515,6 +518,37 @@ emptyTx =
515518
, auxiliaryData = maybeToStrictMaybe Nothing
516519
}
517520

521+
mkParamUpdateTx :: Either ForgingError (AlonzoTx StandardBabbage)
522+
mkParamUpdateTx = Right (mkSimpleTx True txBody)
523+
where
524+
txBody =
525+
BabbageTxBody
526+
{ btbInputs = mempty
527+
, btbCollateral = mempty
528+
, btbReferenceInputs = mempty
529+
, btbOutputs = mempty
530+
, btbCollateralReturn = SNothing
531+
, btbTotalCollateral = SNothing
532+
, btbCerts = mempty
533+
, btbWithdrawals = Withdrawals mempty
534+
, btbTxFee = Coin 0
535+
, btbValidityInterval = ValidityInterval SNothing SNothing
536+
, btbUpdate = SJust $ Update update (EpochNo 1)
537+
, btbReqSignerHashes = mempty
538+
, btbMint = mempty
539+
, btbScriptIntegrityHash = SNothing
540+
, btbAuxDataHash = SNothing
541+
, btbTxNetworkId = SJust Testnet
542+
}
543+
update =
544+
ProposedPPUpdates $
545+
Map.fromList $
546+
map (,paramsUpdate) registeredShelleyGenesisKeys
547+
paramsUpdate =
548+
Core.emptyPParamsUpdate
549+
& ppuProtocolVersionL
550+
.~ SJust (ProtVer (natVersion @9) 0)
551+
518552
mkFullTx ::
519553
Int ->
520554
Integer ->

cardano-chain-gen/src/Cardano/Mock/Forging/Tx/Conway.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ module Cardano.Mock.Forging.Tx.Conway (
3232
mkRegTxCert,
3333
mkUnRegTxCert,
3434
mkDelegTxCert,
35+
Babbage.mkParamUpdateTx,
3536
mkFullTx,
3637
mkScriptMint,
3738
Babbage.mkScriptInp,

cardano-chain-gen/src/Cardano/Mock/Forging/Tx/Generic.hs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ module Cardano.Mock.Forging.Tx.Generic (
2222
unregisteredAddresses,
2323
unregisteredStakeCredentials,
2424
unregisteredPools,
25+
registeredByronGenesisKeys,
26+
registeredShelleyGenesisKeys,
2527
consPoolParams,
2628
getPoolStakeCreds,
2729
) where
@@ -249,6 +251,17 @@ unregisteredGenesisKeys =
249251
, KeyHash "33323876542397465497834256329487563428975634827956348975"
250252
]
251253

254+
registeredByronGenesisKeys :: [KeyHash 'Genesis StandardCrypto]
255+
registeredByronGenesisKeys =
256+
[ KeyHash "1a3e49767796fd99b057ad54db3310fd640806fcb0927399bbca7b43"
257+
]
258+
259+
registeredShelleyGenesisKeys :: [KeyHash 'Genesis StandardCrypto]
260+
registeredShelleyGenesisKeys =
261+
[ KeyHash "30c3083efd794227fde2351a04500349d1b467556c30e35d6794a501"
262+
, KeyHash "471cc34983f6a2fd7b4018e3147532185d69a448d6570d46019e58e6"
263+
]
264+
252265
createStakeCredentials :: Int -> [StakeCredential StandardCrypto]
253266
createStakeCredentials n =
254267
fmap (KeyHashObj . KeyHash . mkDummyHash (Proxy @(ADDRHASH StandardCrypto))) [1 .. n]
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{-# LANGUAGE TypeApplications #-}
2+
3+
module Cardano.Mock.Query (
4+
queryVersionMajorFromEpoch,
5+
queryParamProposalFromEpoch,
6+
) where
7+
8+
import qualified Cardano.Db as Db
9+
import Cardano.Prelude hiding (from)
10+
import Database.Esqueleto.Experimental
11+
import Prelude ()
12+
13+
-- | Query protocol parameters from @EpochParam@ by epoch number. Note that epoch
14+
-- parameters are inserted at the beginning of the next epoch.
15+
--
16+
-- TODO[sgillespie]: It would probably be better to return @Db.EpochParam@, but
17+
-- persistent seems to be having trouble with the data:
18+
--
19+
-- PersistMarshalError "Couldn't parse field `govActionLifetime` from table
20+
-- `epoch_param`. Failed to parse Haskell type `Word64`; expected integer from
21+
-- database, but received: PersistRational (0 % 1).
22+
queryVersionMajorFromEpoch ::
23+
MonadIO io =>
24+
Word64 ->
25+
ReaderT SqlBackend io (Maybe Word16)
26+
queryVersionMajorFromEpoch epochNo = do
27+
res <- selectOne $ do
28+
prop <- from $ table @Db.EpochParam
29+
where_ (prop ^. Db.EpochParamEpochNo ==. val epochNo)
30+
pure (prop ^. Db.EpochParamProtocolMajor)
31+
pure $ unValue <$> res
32+
33+
-- | Query protocol parameter proposals from @ParamProposal@ by epoch number.
34+
queryParamProposalFromEpoch ::
35+
MonadIO io =>
36+
Word64 ->
37+
ReaderT SqlBackend io (Maybe Db.ParamProposal)
38+
queryParamProposalFromEpoch epochNo = do
39+
res <- selectOne $ do
40+
prop <- from $ table @Db.ParamProposal
41+
where_ $ prop ^. Db.ParamProposalEpochNo ==. val (Just epochNo)
42+
pure prop
43+
pure $ entityVal <$> res

cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Conway.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ unitTests iom knownMigrations =
202202
"Hard Fork"
203203
[ test "fork from Babbage to Conway fixed epoch" Other.forkFixedEpoch
204204
, test "fork from Babbage to Conway and rollback" Other.rollbackFork
205+
, test "fork with protocol change proposal" Other.forkParam
205206
]
206207
]
207208
where

cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Conway/Other.hs

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{-# LANGUAGE DataKinds #-}
2+
{-# LANGUAGE ExplicitNamespaces #-}
3+
{-# LANGUAGE FlexibleContexts #-}
24
{-# LANGUAGE NumericUnderscores #-}
5+
{-# LANGUAGE OverloadedStrings #-}
6+
{-# LANGUAGE ScopedTypeVariables #-}
37

48
module Test.Cardano.Db.Mock.Unit.Conway.Other (
59
-- * Different configs
@@ -16,22 +20,25 @@ module Test.Cardano.Db.Mock.Unit.Conway.Other (
1620
-- * Hard fork
1721
forkFixedEpoch,
1822
rollbackFork,
23+
forkParam,
1924
) where
2025

26+
import qualified Cardano.Db as Db
2127
import Cardano.DbSync.Era.Shelley.Generic.Util (unKeyHashRaw)
22-
import Cardano.Ledger.BaseTypes (EpochNo ())
28+
import Cardano.Ledger.BaseTypes (EpochNo (..))
2329
import Cardano.Ledger.Conway.TxCert (ConwayTxCert (..))
2430
import Cardano.Ledger.Core (PoolCert (..))
2531
import Cardano.Ledger.Credential (StakeCredential ())
2632
import Cardano.Ledger.Crypto (StandardCrypto ())
2733
import Cardano.Ledger.Keys (KeyHash (), KeyRole (..))
2834
import Cardano.Mock.ChainSync.Server (IOManager (), addBlock, rollback)
29-
import Cardano.Mock.Forging.Interpreter (forgeNext)
35+
import Cardano.Mock.Forging.Interpreter (forgeNext, getCurrentEpoch)
3036
import qualified Cardano.Mock.Forging.Tx.Babbage as Babbage
3137
import qualified Cardano.Mock.Forging.Tx.Conway as Conway
3238
import Cardano.Mock.Forging.Tx.Generic (resolvePool)
3339
import Cardano.Mock.Forging.Types
34-
import Cardano.Prelude
40+
import Cardano.Mock.Query (queryParamProposalFromEpoch, queryVersionMajorFromEpoch)
41+
import Cardano.Prelude hiding (from)
3542
import Cardano.SMASH.Server.PoolDataLayer (PoolDataLayer (..), dbToServantPoolId)
3643
import Cardano.SMASH.Server.Types (DBFail (..))
3744
import Data.List (last)
@@ -436,3 +443,62 @@ rollbackFork =
436443
where
437444
configDir = "config-conway-hf-epoch1"
438445
testLabel = "conwayRollbackFork"
446+
447+
forkParam :: IOManager -> [(Text, Text)] -> Assertion
448+
forkParam =
449+
withFullConfig configDir testLabel $ \interpreter mockServer dbSync -> do
450+
startDBSync dbSync
451+
452+
-- Protocol params aren't added to the DB until the following epoch
453+
epoch0 <- Api.fillUntilNextEpoch interpreter mockServer
454+
-- Wait for it to sync
455+
assertBlockNoBackoff dbSync (length epoch0)
456+
-- Protocol major version should still match config
457+
assertEqBackoff
458+
dbSync
459+
(queryCurrentMajVer interpreter)
460+
(Just 7)
461+
[]
462+
"Unexpected protocol major version"
463+
464+
-- Propose a parameter update
465+
void $
466+
Api.withBabbageFindLeaderAndSubmitTx interpreter mockServer $
467+
const Babbage.mkParamUpdateTx
468+
-- Wait for it to sync
469+
assertBlockNoBackoff dbSync (1 + length epoch0)
470+
-- Query protocol param proposals
471+
assertEqBackoff
472+
dbSync
473+
(queryMajVerProposal interpreter)
474+
(Just 9)
475+
[]
476+
"Unexpected protocol major version proposal"
477+
478+
-- The fork will be applied on the first block of the next epoch
479+
epoch1 <- Api.fillUntilNextEpoch interpreter mockServer
480+
-- Wait for it to sync
481+
assertBlockNoBackoff dbSync $ 1 + length (epoch0 <> epoch1)
482+
-- Protocol major version should now be updated
483+
assertEqBackoff
484+
dbSync
485+
(queryCurrentMajVer interpreter)
486+
(Just 9)
487+
[]
488+
"Unexpected protocol major version"
489+
490+
-- Add a simple Conway tx
491+
void $
492+
Api.withConwayFindLeaderAndSubmitTx interpreter mockServer $
493+
Conway.mkPaymentTx (UTxOIndex 0) (UTxOIndex 1) 10_000 500
494+
-- Wait for it to sync
495+
assertBlockNoBackoff dbSync $ 2 + length (epoch0 <> epoch1)
496+
where
497+
testLabel = "conwayForkParam"
498+
configDir = babbageConfigDir
499+
queryCurrentMajVer interpreter = queryVersionMajorFromEpoch =<< getEpochNo interpreter
500+
queryMajVerProposal interpreter = do
501+
epochNo <- getEpochNo interpreter
502+
prop <- queryParamProposalFromEpoch epochNo
503+
pure (Db.paramProposalProtocolMajor =<< prop)
504+
getEpochNo = fmap unEpochNo . liftIO . getCurrentEpoch

cardano-chain-gen/test/testfiles/config-conway/genesis.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"maxLovelaceSupply": 60000000,
33
"securityParam": 10,
44
"slotsPerKESPeriod": 129600,
5-
"updateQuorum": 5,
5+
"updateQuorum": 2,
66
"activeSlotsCoeff": 0.2,
77
"protocolParams": {
88
"minUTxOValue": 0,
@@ -43,7 +43,16 @@
4343
},
4444
"networkId": "Testnet",
4545
"maxKESEvolutions": 60,
46-
"genDelegs": { },
46+
"genDelegs": {
47+
"30c3083efd794227fde2351a04500349d1b467556c30e35d6794a501": {
48+
"delegate": "3af50e522694318e8856d34021140817aa21d47ff62a4d0ddcba1924",
49+
"vrf": "2846ed605f6629976ec92e9e65140c1cb3a95c563c996592c926a2ae7e5a461f"
50+
},
51+
"471cc34983f6a2fd7b4018e3147532185d69a448d6570d46019e58e6": {
52+
"delegate": "1683652d05e83e25eb648a9543db33cf8ff1f7a2af9129d3a901dd4a",
53+
"vrf": "4df7c5a5b30469756bd09db60cbe9b0cf1b2447e0c41122d130768c179b7d166"
54+
}
55+
},
4756
"slotLength": 1,
4857
"systemStart": "2021-11-18T20:22:02Z",
4958
"epochLength": 500,

cardano-chain-gen/test/testfiles/config/genesis.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"maxLovelaceSupply": 60000000,
33
"securityParam": 10,
44
"slotsPerKESPeriod": 129600,
5-
"updateQuorum": 5,
5+
"updateQuorum": 2,
66
"activeSlotsCoeff": 0.2,
77
"protocolParams": {
88
"minUTxOValue": 0,
@@ -43,7 +43,16 @@
4343
},
4444
"networkId": "Testnet",
4545
"maxKESEvolutions": 60,
46-
"genDelegs": { },
46+
"genDelegs": {
47+
"30c3083efd794227fde2351a04500349d1b467556c30e35d6794a501": {
48+
"delegate": "3af50e522694318e8856d34021140817aa21d47ff62a4d0ddcba1924",
49+
"vrf": "2846ed605f6629976ec92e9e65140c1cb3a95c563c996592c926a2ae7e5a461f"
50+
},
51+
"471cc34983f6a2fd7b4018e3147532185d69a448d6570d46019e58e6": {
52+
"delegate": "1683652d05e83e25eb648a9543db33cf8ff1f7a2af9129d3a901dd4a",
53+
"vrf": "4df7c5a5b30469756bd09db60cbe9b0cf1b2447e0c41122d130768c179b7d166"
54+
}
55+
},
4756
"slotLength": 1,
4857
"systemStart": "2021-11-18T20:22:02Z",
4958
"epochLength": 500,

cardano-chain-gen/test/testfiles/fingerprint/CLAMigrateAndPruneRestart

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)