Skip to content

Commit

Permalink
Make cardano create-testnet-data register DReps and delegate stake de…
Browse files Browse the repository at this point in the history
…legators to them

- Create default conway genesis file and register DReps
- Delegate vote to DReps
- Add option to not write DReps to disk and update tests
- Pass template conway genesis spec as parameter
- Add alonzo genesis parameter with default
- Separate insecure key generation from pool assignation
- Change distribution algorithm so that remainder is distributed
- Refactor stake delegator creation to use same code for `OnDisk` and `Transient`
- Use generateInsecureSigningKey for generating DReps
- Improve generated README.md for DReps folder
- Move transient test and check no dir created
- Add basic checks about Conway genesis to test
- Invalidate Hydra cache
  • Loading branch information
palas committed Mar 14, 2024
1 parent 4ff26c0 commit 554e845
Show file tree
Hide file tree
Showing 25 changed files with 430 additions and 222 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/haskell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:

env:
# Modify this value to "invalidate" the cabal cache.
CABAL_CACHE_VERSION: "2024-02-23-4"
CABAL_CACHE_VERSION: "2024-03-14-2"

concurrency:
group: >
Expand Down
7 changes: 7 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ index-state:
packages:
cardano-cli

source-repository-package
type: git
location: https://github.com/IntersectMBO/cardano-api.git
tag: d77f096d0647c38bc2f87a97fda28cef7f31c679
subdir: cardano-api
--sha256: sha256-lFDjMQayPFhc5suvTChFZHtuVIOM9oLVDsfAZ42qm0k=

package cardano-cli
ghc-options: -Werror

Expand Down
8 changes: 5 additions & 3 deletions cardano-cli/src/Cardano/CLI/EraBased/Commands/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,13 @@ data GenesisCreateStakedCmdArgs = GenesisCreateStakedCmdArgs
} deriving Show

data GenesisCreateTestNetDataCmdArgs = GenesisCreateTestNetDataCmdArgs
{ specShelley :: !(Maybe FilePath) -- ^ Path to the @genesis-shelley@ file to use. If unspecified, a default one will be used if omitted.
{ specShelley :: !(Maybe FilePath) -- ^ Path to the @genesis-shelley@ file to use. If unspecified, a default one will be used.
, specAlonzo :: !(Maybe FilePath) -- ^ Path to the @genesis-alonzo@ file to use. If unspecified, a default one will be used.
, specConway :: !(Maybe FilePath) -- ^ Path to the @genesis-conway@ file to use. If unspecified, a default one will be used.
, 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 :: !StakeDelegators -- ^ The number of delegators to pools to create.
, numDrepKeys :: !Word -- ^ The number of DRep keys to create. Right now they receive neither delegation nor are registrated. This will come later.
, stakeDelegators :: !StakeDelegators -- ^ The number of delegators to pools and DReps to create.
, numDRepKeys :: !DRepCredentials -- ^ The number of DRep keys to create. They are registered and get delegated to by stake delegators
, 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.
, totalSupply :: !(Maybe Coin) -- ^ The total number of Lovelace
Expand Down
41 changes: 24 additions & 17 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ pGenesisCreateTestNetData :: EnvCli -> Parser (GenesisCmds era)
pGenesisCreateTestNetData envCli =
fmap GenesisCreateTestNetData $ GenesisCreateTestNetDataCmdArgs
<$> (optional $ pSpecFile "shelley")
<*> (optional $ pSpecFile "alonzo")
<*> (optional $ pSpecFile "conway")
<*> pNumGenesisKeys
<*> pNumPools
<*> pNumStakeDelegs
Expand Down Expand Up @@ -245,27 +247,32 @@ pGenesisCreateTestNetData envCli =
, Opt.help "The number of stake pool credential sets to make (default is 0)."
, Opt.value 0
]
pNumDReps :: Parser Word
pNumDReps :: Parser DRepCredentials
pNumDReps =
Opt.option Opt.auto $ mconcat
[ Opt.long "drep-keys"
, Opt.metavar "INT"
, Opt.help "The number of DRep credentials to make (default is 0)."
, Opt.value 0
]
pDReps OnDisk "drep-keys" "Credentials are written to disk."
<|> pDReps Transient "transient-drep-keys" "The credentials are NOT written to disk."
where
pDReps :: CredentialGenerationMode -> String -> String -> Parser DRepCredentials
pDReps mode modeOptionName modeExplanation =
DRepCredentials mode <$>
(Opt.option Opt.auto $ mconcat
[ Opt.long modeOptionName
, Opt.help $ "The number of DRep credentials to make (default is 0). " <> modeExplanation
, Opt.metavar "INT", Opt.value 0
])
pNumStakeDelegs :: Parser StakeDelegators
pNumStakeDelegs =
pNumOnDiskStakeDelegators <|> pNumTransientStakeDelegs
pStakeDelegators OnDisk "stake-delegators" "Credentials are written to disk."
<|> pStakeDelegators Transient "transient-stake-delegators" "The credentials are NOT written to disk."
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]
pStakeDelegators :: CredentialGenerationMode -> String -> String -> Parser StakeDelegators
pStakeDelegators mode modeOptionName modeExplanation =
StakeDelegators mode <$>
(Opt.option Opt.auto $ mconcat
[ Opt.long modeOptionName
, Opt.help $ "The number of stake delegator credential sets to make (default is 0). " <> modeExplanation
, Opt.metavar "INT", Opt.value 0
])
pNumStuffedUtxoCount :: Parser Word
pNumStuffedUtxoCount =
Opt.option Opt.auto $ mconcat
Expand Down
15 changes: 9 additions & 6 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Address.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

