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

Refactor: Use KeyPair type for key pairs in cardano-testnet #5829

Merged
merged 1 commit into from
May 9, 2024

Conversation

carbolymer
Copy link
Contributor

@carbolymer carbolymer commented May 7, 2024

Description

This PR looks big but it's mostly code style changes and wrapping and unwrapping from File. The list of changes:

  1. Remove multiple redundant key types, class KeyPair, replace with parameterized type KeyPair k
  2. Use NodeConfigFile In and SocketPath for node config file, and socket path respectively. Reduces required wrapping in File on usage sites.
  3. Moved out testnet runtime related types to Testnet.Types
  4. Fix functions in Testnet.Process.Cli where we were abusing </> in building paths.

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated. These may include:
    • golden tests
    • property tests
    • roundtrip tests
    • integration tests
      See Runnings tests for more details
  • Any changes are noted in the CHANGELOG.md for affected package
  • The version bounds in .cabal files are updated
  • CI passes. See note on CI. The following CI checks are required:
    • Code is linted with hlint. See .github/workflows/check-hlint.yml to get the hlint version
    • Code is formatted with stylish-haskell. See .github/workflows/stylish-haskell.yml to get the stylish-haskell version
    • Code builds on Linux, MacOS and Windows for ghc-8.10.7 and ghc-9.2.7
  • Self-reviewed the diff

Note on CI

If your PR is from a fork, the necessary CI jobs won't trigger automatically for security reasons.
You will need to get someone with write privileges. Please contact IOG node developers to do this
for you.

@carbolymer carbolymer force-pushed the mgalazyn/refactor/use-keypairs-in-testnet branch 2 times, most recently from 5607eb8 to 68e2c8b Compare May 7, 2024 16:42
shelleyKeyGen command subCommand tmpDir keyNames =
GHC.withFrozenCallStack $ do
let
vKeyPath = tmpDir </> verificationKeyFile keyNames
Copy link
Contributor Author

@carbolymer carbolymer May 7, 2024

Choose a reason for hiding this comment

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

This was very misleading. We were only calling this function with an absolute paths in keyNames which resulted in tmpDir being completely ignored. That's a property of </>:

"some/leading/path" </> "/absolutepath.txt" == "/absolutepath.txt"

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice catch! How did you find this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some time ago when I was refactoring path building in testnet, I was quite surprised with the results.

@@ -151,17 +117,8 @@ data ByronDelegationCert

type TmpDir = FilePath

newtype File a = File {unFile :: FilePath}
Copy link
Contributor Author

@carbolymer carbolymer May 7, 2024

Choose a reason for hiding this comment

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

This name is confusing, as we're using API's File more frequently in testnet. I've opted to remove this type and to use API one.

@carbolymer carbolymer force-pushed the mgalazyn/refactor/use-keypairs-in-testnet branch 2 times, most recently from 01370d3 to cd71efa Compare May 7, 2024 17:53
@carbolymer carbolymer marked this pull request as ready for review May 7, 2024 17:55
@carbolymer carbolymer requested a review from a team as a code owner May 7, 2024 17:55
@carbolymer carbolymer force-pushed the mgalazyn/refactor/use-keypairs-in-testnet branch 3 times, most recently from aed1a8a to 105d6ff Compare May 8, 2024 10:39
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changes:

  • Moved all types from Testnet.Runtime
  • Removed redundant key pair types
  • Added KeyPair, VKey, SKey, move SomeKeyPair
  • updated configurationFile type in TestnetRuntime

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.

Nice work 👍. A few minor comments.

=> H.ExecConfig -- ^ Specifies the CLI execution configuration.
-> AnyCardanoEra -- ^ Specifies the current Cardano era.
-> FilePath -- ^ Base directory path where the signed transaction file will be stored.
-> String -- ^ Prefix for the output signed transaction file name. The extension will be @.tx@.
-> File TxBody In -- ^ Transaction body to be signed, obtained using 'createCertificatePublicationTxBody' or similar.
-> [k] -- ^ List of payment key pairs used for signing the transaction.
-> [SomeKeyPair] -- ^ List of payment key pairs used for signing the transaction.
Copy link
Contributor

Choose a reason for hiding this comment

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

The comment needs to be modified to show that we can sign with other keys (e.g stake keys)

-> ShelleyBasedEra ConwayEra -- ^ The Shelley-based era (e.g., 'ConwayEra') in which the transaction will be constructed.
-> FilePath -- ^ Base directory path where generated files will be stored.
-> String -- ^ Name for the subfolder that will be created under 'work' folder.
-> PaymentKeyInfo -- ^ Wallet that will pay for the transaction.
-> StakingKeyPair -- ^ Staking key pair used for delegation.
-> PaymentKeyPair -- ^ Delegate Representative (DRep) key pair ('PaymentKeyPair') to which delegate.
-> KeyPair StakingKey -- ^ Staking key pair used for delegation.
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

shelleyKeyGen command subCommand tmpDir keyNames =
GHC.withFrozenCallStack $ do
let
vKeyPath = tmpDir </> verificationKeyFile keyNames
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice catch! How did you find this?

Map.foldlWithKey' (compareWithTxId txid) Nothing (L.proposalsActionsMap proposals)
Nothing -> do
error $ "Eras mismatch! expected: " <> show sbe <> ", actual: " <> show actualEra
maybeExtractGovernanceActionIndex ceo txid (AnyNewEpochState actualEra newEpochState) = conwayEraOnwardsConstraints ceo $ do
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactoring suggestion:

maybeExtractGovernanceActionIndex
  :: HasCallStack
  => TxId -- ^ transaction id searched for
  -> AnyNewEpochState
  -> Maybe Word32
maybeExtractGovernanceActionIndex txid (AnyNewEpochState sbe newEpochState) =
  caseShelleyToBabbageOrConwayEraOnwards
    (const $ error "Governance actions only available in Conway era onwards")
    (\ceo -> conwayEraOnwardsConstraints ceo $ do
        let proposals = newEpochState ^. L.newEpochStateGovStateL . L.proposalsGovStateL
        Map.foldlWithKey' (compareWithTxId txid) Nothing (L.proposalsActionsMap proposals)
    )
    sbe
  where
   compareWithTxId (TxId ti1) Nothing (GovActionId (L.TxId ti2) (L.GovActionIx gai)) _
     | ti1 == L.extractHash ti2 = Just gai
   compareWithTxId _ x _ _ = x

@carbolymer carbolymer force-pushed the mgalazyn/refactor/use-keypairs-in-testnet branch from 105d6ff to c7e7545 Compare May 9, 2024 14:03
@carbolymer carbolymer enabled auto-merge May 9, 2024 14:03
@carbolymer carbolymer added this pull request to the merge queue May 9, 2024
Merged via the queue into master with commit b8c8695 May 9, 2024
22 checks passed
@carbolymer carbolymer deleted the mgalazyn/refactor/use-keypairs-in-testnet branch May 9, 2024 15:50
@@ -1,28 +1,25 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE RankNTypes #-}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could have removed RankNTypes here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed in #5821

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.

None yet

2 participants