Skip to content

Commit e6a9c24

Browse files
authored
Merge pull request #5976 from IntersectMBO/smelc/separate-cardano-testnet-options-stages
cardano-testnet: separate in types the options encoded in genesis files, from other options
2 parents 82dfb84 + a25c6c1 commit e6a9c24

Some content is hidden

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

42 files changed

+379
-323
lines changed

cardano-node-chairman/cardano-node-chairman.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ test-suite chairman-tests
7070

7171
build-depends: cardano-testnet
7272
, cardano-crypto-class ^>= 2.1.2
73+
, data-default-class
7374
, filepath
7475
, hedgehog
7576
, hedgehog-extras ^>= 0.6.4

cardano-node-chairman/test/Spec/Chairman/Cardano.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
module Spec.Chairman.Cardano where
66

7-
import Cardano.Testnet (NodeRuntime (nodeName), allNodes, cardanoDefaultTestnetOptions,
7+
import Cardano.Testnet (NodeRuntime (nodeName), allNodes,
88
cardanoTestnetDefault, mkConf)
99

10+
import Data.Default.Class
1011
import Testnet.Property.Util (integrationRetryWorkspace)
1112

1213
import qualified Hedgehog as H
@@ -18,6 +19,6 @@ hprop_chairman :: H.Property
1819
hprop_chairman = integrationRetryWorkspace 2 "cardano-chairman" $ \tempAbsPath' -> do
1920
conf <- mkConf tempAbsPath'
2021

21-
allNodes' <- fmap nodeName . allNodes <$> cardanoTestnetDefault cardanoDefaultTestnetOptions conf
22+
allNodes' <- fmap nodeName . allNodes <$> cardanoTestnetDefault def def conf
2223

2324
chairmanOver 120 50 conf allNodes'

cardano-testnet/cardano-testnet.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ test-suite cardano-testnet-test
228228
, cardano-strict-containers ^>= 0.1
229229
, cardano-testnet
230230
, containers
231+
, data-default-class
231232
, directory
232233
, exceptions
233234
, filepath

cardano-testnet/src/Cardano/Testnet.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ module Cardano.Testnet (
1111
-- ** Testnet options
1212
CardanoTestnetOptions(..),
1313
TestnetNodeOptions(..),
14-
cardanoDefaultTestnetOptions,
1514
cardanoDefaultTestnetNodeOptions,
1615
getDefaultAlonzoGenesis,
1716
getDefaultShelleyGenesis,

cardano-testnet/src/Parsers/Cardano.hs

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Cardano.CLI.EraBased.Options.Common hiding (pNetworkId)
99

1010
import Prelude
1111

12+
import Data.Default.Class
1213
import Data.Functor
1314
import qualified Data.List as L
1415
import Data.Word (Word64)
@@ -20,46 +21,29 @@ import Testnet.Start.Types
2021
import Testnet.Types (readNodeLoggingFormat)
2122

2223

23-
optsTestnet :: EnvCli -> Parser CardanoTestnetOptions
24-
optsTestnet envCli = CardanoTestnetOptions
24+
optsTestnet :: EnvCli -> Parser CardanoTestnetCliOptions
25+
optsTestnet envCli = CardanoTestnetCliOptions
26+
<$> pCardanoTestnetCliOptions envCli
27+
<*> pShelleyTestnetOptions
28+
29+
pCardanoTestnetCliOptions :: EnvCli -> Parser CardanoTestnetOptions
30+
pCardanoTestnetCliOptions envCli = CardanoTestnetOptions
2531
<$> pNumSpoNodes
2632
<*> pAnyShelleyBasedEra'
27-
<*> OA.option auto
28-
( OA.long "epoch-length"
29-
<> OA.help "Epoch length, in number of slots"
30-
<> OA.metavar "SLOTS"
31-
<> OA.showDefault
32-
<> OA.value (cardanoEpochLength cardanoDefaultTestnetOptions)
33-
)
34-
<*> OA.option auto
35-
( OA.long "slot-length"
36-
<> OA.help "Slot length"
37-
<> OA.metavar "SECONDS"
38-
<> OA.showDefault
39-
<> OA.value (cardanoSlotLength cardanoDefaultTestnetOptions)
40-
)
41-
<*> pNetworkId
42-
<*> OA.option auto
43-
( OA.long "active-slots-coeff"
44-
<> OA.help "Active slots co-efficient"
45-
<> OA.metavar "DOUBLE"
46-
<> OA.showDefault
47-
<> OA.value (cardanoActiveSlotsCoeff cardanoDefaultTestnetOptions)
48-
)
4933
<*> pMaxLovelaceSupply
5034
<*> OA.option auto
5135
( OA.long "enable-p2p"
5236
<> OA.help "Enable P2P"
5337
<> OA.metavar "BOOL"
5438
<> OA.showDefault
55-
<> OA.value (cardanoEnableP2P cardanoDefaultTestnetOptions)
39+
<> OA.value (cardanoEnableP2P def)
5640
)
5741
<*> OA.option (OA.eitherReader readNodeLoggingFormat)
5842
( OA.long "nodeLoggingFormat"
5943
<> OA.help "Node logging format (json|text)"
6044
<> OA.metavar "LOGGING_FORMAT"
6145
<> OA.showDefault
62-
<> OA.value (cardanoNodeLoggingFormat cardanoDefaultTestnetOptions)
46+
<> OA.value (cardanoNodeLoggingFormat def)
6347
)
6448
<*> OA.option auto
6549
( OA.long "num-dreps"
@@ -86,10 +70,9 @@ pNumSpoNodes =
8670
<> OA.help "Number of pool nodes. Note this uses a default node configuration for all nodes."
8771
<> OA.metavar "COUNT"
8872
<> OA.showDefault
89-
<> OA.value (cardanoNodes cardanoDefaultTestnetOptions)
73+
<> OA.value (cardanoNodes def)
9074
)
9175

92-
9376
_pSpo :: Parser TestnetNodeOptions
9477
_pSpo =
9578
SpoTestnetNodeOptions . Just
@@ -113,8 +96,40 @@ parseNodeConfigFile = NodeConfigurationYaml <$>
11396
, "Or use num-pool-nodes to use cardano-testnet's default configuration."
11497
]
11598

116-
117-
cmdCardano :: EnvCli -> Mod CommandFields CardanoTestnetOptions
99+
pShelleyTestnetOptions :: Parser ShelleyTestnetOptions
100+
pShelleyTestnetOptions =
101+
ShelleyTestnetOptions
102+
<$> pNetworkId
103+
<*> pEpochLength
104+
<*> pSlotLength
105+
<*> pActiveSlotCoeffs
106+
where
107+
pEpochLength =
108+
OA.option auto
109+
( OA.long "epoch-length"
110+
<> OA.help "Epoch length, in number of slots"
111+
<> OA.metavar "SLOTS"
112+
<> OA.showDefault
113+
<> OA.value (shelleyEpochLength def)
114+
)
115+
pSlotLength =
116+
OA.option auto
117+
( OA.long "slot-length"
118+
<> OA.help "Slot length"
119+
<> OA.metavar "SECONDS"
120+
<> OA.showDefault
121+
<> OA.value (shelleySlotLength def)
122+
)
123+
pActiveSlotCoeffs =
124+
OA.option auto
125+
( OA.long "active-slots-coeff"
126+
<> OA.help "Active slots co-efficient"
127+
<> OA.metavar "DOUBLE"
128+
<> OA.showDefault
129+
<> OA.value (shelleyActiveSlotsCoeff def)
130+
)
131+
132+
cmdCardano :: EnvCli -> Mod CommandFields CardanoTestnetCliOptions
118133
cmdCardano envCli = command' "cardano" "Start a testnet in any era" (optsTestnet envCli)
119134

120135
pNetworkId :: Parser Int
@@ -132,6 +147,6 @@ pMaxLovelaceSupply =
132147
<> help "Max lovelace supply that your testnet starts with."
133148
<> metavar "WORD64"
134149
<> showDefault
135-
<> value (cardanoMaxSupply cardanoDefaultTestnetOptions)
150+
<> value (cardanoMaxSupply def)
136151
)
137152

