Skip to content
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

create-testnet-data: correctly compute set of credentials delegating votes to a drep in conway genesis #943

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeApplications #-}

{- HLINT ignore "Use zipWith" -}

module Cardano.CLI.EraBased.Run.Genesis.CreateTestnetData
( runGenesisKeyGenUTxOCmd
, runGenesisKeyGenGenesisCmd
Expand Down Expand Up @@ -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 =
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to @palas: this new delegs value is like the old cgDelegs one, except that it doesn't hardcode applying some constructors right away in nested positions. This allows to use delegs at the source for computing cgDelegs and cgInitialDReps. This is important to make sure we are consistent between the two.

fromList
. map
( bimap
verificationKeytoStakeCredential
(L.DelegVote . L.DRepCredential . verificationKeyToDRepCredential)
)
map
(first verificationKeytoStakeCredential)
(zip stakingKeys (case dRepKeys of [] -> []; _ -> cycle dRepKeys))
Fixed Show fixed Hide fixed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is problematic and thankfully it showed up in the tests:

/out/conway-genesis.json
        149 ┃ 
        150 ┃     length (cgInitialDReps conwayGenesis) H.=== numDReps
            ┃     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            ┃     │ ━━━ Failed (- lhs) (+ rhs) ━━━
            ┃     │ - 4
            ┃     │ + 5
        151 ┃ 
        152 ┃     length (cgDelegs conwayGenesis) H.=== numStakeDelegs

We have: numStakeDelegs = 4 and

numDReps :: Int
numDReps = 5

Because we use zip the 5th drep is ignored because there is no stake key to delegate to it. We must therefore take into consideration dreps with no delegators.


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
}
)
)
Expand Down
Loading