IntersectMBO / cardano-cli

This repository contains sources for the command-line interface (CLI) tool for interacting with the Cardano blockchain.
Apache License 2.0
39 stars 14 forks source link

create-testnet-data: wrong supply/total-supply interaction #631

Closed smelc closed 6 months ago

smelc commented 6 months ago

From @mgmeier here on Slack:

In Cardano.CLI.EraBased.Run.CreateTestnetData.updateOutputTemplate:

delegCoinRaw, nonDelegCoinRaw :: Integer
delegCoinRaw = case mDelegatedSupply of Nothing -> 0; Just (Lovelace amountDeleg) -> totalSupply - amountDeleg
nonDelegCoinRaw = totalSupply - delegCoinRaw

this seems to be doing the wrong thing. I.e., subtracting the amountDeleg from the total supply does not give you the delegated coin, rather the non-delegated coin. So I suspect, the values might end up being reversed here.

Comparing with the behaviour of create-staked:

Cardano.CLI.EraBased.Run.CreateTestnetData.updateOutputTemplate: maximumLovelaceSupply :: Word64 maximumLovelaceSupply = sgMaxLovelaceSupply template

totalSupply :: Integral a => a
-- if --total-supply is not specified, supply comes from the template passed to this function:
totalSupply = fromIntegral $ maybe maximumLovelaceSupply unLovelace mTotalSupply

Cardano.CLI.EraBased.Run.Genesis.updateOutputTemplate:

maximumLovelaceSupply :: Word64
maximumLovelaceSupply = sgMaxLovelaceSupply template

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)

This seems be incosistent wrt. the template field sgMaxLovelaceSupply. In 1., it serves as base for the total supply - in 2., as base for the nonDelegCoin. Isn't the template field semantics (e.g. from genesis.spec.json) meant to be consistent across commands - namely create-staked and create-testnet-data?

smelc commented 6 months ago

Another weirdness was reported (here on Slack): https://github.com/IntersectMBO/cardano-node/pull/5639/files#r1512199219

smelc commented 6 months ago

This seems be incosistent wrt. the template field sgMaxLovelaceSupply. In 1., it serves as base for the total supply - in 2., as base for the nonDelegCoin. Isn't the template field semantics (e.g. from genesis.spec.json) meant to be consistent across commands - namely create-staked and create-testnet-data?

@mgmeier> we checked with the ledger team (here on Slack) that it's the semantics of create-testnet-data that is correct: sgMaxLovelaceSupply is the total coin supply, not the non-delegated coins. create-staked was doing it incorrectly, so you will need to adapt when/if changing from create-staked to create-testnet-data.