Skip to content

Commit

Permalink
cardano-testnet: use create-testnet-data's byron genesis generation
Browse files Browse the repository at this point in the history
  • Loading branch information
smelc committed Nov 20, 2024
1 parent 6fac0b4 commit 1421b17
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 30 deletions.
7 changes: 1 addition & 6 deletions cardano-testnet/src/Testnet/Components/Configuration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ createConfigJson :: ()
-> ShelleyBasedEra era -- ^ The era used for generating the hard fork configuration toggle
-> m LBS.ByteString
createConfigJson (TmpAbsolutePath tempAbsPath) sbe = GHC.withFrozenCallStack $ do
byronGenesisHash <- getByronGenesisHash $ tempAbsPath </> "byron/genesis.json"
byronGenesisHash <- getByronGenesisHash $ tempAbsPath </> "byron-genesis.json"
shelleyGenesisHash <- getHash ShelleyEra "ShelleyGenesisHash"
alonzoGenesisHash <- getHash AlonzoEra "AlonzoGenesisHash"
conwayGenesisHash <- getHash ConwayEra "ConwayGenesisHash"
Expand Down Expand Up @@ -179,14 +179,9 @@ createSPOGenesisAndFiles nPoolNodes nDelReps maxSupply sbe shelleyGenesis
-- Remove the input files. We don't need them anymore, since create-testnet-data wrote new versions.
forM_ [inputGenesisShelleyFp, inputGenesisAlonzoFp, inputGenesisConwayFp] (liftIO . System.removeFile)

-- Move all genesis related files
genesisByronDir <- H.createDirectoryIfMissing $ tempAbsPath </> "byron"

files <- H.listDirectory tempAbsPath
forM_ files H.note

H.renameFile (tempAbsPath </> "byron-gen-command" </> "genesis.json") (genesisByronDir </> "genesis.json")

return genesisShelleyDir
where
genesisInputFilepath e = "genesis-input." <> anyEraToString (AnyCardanoEra e) <> ".json"
Expand Down
2 changes: 1 addition & 1 deletion cardano-testnet/src/Testnet/Defaults.hs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ defaultYamlConfig =
, ("EnableLogging", Aeson.Bool True)

-- Genesis filepaths
, ("ByronGenesisFile", "byron/genesis.json")
, ("ByronGenesisFile", genesisPath ByronEra)
, ("ShelleyGenesisFile", genesisPath ShelleyEra)
, ("AlonzoGenesisFile", genesisPath AlonzoEra)
, ("ConwayGenesisFile", genesisPath ConwayEra)
Expand Down
24 changes: 3 additions & 21 deletions cardano-testnet/src/Testnet/Start/Cardano.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,13 @@ import qualified GHC.Stack as GHC
import qualified System.Directory as IO
import System.FilePath ((</>))
import qualified System.Info as OS
import Text.Printf (printf)

import Testnet.Components.Configuration
import qualified Testnet.Defaults as Defaults
import Testnet.Filepath
import Testnet.Process.Run (execCli', execCli_, mkExecConfig)
import Testnet.Property.Assert (assertChainExtended, assertExpectedSposInLedgerState)
import Testnet.Runtime as TR
import qualified Testnet.Start.Byron as Byron
import Testnet.Start.Types
import Testnet.Types as TR hiding (shelleyGenesis)

Expand Down Expand Up @@ -215,7 +213,7 @@ cardanoTestnet
, cardanoNumDReps=nDReps
, cardanoNodes
} = testnetOptions
startTime = sgSystemStart shelleyGenesis
_startTime = sgSystemStart shelleyGenesis
testnetMagic = fromIntegral $ sgNetworkMagic shelleyGenesis
nPools = cardanoNumPools testnetOptions
AnyShelleyBasedEra sbe <- pure asbe
Expand All @@ -231,16 +229,6 @@ cardanoTestnet
-- See all of the ad hoc file creation/renaming/dir creation etc below.
H.failMessage GHC.callStack "Specifying node configuration files per node not supported yet."

