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: Make --stake-delegators write credentials to disk. Keep current behavior with new --transient-stake-delegators. #512

Merged
merged 3 commits into from
Dec 13, 2023

Conversation

smelc
Copy link
Contributor

@smelc smelc commented Dec 8, 2023

Changelog

- description: |
    create-testnet-data: rename --stake-delegators to --transient-stake-delegators

    Introduce --stake-delegators, that generates delegators, but write credentials to disk.
# 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

How to trust this PR

  • Look at how delegations is computed in the new OnDisk case. Squint really hard.

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

@smelc smelc changed the title Make --stake-delegators write credentials to disk. Keep current behavior --transient-stake-delegators Make --stake-delegators write credentials to disk. Keep current behavior with new --transient-stake-delegators. Dec 8, 2023
@smelc smelc mentioned this pull request Dec 8, 2023
6 tasks
@smelc smelc force-pushed the smelc/create-testnet-data-improvements branch from 173f335 to 44a808b Compare December 11, 2023 09:33
Base automatically changed from smelc/create-testnet-data-improvements to main December 11, 2023 10:10
@smelc smelc force-pushed the smelc/create-testnet-data-write-stake-delegators-to-disk branch 2 times, most recently from 7130444 to 2a61253 Compare December 11, 2023 19:33
@smelc smelc marked this pull request as ready for review December 11, 2023 19:48
@smelc smelc force-pushed the smelc/create-testnet-data-write-stake-delegators-to-disk branch from 2a61253 to 628a6e7 Compare December 12, 2023 09:01
@smelc smelc changed the title Make --stake-delegators write credentials to disk. Keep current behavior with new --transient-stake-delegators. create-testnet-data: Make --stake-delegators write credentials to disk. Keep current behavior with new --transient-stake-delegators. Dec 12, 2023
OnDisk -> do
let delegates = concat $ repeat stakeDelegatorsDirs
delegatesAndPools = zip delegates distribution
-- We don't need to be attentive to laziness here, because anyway this
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the context for this comment here?

Copy link
Contributor

Choose a reason for hiding this comment

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

The benchmarking team asked us to stop writing credentials to disk (they were generating massive numbers of keys and I believe it was slowing down their tests). In the case where we want to write keys to disk we basically accept that if we are using large numbers of keys there will be a performance degradation.

Copy link
Contributor

@carlhammann carlhammann left a comment

Choose a reason for hiding this comment

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

I left a few nitpicky comments. Otherwise, LGTM 🎉!

cardano-cli/src/Cardano/CLI/EraBased/Options/Genesis.hs Outdated Show resolved Hide resolved
Comment on lines +295 to +298
-- | The output format used all along this file
desiredKeyOutputFormat :: KeyOutputFormat
desiredKeyOutputFormat = KeyOutputFormatTextEnvelope
Copy link
Contributor

Choose a reason for hiding this comment

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

In the best of all possible worlds, this should be a field of the GenesisCreateTestnetDataCmdArgs, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but I've decided to leave it as future work, until this is requested 👍

Comment on lines 503 to 506
payVK <- firstExceptT GenesisCmdFileInputDecodeError
$ newExceptT $ Keys.readVerificationKeyOrFile AsPaymentKey (VerificationKeyFilePath payVKF)
stakeVK <- firstExceptT GenesisCmdFileInputDecodeError
Copy link
Contributor

Choose a reason for hiding this comment

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

can be joined in a single ExceptT

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went for some code sharing instead, to make this more digestible:

-    payVK <- firstExceptT GenesisCmdFileInputDecodeError
-                  $ newExceptT $ Keys.readVerificationKeyOrFile AsPaymentKey (VerificationKeyFilePath payVKF)
-    stakeVK <- firstExceptT GenesisCmdFileInputDecodeError
-                  $ newExceptT $ Keys.readVerificationKeyOrFile AsStakeKey (VerificationKeyFilePath stakeVKF)
+    payVK   <- readVKeyFromDisk AsPaymentKey payVKF
+    stakeVK <- readVKeyFromDisk AsStakeKey   stakeVKF
     let paymentCredential = PaymentCredentialByKey $ verificationKeyHash payVK
         stakeAddrRef = StakeAddressByValue $ StakeCredentialByKey $ verificationKeyHash stakeVK
         dInitialUtxoAddr = makeShelleyAddressInEra ShelleyBasedEraShelley nw paymentCredential stakeAddrRef
@@ -514,6 +512,9 @@ computeDelegation nw delegDir dPoolParams = do
    where
      payVKF = File @(VerificationKey ()) $ delegDir </> "payment.vkey"
      stakeVKF = File @(VerificationKey ()) $ delegDir </> "staking.vkey"
+     readVKeyFromDisk role file =
+      firstExceptT GenesisCmdFileInputDecodeError $ newExceptT $
+        Keys.readVerificationKeyOrFile role (VerificationKeyFilePath file)

@Jimbo4350 Jimbo4350 self-requested a review December 12, 2023 12:18
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.

Looks good but a couple comments

cardano-cli/src/Cardano/CLI/EraBased/Commands/Genesis.hs Outdated Show resolved Hide resolved
OnDisk -> do
let delegates = concat $ repeat stakeDelegatorsDirs
delegatesAndPools = zip delegates distribution
-- We don't need to be attentive to laziness here, because anyway this
Copy link
Contributor

Choose a reason for hiding this comment

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

The benchmarking team asked us to stop writing credentials to disk (they were generating massive numbers of keys and I believe it was slowing down their tests). In the case where we want to write keys to disk we basically accept that if we are using large numbers of keys there will be a performance degradation.

@smelc smelc force-pushed the smelc/create-testnet-data-write-stake-delegators-to-disk branch from 628a6e7 to a4a8fc7 Compare December 12, 2023 13:57
@Jimbo4350 Jimbo4350 dismissed their stale review December 12, 2023 15:04

No need to block this PR

@smelc smelc force-pushed the smelc/create-testnet-data-write-stake-delegators-to-disk branch from a4a8fc7 to a5d8ae8 Compare December 12, 2023 15:50
cardano-cli/src/Cardano/CLI/Types/Common.hs Outdated Show resolved Hide resolved
@smelc smelc force-pushed the smelc/create-testnet-data-write-stake-delegators-to-disk branch from a5d8ae8 to 31c3e6d Compare December 13, 2023 10:44
@smelc smelc enabled auto-merge December 13, 2023 10:44
@smelc smelc added this pull request to the merge queue Dec 13, 2023
Merged via the queue into main with commit 8a0c9f7 Dec 13, 2023
19 checks passed
@smelc smelc deleted the smelc/create-testnet-data-write-stake-delegators-to-disk branch December 13, 2023 11:49
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.

5 participants