-
Notifications
You must be signed in to change notification settings - Fork 721
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
Conversation
5607eb8
to
68e2c8b
Compare
shelleyKeyGen command subCommand tmpDir keyNames = | ||
GHC.withFrozenCallStack $ do | ||
let | ||
vKeyPath = tmpDir </> verificationKeyFile keyNames |
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.
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"
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.
Nice catch! How did you find this?
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.
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} |
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.
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.
01370d3
to
cd71efa
Compare
aed1a8a
to
105d6ff
Compare
cardano-testnet/src/Testnet/Types.hs
Outdated
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.
Changes:
- Moved all types from
Testnet.Runtime
- Removed redundant key pair types
- Added
KeyPair
,VKey
,SKey
, moveSomeKeyPair
- updated
configurationFile
type inTestnetRuntime
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.
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. |
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.
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. |
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.
👍
shelleyKeyGen command subCommand tmpDir keyNames = | ||
GHC.withFrozenCallStack $ do | ||
let | ||
vKeyPath = tmpDir </> verificationKeyFile keyNames |
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.
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 |
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.
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
105d6ff
to
c7e7545
Compare
@@ -1,28 +1,25 @@ | |||
{-# LANGUAGE DataKinds #-} | |||
{-# LANGUAGE RankNTypes #-} |
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.
Could have removed RankNTypes
here
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.
Removed in #5821
Description
This PR looks big but it's mostly code style changes and wrapping and unwrapping from
File
. The list of changes:KeyPair
, replace with parameterized typeKeyPair k
NodeConfigFile In
andSocketPath
for node config file, and socket path respectively. Reduces required wrapping inFile
on usage sites.Testnet.Types
Testnet.Process.Cli
where we were abusing</>
in building paths.Checklist
See Runnings tests for more details
CHANGELOG.md
for affected package.cabal
files are updatedhlint
. See.github/workflows/check-hlint.yml
to get thehlint
versionstylish-haskell
. See.github/workflows/stylish-haskell.yml
to get thestylish-haskell
versionghc-8.10.7
andghc-9.2.7
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.