H.lbsWriteFile (tmpAbsPath </> "byron.genesis.spec.json")
. encode $ Defaults.defaultByronProtocolParamsJsonValue

Byron.createByronGenesis
testnetMagic
startTime
Byron.byronDefaultGenesisOptions
(tmpAbsPath </> "byron.genesis.spec.json")
(tmpAbsPath </> "byron-gen-command")

-- Write specification files. Those are the same as the genesis files
-- used for launching the nodes, but omitting the content regarding stake, utxos, etc.
-- They are used by benchmarking: as templates to CLI commands,
Expand Down Expand Up @@ -296,16 +284,10 @@ cardanoTestnet
let portNumbers = snd <$> portNumbersWithNodeOptions

-- Byron related
forM_ (zip [1..] portNumbersWithNodeOptions) $ \(i, (nodeOptions, portNumber)) -> do
let iStr = printf "%03d" (i - 1)
nodeDataDir = tmpAbsPath </> Defaults.defaultNodeDataDir i
nodePoolKeysDir = tmpAbsPath </> Defaults.defaultSpoKeysDir i
forM_ (zip [1..] portNumbersWithNodeOptions) $ \(i, (_nodeOptions, portNumber)) -> do
let nodeDataDir = tmpAbsPath </> Defaults.defaultNodeDataDir i
H.evalIO $ IO.createDirectoryIfMissing True nodeDataDir
H.writeFile (nodeDataDir </> "port") (show portNumber)
when (isSpoNodeOptions nodeOptions) $ do
H.renameFile (tmpAbsPath </> "byron-gen-command" </> "delegate-keys." <> iStr <> ".key") (nodePoolKeysDir </> "byron-delegate.key")
H.renameFile (tmpAbsPath </> "byron-gen-command" </> "delegation-cert." <> iStr <> ".json") (nodePoolKeysDir </> "byron-delegation.cert")


-- Make Non P2P topology files
forM_ (zip [1..] portNumbers) $ \(i, myPortNumber) -> do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,15 @@ hprop_shutdown = integrationRetryWorkspace 2 "shutdown" $ \tempAbsBasePath' -> H
H.lbsWriteFile (tempAbsPath' </> "byron.genesis.spec.json")
. encode $ defaultByronProtocolParamsJsonValue

let byronGenesisOutputDir = tempAbsPath' </> "byron"

startTime <- H.noteShowIO DTC.getCurrentTime
createByronGenesis
testnetMagic'
startTime
byronDefaultGenesisOptions
(tempAbsPath' </> "byron.genesis.spec.json")
(tempAbsPath' </> "byron")
byronGenesisOutputDir

shelleyDir <- H.createDirectoryIfMissing $ tempAbsPath' </> "shelley"

Expand All @@ -118,8 +120,9 @@ hprop_shutdown = integrationRetryWorkspace 2 "shutdown" $ \tempAbsBasePath' -> H
, "--start-time", formatIso8601 startTime
]

byronGenesisHash <- getByronGenesisHash $ tempAbsPath' </> "byron/genesis.json"
byronGenesisHash <- getByronGenesisHash $ byronGenesisOutputDir </> "genesis.json"
-- Move the files to the paths expected by 'defaultYamlHardforkViaConfig' below
H.renameFile (byronGenesisOutputDir </> "genesis.json") (tempAbsPath' </> defaultGenesisFilepath ByronEra)
H.renameFile (tempAbsPath' </> "shelley/genesis.json") (tempAbsPath' </> defaultGenesisFilepath ShelleyEra)
H.renameFile (tempAbsPath' </> "shelley/genesis.alonzo.json") (tempAbsPath' </> defaultGenesisFilepath AlonzoEra)
H.renameFile (tempAbsPath' </> "shelley/genesis.conway.json") (tempAbsPath' </> defaultGenesisFilepath ConwayEra)
Expand Down

0 comments on commit 1421b17

Please sign in to comment.