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

Remove uses of coerceKeyRole, use asWitness / fromWitness when key role conversion is required #341

Merged
merged 1 commit into from
Nov 2, 2023

Conversation

carbolymer
Copy link
Contributor

@carbolymer carbolymer commented Oct 25, 2023

Changelog

- description: |
    Remove uses of `coerceKeyRole`, use asWitness when key role conversion is required 
# 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

Reason for the change: https://github.com/input-output-hk/cardano-api/pull/268/files#r1337448193

How to trust this PR

Highlight important bits of the PR that will make the review faster. If there are commands the reviewer can run to observe the new behavior, describe them.

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

@carbolymer carbolymer marked this pull request as ready for review October 25, 2023 09:55
@carbolymer carbolymer requested a review from lehins October 25, 2023 10:05
@carbolymer carbolymer marked this pull request as draft October 25, 2023 14:37
@carbolymer carbolymer force-pushed the mgalazyn/fix/remove-keys-coercing branch from 5a21eaa to 2626cce Compare October 26, 2023 08:39
Just . Ledger.coerceKeyRole . Ledger.KeyHashObj $ Ledger.ppId poolParams
Ledger.RetirePoolTxCert poolId _ ->
Just . Ledger.coerceKeyRole $ Ledger.KeyHashObj poolId
Ledger.RegPoolTxCert _ -> Nothing -- StakePool should never be a credential
Copy link
Contributor Author

Choose a reason for hiding this comment

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

From what I understand, we can't use StakePool as credentials, hence it gets skipped here. https://input-output-rnd.slack.com/archives/G011N23CEAE/p1698229398676999?thread_ts=1698227871.191609&cid=G011N23CEAE

@carbolymer carbolymer force-pushed the mgalazyn/fix/remove-keys-coercing branch from 0ab6808 to 845ac2d Compare October 26, 2023 10:29
data Voter era
= VoterCommittee (VotingCredential era) -- ^ Constitutional committee
| VoterDRep (VotingCredential era) -- ^ Delegated representative
| VoterSpo (Hash StakePoolKey) -- ^ Stake pool operator
Copy link
Contributor Author

@carbolymer carbolymer Oct 26, 2023

Choose a reason for hiding this comment

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

Voter is isomorphic to ledger's Voter so we could use just a newtype wrapper here. This way we can remove manual CBOR instances and bunch of boilerplate.

I'm not sure about the last constructor. Do we need to use Hash type family in cardano-api?

= VoterCommittee (VotingCredential era) -- ^ Constitutional committee
| VoterDRep (VotingCredential era) -- ^ Delegated representative
| VoterSpo (Hash StakePoolKey) -- ^ Stake pool operator
newtype Voter era = Voter (Ledger.Voter (L.EraCrypto (ShelleyLedgerEra era)))
Copy link
Contributor Author

@carbolymer carbolymer Oct 26, 2023

Choose a reason for hiding this comment

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

TODO:

  • check how much this affects cardano-cli

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@carbolymer carbolymer marked this pull request as ready for review October 26, 2023 11:05
@carbolymer carbolymer changed the title Use ledger keys' roles casting with explicit whitelist, instead of coerceKeyRole Remove uses of coerceKeyRole, use asWitness / fromWitness when key role conversion is required Oct 26, 2023
@carbolymer carbolymer force-pushed the mgalazyn/fix/remove-keys-coercing branch 3 times, most recently from 04564ef to c6a6c7e Compare October 30, 2023 17:26
@carbolymer carbolymer requested a review from Jimbo4350 October 30, 2023 17:36
@carbolymer carbolymer force-pushed the mgalazyn/fix/remove-keys-coercing branch from c6a6c7e to f9071e5 Compare October 30, 2023 17:37
Just . Ledger.coerceKeyRole . Ledger.KeyHashObj $ Ledger.ppId poolParams
Ledger.RetirePoolTxCert poolId _ ->
Just . Ledger.coerceKeyRole $ Ledger.KeyHashObj poolId
-- StakePool is always controlled by key, i.e. it is never a script. In other words,
Copy link
Contributor

Choose a reason for hiding this comment

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

Just asked a question in #ledger as I don't know if there are plans to allow registering stake pools with scripts.

cardano-api/internal/Cardano/Api/Keys/Shelley.hs Outdated Show resolved Hide resolved
@carbolymer carbolymer force-pushed the mgalazyn/fix/remove-keys-coercing branch from f9071e5 to 1eef008 Compare November 2, 2023 10:13
@carbolymer carbolymer enabled auto-merge November 2, 2023 10:21
@carbolymer carbolymer added this pull request to the merge queue Nov 2, 2023
Merged via the queue into main with commit 56ac0fd Nov 2, 2023
17 of 20 checks passed
@carbolymer carbolymer deleted the mgalazyn/fix/remove-keys-coercing branch November 2, 2023 11:01
newhoggy pushed a commit that referenced this pull request Mar 11, 2024
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.

3 participants