-
Notifications
You must be signed in to change notification settings - Fork 23
create-testnet-data: create byron genesis #974
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
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 |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
| {-# LANGUAGE GADTs #-} | ||
| {-# LANGUAGE NamedFieldPuns #-} | ||
| {-# LANGUAGE NumericUnderscores #-} | ||
| {-# LANGUAGE RecordWildCards #-} | ||
| {-# LANGUAGE ScopedTypeVariables #-} | ||
| {-# LANGUAGE TupleSections #-} | ||
| {-# LANGUAGE TypeApplications #-} | ||
|
|
@@ -24,6 +25,8 @@ module Cardano.CLI.EraBased.Run.Genesis.CreateTestnetData | |
| where | ||
|
|
||
| import Cardano.Api hiding (ConwayEra) | ||
| import Cardano.Api.Byron (rationalToLovelacePortion) | ||
| import qualified Cardano.Api.Byron as Byron hiding (GenesisParameters) | ||
| import Cardano.Api.Consensus (ShelleyGenesisStaking (..)) | ||
| import Cardano.Api.Ledger (StrictMaybe (SNothing)) | ||
| import qualified Cardano.Api.Ledger as L | ||
|
|
@@ -34,6 +37,8 @@ import Cardano.Api.Shelley (Hash (..), KESPeriod (KESPeriod), | |
| VrfKey, alonzoGenesisDefaults, conwayGenesisDefaults, shelleyGenesisDefaults, | ||
| toShelleyAddr, toShelleyNetwork, toShelleyStakeAddr) | ||
|
|
||
| import Cardano.CLI.Byron.Genesis (NewDirectory (NewDirectory)) | ||
| import qualified Cardano.CLI.Byron.Genesis as Byron | ||
| import qualified Cardano.CLI.Commands.Node as Cmd | ||
| import Cardano.CLI.EraBased.Commands.Genesis as Cmd | ||
| import qualified Cardano.CLI.EraBased.Commands.Governance.Committee as CC | ||
|
|
@@ -52,11 +57,14 @@ import Cardano.CLI.Types.Errors.GenesisCmdError | |
| import Cardano.CLI.Types.Errors.NodeCmdError | ||
| import Cardano.CLI.Types.Errors.StakePoolCmdError | ||
| import Cardano.CLI.Types.Key | ||
| import qualified Cardano.Crypto as Crypto hiding (Hash) | ||
| import qualified Cardano.Crypto.Hash as Crypto | ||
| import Cardano.Prelude (canonicalEncodePretty) | ||
|
|
||
| import Control.DeepSeq (NFData, deepseq) | ||
| import Control.Monad (forM, forM_, unless, void, when) | ||
| import Data.Aeson (toJSON, (.=)) | ||
| import qualified Data.Aeson as Aeson | ||
| import qualified Data.Aeson.Encode.Pretty as Aeson | ||
| import Data.Bifunctor (Bifunctor (..)) | ||
| import Data.ByteString (ByteString) | ||
|
|
@@ -67,7 +75,8 @@ import Data.Functor.Identity (Identity) | |
| import Data.ListMap (ListMap (..)) | ||
| import Data.Map.Strict (Map) | ||
| import qualified Data.Map.Strict as Map | ||
| import Data.Maybe (fromMaybe) | ||
| import Data.Maybe (fromJust, fromMaybe) | ||
| import Data.Ratio ((%)) | ||
| import qualified Data.Sequence.Strict as Seq | ||
| import qualified Data.Set as Set | ||
| import Data.String (fromString) | ||
|
|
@@ -78,12 +87,13 @@ import GHC.Exts (IsList (..)) | |
| import GHC.Generics (Generic) | ||
| import GHC.Num (Natural) | ||
| import Lens.Micro ((^.)) | ||
| import System.Directory (createDirectoryIfMissing) | ||
| import System.Directory | ||
| import System.FilePath ((</>)) | ||
| import qualified System.Random as Random | ||
| import System.Random (StdGen) | ||
| import qualified Text.JSON.Canonical (ToJSON) | ||
| import Text.JSON.Canonical (parseCanonicalJSON, renderCanonicalJSON) | ||
| import Text.Printf (printf) | ||
|
|
||
| runGenesisKeyGenGenesisCmd | ||
| :: GenesisKeyGenGenesisCmdArgs | ||
|
|
@@ -241,7 +251,8 @@ runGenesisCreateTestNetDataCmd | |
| case networkId of | ||
| Just networkFromFlag -> networkFromFlag | ||
| Nothing -> fromNetworkMagic (NetworkMagic $ sgNetworkMagic shelleyGenesisInit) | ||
| shelleyGenesis = shelleyGenesisInit{sgNetworkMagic = unNetworkMagic (toNetworkMagic actualNetworkId)} | ||
| actualNetworkWord32 = unNetworkMagic (toNetworkMagic actualNetworkId) | ||
| shelleyGenesis = shelleyGenesisInit{sgNetworkMagic = actualNetworkWord32} | ||
| -- {0 -> genesis-keys/genesis0/key.vkey, 1 -> genesis-keys/genesis1/key.vkey, ...} | ||
| genesisVKeysPaths = mkPaths numGenesisKeys genesisDir "genesis" "key.vkey" | ||
| -- {0 -> delegate-keys/delegate0/key.vkey, 1 -> delegate-keys/delegate1/key.vkey, ...} | ||
|
|
@@ -278,7 +289,7 @@ runGenesisCreateTestNetDataCmd | |
|
|
||
| -- Pools | ||
| poolParams <- forM [1 .. numPools] $ \index -> do | ||
| let poolDir = poolsDir </> ("pool" <> show index) | ||
| let poolDir = mkPoolDir index | ||
|
|
||
| createPoolCredentials desiredKeyOutputFormat poolDir | ||
| -- Indexes of directories created on disk start at 1, but | ||
|
|
@@ -377,7 +388,32 @@ runGenesisCreateTestNetDataCmd | |
| stuffedUtxoAddrs | ||
| shelleyGenesis | ||
|
|
||
| -- Write genesis.json file to output | ||
| let byronGenesisFp = outputDir </> "byron.genesis.spec.json" -- This file is used by the performance testing team. | ||
| void $ writeFileGenesis byronGenesisFp $ WritePretty defaultByronProtocolParamsJsonValue | ||
|
|
||
| let byronGenesisParameters = mkByronGenesisParameters actualNetworkWord32 byronGenesisFp shelleyGenesis' | ||
| byronOutputDir = outputDir </> "byron-gen-command" | ||
| (byronGenesis, byronSecrets) <- | ||
| firstExceptT GenesisCmdByronError $ Byron.mkGenesis byronGenesisParameters | ||
|
|
||
| firstExceptT GenesisCmdByronError $ | ||
| Byron.dumpGenesis (NewDirectory byronOutputDir) byronGenesis byronSecrets | ||
|
|
||
| -- Move things from byron-gen-command to the nodes' directories | ||
| forM_ [1 .. numPools] $ \index -> do | ||
| let poolDir = mkPoolDir index | ||
| inputIndex = printf "%03d" (index - 1) -- mkGenesis is 0-based | ||
| mkInputFile filePrefix suffix = byronOutputDir </> filePrefix <> inputIndex <> suffix | ||
| liftIO $ do | ||
| renameFile (mkInputFile "delegate-keys." ".key") (poolDir </> "byron-delegate.key") | ||
| renameFile (mkInputFile "delegation-cert." ".json") (poolDir </> "byron-delegation.cert") | ||
|
|
||
| -- Install the byron genesis where it's supposed to be | ||
| liftIO $ renameFile (byronOutputDir </> "genesis.json") (outputDir </> "byron-genesis.json") | ||
| -- Note that we leave some content in the "byron-gen-command" directory: | ||
| -- 1. Deleting a non-empty directory on Windows is hard (yes -> https://github.com/haskell/directory/pull/108) | ||
| -- 2. Users of cardano-testnet may use them | ||
|
|
||
| forM_ | ||
| [ ("conway-genesis.json", WritePretty conwayGenesis') | ||
| , ("shelley-genesis.json", WritePretty shelleyGenesis') | ||
|
|
@@ -392,6 +428,31 @@ runGenesisCreateTestNetDataCmd | |
| utxoKeysDir = outputDir </> "utxo-keys" | ||
| poolsDir = outputDir </> "pools-keys" | ||
| stakeDelegatorsDir = outputDir </> "stake-delegators" | ||
| mkPoolDir idx = poolsDir </> ("pool" <> show idx) | ||
| byronPoolNumber = max 1 numPools -- byron genesis creation needs a >= 1 number of pools | ||
|
|
||
| -- All arbitrary values come from cardano-testnet | ||
| mkByronGenesisParameters actualNetworkWord32 byronGenesisFp shelleyGenesis = | ||
|
Contributor
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. All of the Byron functionality should be factored out on its own as much as possible. A separate module for it would make sense. |
||
| Byron.GenesisParameters{..} | ||
| where | ||
| gpStartTime = sgSystemStart shelleyGenesis | ||
|
Contributor
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. These needs comments or need to point to documentation that explains them. |
||
| gpProtocolParamsFile = byronGenesisFp | ||
| gpK = Byron.BlockCount 10 | ||
| protocolMagicId = Crypto.ProtocolMagicId actualNetworkWord32 | ||
| gpProtocolMagic = Crypto.AProtocolMagic (L.Annotated protocolMagicId ()) Crypto.RequiresMagic | ||
| gpTestnetBalance = | ||
| Byron.TestnetBalanceOptions | ||
| 0 -- poor adresses | ||
| byronPoolNumber -- delegate addresses (BFT nodes) | ||
| (fromJust $ Byron.toByronLovelace $ L.Coin $ 3_000_000_000 * fromIntegral byronPoolNumber) | ||
| 1 | ||
| gpFakeAvvmOptions = | ||
| Byron.FakeAvvmOptions | ||
| 0 -- avvm entry count | ||
| (fromJust $ Byron.toByronLovelace $ L.Coin 0) -- avvm entry balance | ||
| gpAvvmBalanceFactor = rationalToLovelacePortion $ 1 % 1 | ||
| gpSeed = Nothing | ||
|
|
||
| mkDelegationMapEntry | ||
| :: Delegation -> (L.KeyHash L.Staking L.StandardCrypto, L.PoolParams L.StandardCrypto) | ||
| mkDelegationMapEntry d = (dDelegStaking d, dPoolParams d) | ||
|
|
@@ -496,6 +557,37 @@ runGenesisCreateTestNetDataCmd | |
| desiredKeyOutputFormat :: KeyOutputFormat | ||
| desiredKeyOutputFormat = KeyOutputFormatTextEnvelope | ||
|
|
||
| -- | We need to pass these values to create the Byron genesis file. | ||
| -- The values here don't matter as the testnet conditions are ultimately determined | ||
| -- by the Shelley genesis. | ||
|
Contributor
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. Is there any documentation we can point to? |
||
| defaultByronProtocolParamsJsonValue :: Aeson.Value | ||
| defaultByronProtocolParamsJsonValue = | ||
| Aeson.object | ||
| [ "heavyDelThd" .= toJSON @String "300000000000" | ||
smelc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| , "maxBlockSize" .= toJSON @String "2000000" | ||
| , "maxTxSize" .= toJSON @String "4096" | ||
| , "maxHeaderSize" .= toJSON @String "2000000" | ||
| , "maxProposalSize" .= toJSON @String "700" | ||
| , "mpcThd" .= toJSON @String "20000000000000" | ||
| , "scriptVersion" .= toJSON @Int 0 | ||
| , "slotDuration" .= toJSON @String "1000" | ||
| , "softforkRule" | ||
| .= Aeson.object | ||
| [ "initThd" .= toJSON @String "900000000000000" | ||
| , "minThd" .= toJSON @String "600000000000000" | ||
| , "thdDecrement" .= toJSON @String "50000000000000" | ||
| ] | ||
| , "txFeePolicy" | ||
| .= Aeson.object | ||
| [ "multiplier" .= toJSON @String "43946000000" | ||
| , "summand" .= toJSON @String "155381000000000" | ||
| ] | ||
| , "unlockStakeEpoch" .= toJSON @String "18446744073709551615" | ||
| , "updateImplicit" .= toJSON @String "10000" | ||
| , "updateProposalThd" .= toJSON @String "100000000000000" | ||
| , "updateVoteThd" .= toJSON @String "1000000000000" | ||
| ] | ||
|
|
||
| writeREADME | ||
| :: () | ||
| => FilePath | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,8 @@ | ||
| alonzo-genesis.json | ||
| byron-gen-command/genesis-keys.000.key | ||
| byron-gen-command/genesis-keys.001.key | ||
|
Comment on lines
+2
to
+3
Contributor
Author
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. Those files are not used by |
||
| byron-genesis.json | ||
| byron.genesis.spec.json | ||
| cc-keys/README.md | ||
| cc-keys/cc1/cc.cold.skey | ||
| cc-keys/cc1/cc.cold.vkey | ||
|
|
@@ -63,6 +67,8 @@ genesis-keys/genesis1/key.vkey | |
| genesis-keys/genesis2/key.skey | ||
| genesis-keys/genesis2/key.vkey | ||
| pools-keys/README.md | ||
| pools-keys/pool1/byron-delegate.key | ||
| pools-keys/pool1/byron-delegation.cert | ||
| pools-keys/pool1/cold.skey | ||
| pools-keys/pool1/cold.vkey | ||
| pools-keys/pool1/kes.skey | ||
|
|
@@ -73,6 +79,8 @@ pools-keys/pool1/staking-reward.skey | |
| pools-keys/pool1/staking-reward.vkey | ||
| pools-keys/pool1/vrf.skey | ||
| pools-keys/pool1/vrf.vkey | ||
| pools-keys/pool2/byron-delegate.key | ||
| pools-keys/pool2/byron-delegation.cert | ||
| pools-keys/pool2/cold.skey | ||
| pools-keys/pool2/cold.vkey | ||
| pools-keys/pool2/kes.skey | ||
|
|
||
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.
I think this default should live in the parsers.