Skip to content

Commit

Permalink
Apply review comments (1/n) (will ultimately be squashed)
Browse files Browse the repository at this point in the history
  • Loading branch information
smelc committed Dec 12, 2023
1 parent f175afe commit a4a8fc7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 29 deletions.
2 changes: 1 addition & 1 deletion cardano-cli/src/Cardano/CLI/EraBased/Commands/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ data GenesisCreateTestNetDataCmdArgs = GenesisCreateTestNetDataCmdArgs
{ specShelley :: !(Maybe FilePath) -- ^ Path to the @genesis-shelley@ file to use. If unspecified, a default one will be used if omitted.
, numGenesisKeys :: !Word -- ^ The number of genesis keys credentials to create and write to disk.
, numPools :: !Word -- ^ The number of stake pools credentials to create and write to disk.
, stakeDelegators :: !(StakeDelegatorsKind, Word) -- ^ The number of delegators to pools to create.
, stakeDelegators :: !StakeDelegators -- ^ The number of delegators to pools to create.
, numStuffedUtxo :: !Word -- ^ The number of UTxO accounts to make. They are "stuffed" because the credentials are not written to disk.
, numUtxoKeys :: !Word -- ^ The number of UTxO credentials to create and write to disk.
, supply :: !(Maybe Lovelace) -- ^ The number of Lovelace to distribute over initial, non-delegating stake holders.
Expand Down
29 changes: 13 additions & 16 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ pGenesisCreateTestNetData envCli =
<$> (optional $ pSpecFile "shelley")
<*> pNumGenesisKeys
<*> pNumPools
<*> (fmap (OnDisk, ) pNumStakeDelegs <|> fmap (Transient,) pNumTransientStakeDelegs)
<*> pNumStakeDelegs
<*> pNumStuffedUtxoCount
<*> pNumUtxoKeys
<*> pSupply
Expand Down Expand Up @@ -233,22 +233,19 @@ pGenesisCreateTestNetData envCli =
, Opt.help "The number of stake pool credential sets to make (default is 0)."
, Opt.value 0
]
pNumStakeDelegs :: Parser Word
pNumStakeDelegs :: Parser StakeDelegators
pNumStakeDelegs =
Opt.option Opt.auto $ mconcat
[ Opt.long "stake-delegators"
, Opt.metavar "INT"
, Opt.help "The number of stake delegator credential sets to make (default is 0). Credentials are written to disk."
, Opt.value 0
]
pNumTransientStakeDelegs :: Parser Word
pNumTransientStakeDelegs =
Opt.option Opt.auto $ mconcat
[ Opt.long "transient-stake-delegators"
, Opt.metavar "INT"
, Opt.help "The number of stake delegator credential sets to make (default is 0). The credentials are NOT written to disk."
, Opt.value 0
]
pNumOnDiskStakeDelegators <|> pNumTransientStakeDelegs
where
pNumOnDiskStakeDelegators = fmap OnDisk $ Opt.option Opt.auto $ mconcat $
[ Opt.long "stake-delegators"
, Opt.help "The number of stake delegator credential sets to make (default is 0). Credentials are written to disk."
] ++ common
pNumTransientStakeDelegs = fmap Transient $ Opt.option Opt.auto $ mconcat $
[ Opt.long "transient-stake-delegators"
, Opt.help "The number of stake delegator credential sets to make (default is 0). The credentials are NOT written to disk."
] ++ common
common = [Opt.metavar "INT", Opt.value 0]
pNumStuffedUtxoCount :: Parser Word
pNumStuffedUtxoCount =
Opt.option Opt.auto $ mconcat
Expand Down
18 changes: 10 additions & 8 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/CreateTestnetData.hs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ runGenesisCreateTestNetDataCmd Cmd.GenesisCreateTestNetDataCmdArgs
, specShelley
, numGenesisKeys
, numPools
, stakeDelegators = (stakeDelegatorsKind, numStakeDelegators)
, stakeDelegators
, numStuffedUtxo
, numUtxoKeys
, supply
Expand Down Expand Up @@ -239,10 +239,11 @@ runGenesisCreateTestNetDataCmd Cmd.GenesisCreateTestNetDataCmdArgs
writeREADME poolsDir poolsREADME

-- Stake delegators
forM_ [ 1 .. numStakeDelegators] $ \index -> do
case stakeDelegatorsKind of
OnDisk -> createStakeDelegatorCredentials (stakeDelegatorsDir </> "delegator" <> show index)
Transient -> pure ()
case stakeDelegators of
OnDisk _ ->
forM_ [ 1 .. numStakeDelegators] $ \index -> do
createStakeDelegatorCredentials (stakeDelegatorsDir </> "delegator" <> show index)
Transient _ -> pure ()

let (delegsPerPool, delegsRemaining) = numStakeDelegators `divMod` numPools
delegsForPool poolIx = if delegsRemaining /= 0 && poolIx == numPools
Expand All @@ -254,15 +255,15 @@ runGenesisCreateTestNetDataCmd Cmd.GenesisCreateTestNetDataCmdArgs

-- Distribute M delegates across N pools:
delegations <-
case stakeDelegatorsKind of
OnDisk -> do
case stakeDelegators of
OnDisk _ -> do
let delegates = concat $ repeat stakeDelegatorsDirs
delegatesAndPools = zip delegates distribution
-- We don't need to be attentive to laziness here, because anyway this
-- doesn't scale really well (because we're generating legit credentials,
-- as opposed to the Transient case).
forM delegatesAndPools (uncurry $ computeDelegation networkId)
Transient ->
Transient _ ->
liftIO $ Lazy.forStateM g distribution $ flip computeInsecureDelegation networkId

genDlgs <- readGenDelegsMap genesisVKeysPaths delegateKeys delegateVrfKeys
Expand All @@ -289,6 +290,7 @@ runGenesisCreateTestNetDataCmd Cmd.GenesisCreateTestNetDataCmdArgs
utxoKeysDir = outputDir </> "utxo-keys"
poolsDir = outputDir </> "pools-keys"
stakeDelegatorsDir = outputDir </> "stake-delegators"
numStakeDelegators = case stakeDelegators of OnDisk n -> n; Transient n -> n
mkDelegationMapEntry :: Delegation -> (Ledger.KeyHash Ledger.Staking StandardCrypto, Ledger.PoolParams StandardCrypto)
mkDelegationMapEntry d = (dDelegStaking d, dPoolParams d)

Expand Down
8 changes: 4 additions & 4 deletions cardano-cli/src/Cardano/CLI/Types/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ module Cardano.CLI.Types.Common
, SigningKeyFile
, SlotsTillKesKeyExpiry (..)
, SomeKeyFile(..)
, StakeDelegatorsKind(..)
, StakeDelegators(..)
, StakePoolMetadataFile
, TransferDirection(..)
, TxBodyFile
Expand Down Expand Up @@ -142,9 +142,9 @@ data VoteHashSource
| VoteHashSourceHash (L.SafeHash Crypto.StandardCrypto L.AnchorData)
deriving Show

data StakeDelegatorsKind =
OnDisk -- ^ Credentials are written to disk
| Transient -- ^ Credentials are not written to disk
data StakeDelegators =
OnDisk !Word -- ^ The number of credentials to write to disk
| Transient !Word -- ^ The number of credentials, that are not written to disk
deriving Show

-- | Specify whether to render the script cost as JSON
Expand Down

0 comments on commit a4a8fc7

Please sign in to comment.