cardano-testnet/src/Parsers/Run.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ opts envCli = Opt.info (commands envCli <**> helper) idm
3131
-- by allowing the user to start testnets in any era (excluding Byron)
3232
-- via StartCardanoTestnet
3333
data CardanoTestnetCommands
34-
= StartCardanoTestnet CardanoTestnetOptions
34+
= StartCardanoTestnet CardanoTestnetCliOptions
3535
| GetVersion VersionOptions
3636
| Help ParserPrefs (ParserInfo CardanoTestnetCommands) HelpOptions
3737

@@ -51,6 +51,6 @@ runTestnetCmd = \case
5151
Help pPrefs pInfo cmdOpts -> runHelpOptions pPrefs pInfo cmdOpts
5252

5353

54-
runCardanoOptions :: CardanoTestnetOptions -> IO ()
55-
runCardanoOptions options =
56-
runTestnet $ cardanoTestnetDefault options
54+
runCardanoOptions :: CardanoTestnetCliOptions -> IO ()
55+
runCardanoOptions (CardanoTestnetCliOptions testnetOptions shelleyOptions) =
56+
runTestnet $ cardanoTestnetDefault testnetOptions shelleyOptions

cardano-testnet/src/Testnet/Defaults.hs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import Data.Text (Text)
6868
import qualified Data.Text as Text
6969
import Data.Time (UTCTime)
7070
import qualified Data.Vector as Vector
71+
import Data.Word (Word64)
7172
import Lens.Micro
7273
import Numeric.Natural
7374
import System.FilePath ((</>))
@@ -416,31 +417,31 @@ defaultByronProtocolParamsJsonValue =
416417
]
417418

