Skip to content

Commit 2a43449

Browse files
authored
Merge pull request #6289 from IntersectMBO/nb/custom_onchain_params
Create sandbox for `cardano-testnet` with custom on-chain parameters
2 parents 57e228c + 1d2b636 commit 2a43449

File tree

19 files changed

+1928
-205
lines changed

19 files changed

+1928
-205
lines changed

cardano-testnet/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* [Add an option to dump/load configuration sandbox](https://github.com/IntersectMBO/cardano-node/pull/6239)
77
* [Add flag to support P2P topology](https://github.com/IntersectMBO/cardano-node/pull/6263)
88
* [Add flag to update time stamps in custom environment](https://github.com/IntersectMBO/cardano-node/pull/6275)
9+
* [Add option to create configuration sandbox with parameters from mainnet](https://github.com/IntersectMBO/cardano-node/pull/6289)
910

1011
## 10.0.0
1112

cardano-testnet/cardano-testnet.cabal

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ library
4949
, cardano-ledger-binary
5050
, cardano-ledger-byron
5151
, cardano-ledger-conway
52+
, cardano-ledger-core
5253
, cardano-ledger-api
5354
, cardano-ledger-conway
5455
, cardano-ledger-core:{cardano-ledger-core, testlib}
@@ -70,6 +71,7 @@ library
7071
, filepath
7172
, hedgehog
7273
, hedgehog-extras ^>= 0.8
74+
, http-conduit
7375
, lens-aeson
7476
, microlens
7577
, monad-control
@@ -102,6 +104,7 @@ library
102104
hs-source-dirs: src
103105
exposed-modules: Cardano.Testnet
104106
Parsers.Run
107+
Testnet.Blockfrost
105108
Testnet.Components.Configuration
106109
Testnet.Components.Query
107110
Testnet.Defaults
@@ -222,6 +225,7 @@ test-suite cardano-testnet-test
222225
Cardano.Testnet.Test.Gov.TreasuryWithdrawal
223226
Cardano.Testnet.Test.Misc
224227
Cardano.Testnet.Test.Node.Shutdown
228+
Cardano.Testnet.Test.MainnetParams
225229
Cardano.Testnet.Test.P2PTopology
226230
Cardano.Testnet.Test.SanityCheck
227231
Cardano.Testnet.Test.RunTestnet

cardano-testnet/src/Parsers/Cardano.hs

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import Control.Applicative
1616
import Data.Default.Class
1717
import Data.Functor
1818
import qualified Data.List as L
19+
import Data.Maybe (fromMaybe)
1920
import Data.Word (Word64)
2021
import Options.Applicative (CommandFields, Mod, Parser)
2122
import qualified Options.Applicative as OA
@@ -29,16 +30,21 @@ optsTestnet envCli = CardanoTestnetCliOptions
2930
<$> pCardanoTestnetCliOptions envCli
3031
<*> pGenesisOptions
3132
<*> pNodeEnvironment
33+
<*> pUpdateTimestamps
3234

3335
optsCreateTestnet :: EnvCli -> Parser CardanoTestnetCreateEnvOptions
3436
optsCreateTestnet envCli = CardanoTestnetCreateEnvOptions
3537
<$> pCardanoTestnetCliOptions envCli
3638
<*> pGenesisOptions
3739
<*> pEnvOutputDir
38-
<*> ( CreateEnvOptions
39-
<$> pTopologyType
40-
<*> pCreateEnvUpdateTime
41-
)
40+
<*> pCreateEnvOptions
41+
42+
-- We can't fill in the optional Genesis files at parse time, because we want to be in a monad
43+
-- to properly parse JSON. We delegate this task to the caller.
44+
pCreateEnvOptions :: Parser CreateEnvOptions
45+
pCreateEnvOptions = CreateEnvOptions
46+
<$> pOnChainParams
47+
<*> pTopologyType
4248

4349
pCardanoTestnetCliOptions :: EnvCli -> Parser CardanoTestnetOptions
4450
pCardanoTestnetCliOptions envCli = CardanoTestnetOptions
@@ -95,17 +101,34 @@ pNodeEnvironment = fmap (maybe NoUserProvidedEnv UserProvidedEnv) <$>
95101
<> OA.help "Path to the node's environment (which is generated otherwise). You can generate a default environment with the 'create-env' command, then modify it and pass it with this argument."
96102
)
97103

104+
pOnChainParams :: Parser TestnetOnChainParams
105+
pOnChainParams = fmap (fromMaybe DefaultParams) <$> optional $
106+
pCustomParamsFile <|> pMainnetParams
107+
108+
pCustomParamsFile :: Parser TestnetOnChainParams
109+
pCustomParamsFile = OnChainParamsFile <$> OA.strOption
110+
( OA.long "params-file"
111+
<> OA.help "File containing custom on-chain parameters in Blockfrost format:\nhttps://docs.blockfrost.io/#tag/cardano--epochs/GET/epochs/latest/parameters"
112+
<> OA.metavar "FILEPATH"
113+
)
114+
115+
pMainnetParams :: Parser TestnetOnChainParams
116+
pMainnetParams = OA.flag' OnChainParamsMainnet
117+
( OA.long "mainnet"
118+
<> OA.help "Use mainnet on-chain parameters"
119+
)
120+
98121
pTopologyType :: Parser TopologyType
99122
pTopologyType = OA.flag DirectTopology P2PTopology
100123
( OA.long "p2p-topology"
101124
<> OA.help "Use P2P topology files instead of \"direct\" topology files"
102125
<> OA.showDefault
103126
)
104127

105-
pCreateEnvUpdateTime :: Parser CreateEnvUpdateTime
106-
pCreateEnvUpdateTime = OA.flag CreateEnv UpdateTimeAndExit
128+
pUpdateTimestamps :: Parser UpdateTimestamps
129+
pUpdateTimestamps = OA.flag DontUpdateTimestamps UpdateTimestamps
107130
( OA.long "update-time"
108-
<> OA.help "Don't create anything, just update the time stamps in existing files"
131+
<> OA.help "Update the time stamps in genesis files to current date"
109132
<> OA.showDefault
110133
)
111134

cardano-testnet/src/Parsers/Run.hs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,9 @@ createEnvOptions CardanoTestnetCreateEnvOptions
6464
, createEnvOutputDir=outputDir
6565
, createEnvCreateEnvOptions=ceOptions
6666
} =
67-
testnetRoutine (UserProvidedEnv outputDir) $ \conf ->
67+
testnetRoutine (UserProvidedEnv outputDir) $ \conf -> do
6868
createTestnetEnv
6969
testnetOptions genesisOptions ceOptions
70-
-- The CLI does not provide a way to provide custom genesis data by design:
71-
-- If the user wants to have custom genesis data, they should manually
72-
-- modify the files created by this command before running the testnet.
73-
NoUserProvidedData NoUserProvidedData NoUserProvidedData
7470
-- Do not add hashes to the main config file, so that genesis files
7571
-- can be modified without having to recompute hashes every time.
7672
conf{genesisHashesPolicy = WithoutHashes}
@@ -80,17 +76,23 @@ runCardanoOptions CardanoTestnetCliOptions
8076
{ cliTestnetOptions=testnetOptions@CardanoTestnetOptions{cardanoOutputDir}
8177
, cliGenesisOptions=genesisOptions
8278
, cliNodeEnvironment=env
79+
, cliUpdateTimestamps=updateTimestamps
8380
} =
8481
case env of
8582
NoUserProvidedEnv ->
86-
-- Create the sandbox, then run cardano-testnet
83+
-- Create the sandbox, then run cardano-testnet.
84+
-- It is not necessary to honor `cliUpdateTimestamps` here, because
85+
-- the genesis files will be created with up-to-date stamps already.
8786
runTestnet cardanoOutputDir $ \conf -> do
8887
createTestnetEnv
8988
testnetOptions genesisOptions def
90-
NoUserProvidedData NoUserProvidedData NoUserProvidedData
9189
conf
9290
cardanoTestnet testnetOptions genesisOptions conf
9391
UserProvidedEnv nodeEnvPath ->
9492
-- Run cardano-testnet in the sandbox provided by the user
9593
-- In that case, 'cardanoOutputDir' is not used
96-
runTestnet (UserProvidedEnv nodeEnvPath) $ cardanoTestnet testnetOptions genesisOptions
94+
runTestnet (UserProvidedEnv nodeEnvPath) $ \conf ->
95+
cardanoTestnet
96+
testnetOptions
97+
genesisOptions
98+
conf{updateTimestamps=updateTimestamps}

0 commit comments

Comments
 (0)