From 1a46427b8194406451daa221e7ca0c63869dff4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Thu, 17 Oct 2024 20:25:13 +0200 Subject: [PATCH] create-testnet-data: correctly compute set of credentials delegating votes to a drep in conway genesis --- .../EraBased/Run/Genesis/CreateTestnetData.hs | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Genesis/CreateTestnetData.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Genesis/CreateTestnetData.hs index 514ceb005..ad0f6d2b2 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Genesis/CreateTestnetData.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Genesis/CreateTestnetData.hs @@ -12,6 +12,8 @@ {-# LANGUAGE TupleSections #-} {-# LANGUAGE TypeApplications #-} +{- HLINT ignore "Use zipWith" -} + module Cardano.CLI.EraBased.Run.Genesis.CreateTestnetData ( runGenesisKeyGenUTxOCmd , runGenesisKeyGenGenesisCmd @@ -338,40 +340,41 @@ runGenesisCreateTestNetDataCmd addDRepsToConwayGenesis :: [VerificationKey DRepKey] + -- \^ The credential of the DReps -> [VerificationKey StakeKey] + -- \^ The credentials of those that delegate their votes to the dreps. It happens + -- to only be stake keys now, but it could be more general in the future. -> L.ConwayGenesis L.StandardCrypto + -- \^ The genesis data to amend -> L.ConwayGenesis L.StandardCrypto addDRepsToConwayGenesis dRepKeys stakingKeys conwayGenesis = - conwayGenesis - { L.cgDelegs = delegs (zip stakingKeys (case dRepKeys of [] -> []; _ -> cycle dRepKeys)) - , L.cgInitialDReps = initialDReps (L.ucppDRepDeposit $ L.cgUpgradePParams conwayGenesis) dRepKeys - } + conwayGenesis{L.cgDelegs, L.cgInitialDReps} where - delegs - :: [(VerificationKey StakeKey, VerificationKey DRepKey)] - -> ListMap (L.Credential L.Staking L.StandardCrypto) (L.Delegatee L.StandardCrypto) + -- The credential, to the drep it delegates to + delegs :: [(L.Credential L.Staking L.StandardCrypto, VerificationKey DRepKey)] delegs = - fromList - . map - ( bimap - verificationKeytoStakeCredential - (L.DelegVote . L.DRepCredential . verificationKeyToDRepCredential) - ) + map + (first verificationKeytoStakeCredential) + (zip stakingKeys (case dRepKeys of [] -> []; _ -> cycle dRepKeys)) + + minDeposit = L.ucppDRepDeposit $ L.cgUpgradePParams conwayGenesis + cgDelegs = fromList $ map (second (L.DelegVote . L.DRepCredential . verificationKeyToDRepCredential)) delegs + cgInitialDReps = initialDReps $ map (\(stakingCred, drep) -> (drep, Set.singleton stakingCred)) delegs initialDReps - :: Lovelace - -> [VerificationKey DRepKey] + :: [(VerificationKey DRepKey, Set.Set (L.Credential L.Staking L.StandardCrypto))] + -- \^ The initial DReps and the credentials of those that delegate their votes to them -> ListMap (L.Credential L.DRepRole L.StandardCrypto) (L.DRepState L.StandardCrypto) - initialDReps minDeposit = + initialDReps = fromList . map - ( \c -> - ( verificationKeyToDRepCredential c + ( \(drep, drepDelegs) -> + ( verificationKeyToDRepCredential drep , L.DRepState { L.drepExpiry = EpochNo 1_000 , L.drepAnchor = SNothing , L.drepDeposit = max (L.Coin 1_000_000) minDeposit - , L.drepDelegs = Set.empty + , L.drepDelegs } ) )