module Cardano.CLI.EraBased.Run.Address
( runAddressCmds

, runAddressBuildCmd
, runAddressKeyGenCmd
, runAddressKeyHashCmd
, generateAndWriteKeyFiles
) where

import Cardano.Api
Expand All @@ -26,6 +26,7 @@ import Cardano.CLI.Types.Key (PaymentVerifier (..), StakeIdentifier (.
StakeVerifier (..), VerificationKeyTextOrFile, generateKeyPair,
readVerificationKeyOrHashOrFile, readVerificationKeyTextOrFileAnyOf)

import Control.Monad (void)
import qualified Data.ByteString.Char8 as BS
import Data.Function
import qualified Data.Text.IO as Text
Expand All @@ -50,9 +51,9 @@ runAddressKeyGenCmd
-> SigningKeyFile Out
-> ExceptT AddressCmdError IO ()
runAddressKeyGenCmd fmt kt vkf skf = case kt of
AddressKeyShelley -> generateAndWriteKeyFiles fmt AsPaymentKey vkf skf
AddressKeyShelleyExtended -> generateAndWriteKeyFiles fmt AsPaymentExtendedKey vkf skf
AddressKeyByron -> generateAndWriteByronKeyFiles AsByronKey vkf skf
AddressKeyShelley -> void $ generateAndWriteKeyFiles fmt AsPaymentKey vkf skf
AddressKeyShelleyExtended -> void $ generateAndWriteKeyFiles fmt AsPaymentExtendedKey vkf skf
AddressKeyByron -> generateAndWriteByronKeyFiles AsByronKey vkf skf

generateAndWriteByronKeyFiles :: ()
=> Key keyrole
Expand All @@ -73,9 +74,11 @@ generateAndWriteKeyFiles :: ()
-> AsType keyrole
-> VerificationKeyFile Out
-> SigningKeyFile Out
-> ExceptT AddressCmdError IO ()
-> ExceptT AddressCmdError IO (VerificationKey keyrole, SigningKey keyrole)
generateAndWriteKeyFiles fmt asType vkf skf = do
uncurry (writePaymentKeyFiles fmt vkf skf) =<< liftIO (generateKeyPair asType)
(vk, sk) <- liftIO (generateKeyPair asType)
writePaymentKeyFiles fmt vkf skf vk sk
return (vk, sk)

writePaymentKeyFiles
:: Key keyrole
Expand Down
Loading

0 comments on commit 554e845

Please sign in to comment.