Skip to content

Commit

Permalink
Merge pull request #508 from input-output-hk/smelc/create-testnet-dat…
Browse files Browse the repository at this point in the history
…a-improvements

create-testnet-data: add succinct documentation in generated directory
  • Loading branch information
smelc authored Dec 11, 2023
2 parents b0cf3f0 + 44a808b commit 6947822
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 9 deletions.
56 changes: 47 additions & 9 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/CreateTestnetData.hs
Original file line number Diff line number Diff line change
Expand Up @@ -202,32 +202,38 @@ runGenesisCreateTestNetDataCmd Cmd.GenesisCreateTestNetDataCmdArgs
pure $ shelleyGenesisDefaults { sgNetworkMagic = unNetworkMagic (toNetworkMagic networkId) }

let -- {0 -> genesis-keys/genesis0/key.vkey, 1 -> genesis-keys/genesis1/key.vkey, ...}
genesisVKeysPaths = mkPaths numGenesisKeys (outputDir </> "genesis-keys") "genesis" "key.vkey"
genesisVKeysPaths = mkPaths numGenesisKeys genesisDir "genesis" "key.vkey"
-- {0 -> delegate-keys/delegate0/key.vkey, 1 -> delegate-keys/delegate1/key.vkey, ...}
delegateKeys = mkPaths numGenesisKeys (outputDir </> "delegate-keys") "delegate" "key.vkey"
delegateKeys = mkPaths numGenesisKeys delegateDir "delegate" "key.vkey"
-- {0 -> delegate-keys/delegate0/vrf.vkey, 1 -> delegate-keys/delegate1/vrf.vkey, ...}
delegateVrfKeys = mkPaths numGenesisKeys (outputDir </> "delegate-keys") "delegate" "vrf.vkey"
delegateVrfKeys = mkPaths numGenesisKeys delegateDir "delegate" "vrf.vkey"

forM_ [ 1 .. numGenesisKeys ] $ \index -> do
createGenesisKeys (genesisDir </> ("genesis" <> show index))
createDelegateKeys keyOutputFormat (outputDir </> "delegate-keys" </> ("delegate" <> show index))
createDelegateKeys keyOutputFormat (delegateDir </> ("delegate" <> show index))

writeREADME genesisDir genesisREADME
writeREADME delegateDir delegatesREADME

-- UTxO keys
let utxoKeys = [outputDir </> "utxo-keys" </> ("utxo" <> show index) </> "utxo.vkey"
let utxoKeys = [utxoKeysDir </> ("utxo" <> show index) </> "utxo.vkey"
| index <- [ 1 .. numUtxoKeys ]]
forM_ [ 1 .. numUtxoKeys ] $ \index ->
createUtxoKeys $ outputDir </> "utxo-keys" </> ("utxo" <> show index)
createUtxoKeys $ utxoKeysDir </> ("utxo" <> show index)

writeREADME utxoKeysDir utxoKeysREADME

let mayStakePoolRelays = Nothing -- TODO @smelc temporary?

-- Pools
poolParams <- forM [ 1 .. numPools ] $ \index -> do
let poolsDir = outputDir </> "pools-keys"
poolDir = poolsDir </> ("pool" <> show index)
let poolDir = poolsDir </> ("pool" <> show index)

createPoolCredentials keyOutputFormat poolDir
buildPoolParams networkId poolDir Nothing (fromMaybe mempty mayStakePoolRelays)

writeREADME poolsDir poolsREADME

-- Stake delegators
let (delegsPerPool, delegsRemaining) = divMod numStakeDelegators numPools
delegsForPool poolIx = if delegsRemaining /= 0 && poolIx == numPools
Expand Down Expand Up @@ -260,11 +266,43 @@ runGenesisCreateTestNetDataCmd Cmd.GenesisCreateTestNetDataCmdArgs
liftIO $ LBS.writeFile (outputDir </> "genesis.json") $ Aeson.encode shelleyGenesis'
where
genesisDir = outputDir </> "genesis-keys"
delegateDir = outputDir </> "delegate-keys"
utxoKeysDir = outputDir </> "utxo-keys"
poolsDir = outputDir </> "pools-keys"
keyOutputFormat = KeyOutputFormatTextEnvelope
mkDelegationMapEntry :: Delegation -> (Ledger.KeyHash Ledger.Staking StandardCrypto, Ledger.PoolParams StandardCrypto)
mkDelegationMapEntry d = (dDelegStaking d, dPoolParams d)

-- @mkPaths numKeys dir segment filename@ returns the paths to the keys to generate.
writeREADME :: ()
=> FilePath
-> Text.Text
-> ExceptT GenesisCmdError IO ()
writeREADME dir content = do
firstExceptT GenesisCmdFileError . newExceptT $ writeTextFile file content
where
file :: File Text.Text Out = File $ dir </> "README.md"

genesisREADME :: Text.Text
genesisREADME = Text.intercalate "\n"
["Keys generated by the --genesis-keys flag. In Byron these keys were used to mint blocks and initiate hard forks."
, "Starting with Shelley and decentralization, blocks started being produced by other keys than genesis keys."
, "Still, these keys were required to trigger hard forks."
, "With the introduction of Conway, these keys should become useless"]

delegatesREADME :: Text.Text
delegatesREADME = Text.intercalate "\n"
["Keys generated by the --genesis-keys flag. These keys are used to mint blocks when not being completely decentralized",
"(e.g. when stake pools are not the sole block producers). These keys are intended to run nodes."]

utxoKeysREADME :: Text.Text
utxoKeysREADME = Text.intercalate "\n"
["Keys generated by the --utxo-keys flag. These keys receive a portion of the supply."]

poolsREADME :: Text.Text
poolsREADME = Text.intercalate "\n"
["Keys generated by the --pools flag. These keys are intended to run nodes."]

-- | @mkPaths numKeys dir segment filename@ returns the paths to the keys to generate.
-- For example @mkPaths 3 dir prefix fn.ext@ returns
-- [dir/segment1/fn.ext, dir/segment2/fn.ext, dir/segment3/fn.ext]
mkPaths :: Word -> String -> String -> String -> Map Int FilePath
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
delegate-keys/README.md
delegate-keys/delegate1/kes.skey
delegate-keys/delegate1/kes.vkey
delegate-keys/delegate1/key.skey
Expand All @@ -14,11 +15,13 @@ delegate-keys/delegate2/opcert.cert
delegate-keys/delegate2/opcert.counter
delegate-keys/delegate2/vrf.skey
delegate-keys/delegate2/vrf.vkey
genesis-keys/README.md
genesis-keys/genesis1/key.skey
genesis-keys/genesis1/key.vkey
genesis-keys/genesis2/key.skey
genesis-keys/genesis2/key.vkey
genesis.json
pools-keys/README.md
pools-keys/pool1/cold.skey
pools-keys/pool1/cold.vkey
pools-keys/pool1/kes.skey
Expand All @@ -39,6 +42,7 @@ pools-keys/pool2/staking-reward.skey
pools-keys/pool2/staking-reward.vkey
pools-keys/pool2/vrf.skey
pools-keys/pool2/vrf.vkey
utxo-keys/README.md
utxo-keys/utxo1/utxo.skey
utxo-keys/utxo1/utxo.vkey
utxo-keys/utxo2/utxo.skey
Expand Down

0 comments on commit 6947822

Please sign in to comment.