418419
defaultShelleyGenesis
419-
:: UTCTime
420-
-> CardanoTestnetOptions
420+
:: AnyShelleyBasedEra
421+
-> UTCTime
422+
-> Word64
423+
-> ShelleyTestnetOptions
421424
-> Api.ShelleyGenesis StandardCrypto
422-
defaultShelleyGenesis startTime testnetOptions = do
423-
let CardanoTestnetOptions
424-
{ cardanoTestnetMagic = testnetMagic
425-
, cardanoSlotLength = slotLength
426-
, cardanoEpochLength = epochLength
427-
, cardanoMaxSupply = sgMaxLovelaceSupply
428-
, cardanoActiveSlotsCoeff
429-
, cardanoNodeEra
430-
} = testnetOptions
425+
defaultShelleyGenesis asbe startTime maxSupply options = do
426+
let ShelleyTestnetOptions
427+
{ shelleyTestnetMagic = magic
428+
, shelleySlotLength = slotLength
429+
, shelleyEpochLength = epochLength
430+
, shelleyActiveSlotsCoeff
431+
} = options
431432
-- f
432-
activeSlotsCoeff = round (cardanoActiveSlotsCoeff * 100) % 100
433+
activeSlotsCoeff = round (shelleyActiveSlotsCoeff * 100) % 100
433434
-- make security param k satisfy: epochLength = 10 * k / f
434435
-- TODO: find out why this actually degrates network stability - turned off for now
435436
-- securityParam = ceiling $ fromIntegral epochLength * cardanoActiveSlotsCoeff / 10
436-
pVer = eraToProtocolVersion cardanoNodeEra
437+
pVer = eraToProtocolVersion asbe
437438
protocolParams = Api.sgProtocolParams Api.shelleyGenesisDefaults
438439
protocolParamsWithPVer = protocolParams & ppProtocolVersionL' .~ pVer
439440
Api.shelleyGenesisDefaults
440441
{ Api.sgActiveSlotsCoeff = unsafeBoundedRational activeSlotsCoeff
441442
, Api.sgEpochLength = EpochSize $ fromIntegral epochLength
442-
, Api.sgMaxLovelaceSupply
443-
, Api.sgNetworkMagic = fromIntegral testnetMagic
443+
, Api.sgMaxLovelaceSupply = maxSupply
444+
, Api.sgNetworkMagic = fromIntegral magic
444445
, Api.sgProtocolParams = protocolParamsWithPVer
445446
-- using default from shelley genesis k = 2160
446447
-- , Api.sgSecurityParam = securityParam

cardano-testnet/src/Testnet/Process/Cli/SPO.hs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,13 @@ createStakeKeyDeregistrationCertificate tempAbsP sbe stakeVerKey deposit outputF
241241
-- | Related documentation: https://github.com/input-output-hk/cardano-node-wiki/blob/main/docs/stake-pool-operations/8_register_stakepool.md
242242
registerSingleSpo
243243
:: (MonadTest m, MonadCatch m, MonadIO m, HasCallStack)
244-
=> Int -- ^ Identifier for stake pool
244+
=> AnyShelleyBasedEra
245+
-> Int -- ^ Identifier for stake pool
245246
-> TmpAbsolutePath
246247
-> NodeConfigFile 'In
247248
-> SocketPath
248249
-> EpochNo -- ^ Termination epoch
249-
-> CardanoTestnetOptions
250+
-> Int -- ^ Testnet magic
250251
-> ExecConfig
251252
-> (TxIn, FilePath, String)
252253
-> m ( String
@@ -260,10 +261,8 @@ registerSingleSpo
260261
-- 3. FilePath: Stake pool cold verification key
261262
-- 4. FilePath: Stake pool VRF signing key
262263
-- 5. FilePath: Stake pool VRF verification key
263-
registerSingleSpo identifier tap@(TmpAbsolutePath tempAbsPath') nodeConfigFile socketPath termEpoch cTestnetOptions execConfig
264+
registerSingleSpo asbe identifier tap@(TmpAbsolutePath tempAbsPath') nodeConfigFile socketPath termEpoch testnetMag execConfig
264265
(fundingInput, fundingSigninKey, changeAddr) = GHC.withFrozenCallStack $ do
265-
let testnetMag = cardanoTestnetMagic cTestnetOptions
266-
267266
workDir <- H.note tempAbsPath'
268267

269268
-- In order to register a stake pool we need two certificates:
@@ -322,7 +321,6 @@ registerSingleSpo identifier tap@(TmpAbsolutePath tempAbsPath') nodeConfigFile s
322321

323322
-- 5. Create registration certificate
324323
let poolRegCertFp = spoReqDir </> "registration.cert"
325-
let asbe = cardanoNodeEra cTestnetOptions
326324

327325
-- The pledge, pool cost and pool margin can all be 0
328326
execCli_

cardano-testnet/src/Testnet/Property/Assert.hs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import Data.Type.Equality
4040
import Data.Word (Word8)
4141
import GHC.Stack as GHC
4242

43-
import Testnet.Components.Configuration (NumPools(..), numPools)
43+
import Testnet.Components.Configuration (NumPools(..))
4444
import Testnet.Process.Run
4545
import Testnet.Start.Types
4646

@@ -84,12 +84,10 @@ assertByDeadlineIOCustom str deadline f = withFrozenCallStack $ do
8484
assertExpectedSposInLedgerState
8585
:: (MonadTest m, MonadCatch m, MonadIO m, HasCallStack)
8686
=> FilePath -- ^ Stake pools query output filepath
87-
-> CardanoTestnetOptions
87+
-> NumPools
8888
-> ExecConfig
8989
-> m ()
90-
assertExpectedSposInLedgerState output tNetOptions execConfig = withFrozenCallStack $ do
91-
let NumPools numExpectedPools = numPools tNetOptions
92-
90+
assertExpectedSposInLedgerState output (NumPools numExpectedPools) execConfig = withFrozenCallStack $ do
9391
void $ execCli' execConfig
9492
[ "query", "stake-pools"
9593
, "--out-file", output

0 commit comments

Comments
 (0)