-
Notifications
You must be signed in to change notification settings - Fork 16
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: better UX for supply arguments #581
Changes from all commits
c6203ac
1813191
82cd079
4bd8b73
8c399c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,6 +106,7 @@ import Data.Functor (void) | |
import Data.Functor.Identity (Identity) | ||
import qualified Data.List as List | ||
import qualified Data.List.Split as List | ||
import Data.ListMap (ListMap (..)) | ||
import qualified Data.ListMap as ListMap | ||
import Data.Map.Strict (Map) | ||
import qualified Data.Map.Strict as Map | ||
|
@@ -624,7 +625,7 @@ runGenesisCreateStakedCmd | |
stakePools = [ (Ledger.ppId poolParams', poolParams') | poolParams' <- snd . mkDelegationMapEntry <$> delegations ] | ||
delegAddrs = dInitialUtxoAddr <$> delegations | ||
!shelleyGenesis = | ||
TN.updateCreateStakedOutputTemplate | ||
updateOutputTemplate | ||
-- Shelley genesis parameters | ||
start genDlgs mNonDelegatedSupply (length nonDelegAddrs) nonDelegAddrs stakePools stake | ||
(Just delegatedSupply) numDelegations delegAddrs stuffedUtxoAddrs template | ||
|
@@ -660,6 +661,75 @@ runGenesisCreateStakedCmd | |
|
||
-- ------------------------------------------------------------------------------------------------- | ||
|
||
updateOutputTemplate | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @carbolymer> It's not duplicated: the code you refer to was previously shared was previously used both by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a lot of similar code, like utilities in distribute (nonDelegCoin - subtractForTreasury) nUtxoAddrsNonDeleg utxoAddrsNonDeleg
++
distribute (delegCoin - subtractForTreasury) nUtxoAddrsDeleg utxoAddrsDeleg
++
mkStuffedUtxo stuffedUtxoAddrs Can you de-duplicate parts of this function? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we don't want to change behavior of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm in favour of de-duplicating. I'm un-requesting changes. @Jimbo4350 your call. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's focus on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function is not exported by the module, so I think its name doesn't need to be |
||
:: SystemStart -- ^ System start time | ||
-> Map (Hash GenesisKey) (Hash GenesisDelegateKey, Hash VrfKey) -- ^ Genesis delegation (not stake-based) | ||
-> Maybe Lovelace -- ^ Amount of lovelace not delegated | ||
-> Int -- ^ Number of UTxO addresses that are delegating | ||
-> [AddressInEra ShelleyEra] -- ^ UTxO addresses that are not delegating | ||
-> [(Ledger.KeyHash 'Ledger.StakePool StandardCrypto, Ledger.PoolParams StandardCrypto)] -- ^ Pool map | ||
-> [(Ledger.KeyHash 'Ledger.Staking StandardCrypto, Ledger.KeyHash 'Ledger.StakePool StandardCrypto)] -- ^ Delegaton map | ||
-> Maybe Lovelace -- ^ Amount of lovelace to delegate | ||
-> Int -- ^ Number of UTxO address for delegation | ||
-> [AddressInEra ShelleyEra] -- ^ UTxO address for delegation | ||
-> [AddressInEra ShelleyEra] -- ^ Stuffed UTxO addresses | ||
-> ShelleyGenesis StandardCrypto -- ^ Template from which to build a genesis | ||
-> ShelleyGenesis StandardCrypto -- ^ Updated genesis | ||
updateOutputTemplate | ||
(SystemStart sgSystemStart) | ||
genDelegMap mAmountNonDeleg nUtxoAddrsNonDeleg utxoAddrsNonDeleg pools stake | ||
amountDeleg | ||
nUtxoAddrsDeleg utxoAddrsDeleg stuffedUtxoAddrs | ||
template@ShelleyGenesis{ sgProtocolParams } = | ||
template | ||
{ sgSystemStart | ||
, sgMaxLovelaceSupply = fromIntegral $ nonDelegCoin + delegCoin | ||
, sgGenDelegs = shelleyDelKeys | ||
, sgInitialFunds = ListMap.fromList | ||
[ (toShelleyAddr addr, toShelleyLovelace v) | ||
| (addr, v) <- | ||
distribute (nonDelegCoin - subtractForTreasury) nUtxoAddrsNonDeleg utxoAddrsNonDeleg | ||
++ | ||
distribute (delegCoin - subtractForTreasury) nUtxoAddrsDeleg utxoAddrsDeleg | ||
++ | ||
mkStuffedUtxo stuffedUtxoAddrs | ||
] | ||
, sgStaking = | ||
ShelleyGenesisStaking | ||
{ sgsPools = ListMap pools | ||
, sgsStake = ListMap stake | ||
} | ||
, sgProtocolParams | ||
} | ||
where | ||
maximumLovelaceSupply :: Word64 | ||
maximumLovelaceSupply = sgMaxLovelaceSupply template | ||
-- If the initial funds are equal to the maximum funds, rewards cannot be created. | ||
subtractForTreasury :: Integer | ||
subtractForTreasury = nonDelegCoin `quot` 10 | ||
nonDelegCoin, delegCoin :: Integer | ||
-- if --supply is not specified, non delegated supply comes from the template passed to this function: | ||
nonDelegCoin = fromIntegral (maybe maximumLovelaceSupply unLovelace mAmountNonDeleg) | ||
delegCoin = maybe 0 fromIntegral amountDeleg | ||
|
||
distribute :: Integer -> Int -> [AddressInEra ShelleyEra] -> [(AddressInEra ShelleyEra, Lovelace)] | ||
distribute funds nAddrs addrs = zip addrs (fmap Lovelace (coinPerAddr + remainder:repeat coinPerAddr)) | ||
where coinPerAddr, remainder :: Integer | ||
(coinPerAddr, remainder) = funds `divMod` fromIntegral nAddrs | ||
|
||
mkStuffedUtxo :: [AddressInEra ShelleyEra] -> [(AddressInEra ShelleyEra, Lovelace)] | ||
mkStuffedUtxo xs = (, Lovelace minUtxoVal) <$> xs | ||
where Coin minUtxoVal = sgProtocolParams ^. ppMinUTxOValueL | ||
|
||
shelleyDelKeys = Map.fromList | ||
[ (gh, Ledger.GenDelegPair gdh h) | ||
| (GenesisKeyHash gh, | ||
(GenesisDelegateKeyHash gdh, VrfKeyHash h)) <- Map.toList genDelegMap | ||
] | ||
|
||
unLovelace :: Integral a => Lovelace -> a | ||
unLovelace (Lovelace coin) = fromIntegral coin | ||
|
||
createDelegateKeys :: KeyOutputFormat -> FilePath -> Word -> ExceptT GenesisCmdError IO () | ||
createDelegateKeys fmt dir index = do | ||
liftIO $ createDirectoryIfMissing False dir | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much more understandable 👍🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does total supply indicate total maximum possible supply?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Humm not sure what you mean.
totalSupply
indicates the entire amount of currency in the testnet being created IIUC.