-
Notifications
You must be signed in to change notification settings - Fork 720
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cardano-testnet: allow to pass genesis files #5645
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,13 +16,11 @@ module Testnet.Start.Cardano | |
, PaymentKeyPair(..) | ||
|
||
, cardanoTestnet | ||
|
||
, cardanoTestnetDefault | ||
) where | ||
|
||
|
||
import Control.Monad | ||
import qualified Control.Monad.Class.MonadTimer.SI as MT | ||
import Control.Monad.IO.Class | ||
import Control.Monad.Trans.Class (lift) | ||
import Control.Monad.Trans.Except (runExceptT) | ||
import Data.Aeson | ||
|
@@ -43,14 +41,25 @@ import qualified Hedgehog.Extras.Stock.OS as OS | |
import qualified Hedgehog.Extras.Test.Base as H | ||
import qualified Hedgehog.Extras.Test.File as H | ||
|
||
import qualified Testnet.Defaults as Defaults | ||
|
||
import Cardano.Api | ||
import Cardano.Api.Ledger (StandardCrypto) | ||
import Cardano.Ledger.Alonzo.Genesis (AlonzoGenesis) | ||
import Cardano.Ledger.Conway.Genesis (ConwayGenesis) | ||
import qualified Control.Monad.Class.MonadTimer.SI as MT | ||
import Control.Monad.IO.Class | ||
import qualified Data.Aeson as Aeson | ||
import Data.Bifunctor (first) | ||
import Data.Time (UTCTime) | ||
import Data.Word (Word32) | ||
import Testnet.Components.Configuration | ||
import Testnet.Defaults | ||
import Testnet.Filepath | ||
import qualified Testnet.Process.Run as H | ||
import Testnet.Process.Run | ||
import qualified Testnet.Property.Assert as H | ||
import Testnet.Property.Checks | ||
import Testnet.Runtime | ||
import Testnet.Runtime as TR hiding (shelleyGenesis) | ||
import qualified Testnet.Start.Byron as Byron | ||
import Testnet.Start.Types | ||
|
||
|
@@ -63,10 +72,11 @@ import Testnet.Start.Types | |
-- a valid node cluster. | ||
testnetMinimumConfigurationRequirements :: CardanoTestnetOptions -> H.Integration () | ||
testnetMinimumConfigurationRequirements cTestnetOpts = do | ||
when (length (cardanoNodes cTestnetOpts) < 2) $ do | ||
H.noteShow_ ("Need at least two nodes to run a cluster" :: String) | ||
let actualLength = length (cardanoNodes cTestnetOpts) | ||
when (actualLength < 2) $ do | ||
H.noteShow_ ("Need at least two nodes to run a cluster, but got: " <> show actualLength) | ||
H.noteShow_ cTestnetOpts | ||
H.assert False | ||
H.failure | ||
|
||
data ForkPoint | ||
= AtVersion Int | ||
|
@@ -79,6 +89,19 @@ data ForkPoint | |
startTimeOffsetSeconds :: DTC.NominalDiffTime | ||
startTimeOffsetSeconds = if OS.isWin32 then 90 else 15 | ||
|
||
-- | Like 'cardanoTestnet', but using defaults for all configuration files. | ||
-- See 'cardanoTestnet' for additional documentation. | ||
cardanoTestnetDefault :: () | ||
=> CardanoTestnetOptions | ||
-> Conf | ||
-> H.Integration TestnetRuntime | ||
cardanoTestnetDefault opts conf = do | ||
alonzoGenesis <- H.evalEither $ first prettyError Defaults.defaultAlonzoGenesis | ||
currentTime <- H.noteShowIO DTC.getCurrentTime | ||
startTime <- H.noteShow $ DTC.addUTCTime startTimeOffsetSeconds currentTime | ||
cardanoTestnet | ||
opts conf startTime | ||
(Defaults.defaultShelleyGenesis startTime opts) alonzoGenesis Defaults.defaultConwayGenesis | ||
|
||
-- | Setup a number of credentials and pools, like this: | ||
-- | ||
|
@@ -122,13 +145,37 @@ startTimeOffsetSeconds = if OS.isWin32 then 90 else 15 | |
-- > │ └── node-spo{1,2,3} | ||
-- > └── utxo-keys | ||
-- > └── utxo{1,2,3}.{addr,skey,vkey} | ||
cardanoTestnet :: CardanoTestnetOptions -> Conf -> H.Integration TestnetRuntime | ||
cardanoTestnet testnetOptions Conf {tempAbsPath=TmpAbsolutePath tmpAbsPath} = do | ||
testnetMinimumConfigurationRequirements testnetOptions | ||
void $ H.note OS.os | ||
currentTime <- H.noteShowIO DTC.getCurrentTime | ||
let testnetMagic = cardanoTestnetMagic testnetOptions | ||
cardanoTestnet :: () | ||
=> CardanoTestnetOptions -- ^ The options to use. Must be consistent with the genesis files. | ||
-> Conf | ||
-> UTCTime -- ^ The starting time. Must be the same as the one in the shelley genesis. | ||
-> ShelleyGenesis StandardCrypto -- ^ The shelley genesis to use, for example 'Defaults.defaultShelleyGenesis'. | ||
-- Some fields are overridden by the accompanying 'CardanoTestnetOptions'. | ||
-> AlonzoGenesis -- ^ The alonzo genesis to use, for example 'Defaults.defaultAlonzoGenesis'. | ||
-> ConwayGenesis StandardCrypto -- ^ The conway genesis to use, for example 'Defaults.defaultConwayGenesis'. | ||
Comment on lines
+149
to
+155
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here we mix |
||
-> H.Integration TestnetRuntime | ||
cardanoTestnet | ||
testnetOptions Conf {tempAbsPath=TmpAbsolutePath tmpAbsPath} startTime | ||
shelleyGenesis alonzoGenesis conwayGenesis = do | ||
let shelleyStartTime = sgSystemStart shelleyGenesis | ||
shelleyTestnetMagic = sgNetworkMagic shelleyGenesis | ||
optionsMagic :: Word32 = fromIntegral $ cardanoTestnetMagic testnetOptions | ||
testnetMagic = cardanoTestnetMagic testnetOptions | ||
numPoolNodes = length $ cardanoNodes testnetOptions | ||
nbPools = numPools testnetOptions | ||
era = cardanoNodeEra testnetOptions | ||
|
||
-- Sanity checks | ||
testnetMinimumConfigurationRequirements testnetOptions | ||
when (shelleyStartTime /= startTime) $ do | ||
H.note_ $ "Expected same system start in shelley genesis and parameter, but got " <> show shelleyStartTime <> " and " <> show startTime | ||
H.failure | ||
when (shelleyTestnetMagic /= optionsMagic) $ do | ||
H.note_ $ "Expected same network magic in shelley genesis and parameter, but got " <> show shelleyTestnetMagic <> " and " <> show optionsMagic | ||
H.failure | ||
-- Done with sanity checks | ||
|
||
H.note_ OS.os | ||
|
||
if all isJust [mconfig | SpoTestnetNodeOptions mconfig _ <- cardanoNodes testnetOptions] | ||
then | ||
|
@@ -138,10 +185,8 @@ cardanoTestnet testnetOptions Conf {tempAbsPath=TmpAbsolutePath tmpAbsPath} = do | |
-- 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." | ||
else do | ||
startTime <- H.noteShow $ DTC.addUTCTime startTimeOffsetSeconds currentTime | ||
|
||
H.lbsWriteFile (tmpAbsPath </> "byron.genesis.spec.json") | ||
. encode $ defaultByronProtocolParamsJsonValue | ||
. encode $ Defaults.defaultByronProtocolParamsJsonValue | ||
|
||
-- Because in Conway the overlay schedule and decentralization parameter | ||
-- are deprecated, we must use the "create-staked" cli command to create | ||
|
@@ -153,10 +198,18 @@ cardanoTestnet testnetOptions Conf {tempAbsPath=TmpAbsolutePath tmpAbsPath} = do | |
(tmpAbsPath </> "byron.genesis.spec.json") | ||
(tmpAbsPath </> "byron-gen-command") | ||
|
||
_ <- createSPOGenesisAndFiles testnetOptions startTime (TmpAbsolutePath tmpAbsPath) | ||
-- Write Alonzo genesis file | ||
alonzoGenesisJsonFile <- H.noteShow $ tmpAbsPath </> "genesis.alonzo.spec.json" | ||
H.evalIO $ LBS.writeFile alonzoGenesisJsonFile $ Aeson.encode alonzoGenesis | ||
|
||
-- Write Conway genesis file | ||
conwayGenesisJsonFile <- H.noteShow $ tmpAbsPath </> "genesis.conway.spec.json" | ||
H.evalIO $ LBS.writeFile conwayGenesisJsonFile $ Aeson.encode conwayGenesis | ||
|
||
configurationFile <- H.noteShow $ tmpAbsPath </> "configuration.yaml" | ||
|
||
_ <- createSPOGenesisAndFiles nbPools era shelleyGenesis (TmpAbsolutePath tmpAbsPath) | ||
|
||
poolKeys <- H.noteShow $ flip fmap [1..numPoolNodes] $ \n -> | ||
PoolNodeKeys | ||
{ poolNodeKeysColdVkey = tmpAbsPath </> "pools" </> "cold" <> show n <> ".vkey" | ||
|
@@ -213,7 +266,7 @@ cardanoTestnet testnetOptions Conf {tempAbsPath=TmpAbsolutePath tmpAbsPath} = do | |
|
||
|
||
-- Add Byron, Shelley and Alonzo genesis hashes to node configuration | ||
finalYamlConfig <- createConfigYaml (TmpAbsolutePath tmpAbsPath) $ cardanoNodeEra testnetOptions | ||
finalYamlConfig <- createConfigYaml (TmpAbsolutePath tmpAbsPath) era | ||
|
||
H.evalIO $ LBS.writeFile configurationFile finalYamlConfig | ||
|
||
|
@@ -337,7 +390,7 @@ cardanoTestnet testnetOptions Conf {tempAbsPath=TmpAbsolutePath tmpAbsPath} = do | |
|
||
let runtime = TestnetRuntime | ||
{ configurationFile | ||
, shelleyGenesisFile = tmpAbsPath </> defaultShelleyGenesisFp | ||
, shelleyGenesisFile = tmpAbsPath </> Defaults.defaultShelleyGenesisFp | ||
, testnetMagic | ||
, poolNodes | ||
, wallets = wallets | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, we're not mixing
CardanoTestnetOptions
and genesis files, which is good (as I explained elsewhere). This is nice for the vast majority of callers, that don't need to be exposed to a complex API.