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: fix computation of not-delegated amount #638

Merged
merged 5 commits into from
Mar 8, 2024

Conversation

smelc
Copy link
Contributor

@smelc smelc commented Mar 7, 2024

Changelog

- description: |
    create-testnet-data: fixes that amount of delegated coins was incorrect
# uncomment types applicable to the change:
  type:
  # - feature        # introduces a new feature
  - breaking       # the API has changed in a breaking way
  # - compatible     # the API has changed but is non-breaking
  # - optimisation   # measurable performance improvements
  # - improvement    # QoL changes e.g. refactoring
  - bugfix         # fixes a defect
  # - test           # fixes/modifies tests
  # - maintenance    # not directly related to the code
  # - release        # related to a new release preparation
  # - documentation  # change in code docs, haddocks...

Context

Fixes #631

How to trust this PR

  1. Run the new test (cabal test cardano-cli-golden --test-options '-p "/golden create testnet data deleg non deleg/"') before the fix, witness the test fails
  2. Run the test on the head of this PR. Enjoy the passing test.
  3. Tested on cardano-node locally
  4. Tested CI on cardano-node: Test of https://github.com/IntersectMBO/cardano-cli/pull/638, DO NOT MERGE cardano-node#5712

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated. See Running tests for more details
  • Self-reviewed the diff

Comment on lines 158 to 159
bs <- liftIO $ LBS.readFile $ outputDir </> "genesis.json"
genesis :: ShelleyGenesis StandardCrypto <- Aeson.throwDecode bs
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done and learnt about readJsonFileOk 👍

@@ -622,7 +621,8 @@ updateOutputTemplate
totalSupply = fromIntegral $ maybe maximumLovelaceSupply unLovelace mTotalSupply

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

Choose a reason for hiding this comment

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

👍🏻

let L.Coin onlyHolderCoin = snd $ initialFunds !! 0

-- The check below may seem weird, but we cannot do a very precise check
-- on balances, because of the treasury "stealing" some of the money.
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you mean by that? I thought that treasury starts empty, and gets filled with time from reserves.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

-- of --total-supply above.
-- https://github.com/IntersectMBO/cardano-cli/issues/631

H.assert $ fromIntegral onlyHolderCoin > totalSupply `div` 2
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you replace it with assertWith? assertWith logs the value on failure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 👍 Thanks, I didn't know about assertWith 🙏

@smelc smelc force-pushed the smelc/fix-deleg-non-deleg-confusion branch 2 times, most recently from c710969 to 7890add Compare March 8, 2024 13:14
@smelc smelc force-pushed the smelc/fix-deleg-non-deleg-confusion branch from 7890add to 7efe1ee Compare March 8, 2024 13:16
@smelc smelc added this pull request to the merge queue Mar 8, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 8, 2024
@smelc smelc added this pull request to the merge queue Mar 8, 2024
Merged via the queue into main with commit eafcf17 Mar 8, 2024
19 checks passed
@smelc smelc deleted the smelc/fix-deleg-non-deleg-confusion branch March 8, 2024 19:39
Copy link
Contributor

@Jimbo4350 Jimbo4350 left a comment

Choose a reason for hiding this comment

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

👍

propertyOnce $ moduleWorkspace "tmp" $ \tempDir -> do

let outputDir = tempDir </> "out"
totalSupply :: Int = 2000000000000 -- 2*10^12
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to start using NumericUnderscores more

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually we do now for this file on main 🎉


let initialFunds = ListMap.toList $ L.sgInitialFunds genesis

(length initialFunds) H.=== 1
Copy link
Contributor

Choose a reason for hiding this comment

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

Some commentary would be useful here. Eg "This checks that there is actually only one funded address"
We can also introduce a variable e.g let fundedAddresses = 1 to make this even more clear.

-- The check below may seem weird, but we cannot do a very precise check
-- on balances, because of the treasury "stealing" some of the money.
-- Nevertheless, this check catches a confusion between delegated and
-- non-delegated coins, by virtue of --delegated-supply being a fourth
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment needs to be updated as #631 is closed

@smelc smelc mentioned this pull request Mar 28, 2024
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

create-testnet-data: wrong supply/total-supply interaction
3 participants