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

Add Inject instances for Eons. Deprecate old eons conversion functions. #636

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

carbolymer
Copy link
Contributor

@carbolymer carbolymer commented Sep 13, 2024

Changelog

- description: |
    Deprecate eons conversion functions like `conwayEraOnwardsToBabbageEraOnwards`. Add [`Inject`](https://cardano-ledger.cardano.intersectmbo.org/cardano-ledger-core/Cardano-Ledger-BaseTypes.html#t:Inject) instances for eon conversions. See the PR description for migration aid.
# 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
   - refactoring    # QoL changes
  # - 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

Use Inject for eons conversion instead of specialised and hard to remember functions.

You can migrate your codebase using this snippet:

find . -type f -name "*.hs" -exec sed -i \
  -e 's/allegraEraOnwardsToShelleyBasedEra/inject/g' \
  -e 's/alonzoEraOnwardsToShelleyBasedEra/inject/g' \
  -e 's/babbageEraOnwardsToShelleyBasedEra/inject/g' \
  -e 's/conwayEraOnwardsToShelleyBasedEra/inject/g' \
  -e 's/conwayEraOnwardsToBabbageEraOnwards/inject/g' \
  -e 's/maryEraOnwardsToShelleyBasedEra/inject/g' \
  -e 's/shelleyEraOnlyToShelleyBasedEra/inject/g' \
  -e 's/shelleyToAllegraEraToShelleyBasedEra/inject/g' \
  -e 's/shelleyToBabbageEraToShelleyBasedEra/inject/g' \
  -e 's/shelleyToMaryEraToShelleyBasedEra/inject/g' \
  -e 's/babbageEraOnwardsToEra/inject/g' \
  -e 's/eraToBabbageEraOnwards/inject/g' {} +

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 force-pushed the mgalazyn/refactor/add-inject-instances branch 3 times, most recently from 4af9910 to c2dee39 Compare September 13, 2024 08:08
Copy link
Contributor

@smelc smelc left a comment

Choose a reason for hiding this comment

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

Nice QoL change 👍

genValueForMinting w =
fromLedgerValue sbe <$> genValue w genAssetIdNoAda genSignedNonZeroQuantity
where
sbe = maryEraOnwardsToShelleyBasedEra w
sbe = inject w :: ShelleyBasedEra era
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
sbe = inject w :: ShelleyBasedEra era
sbe :: ShelleyBasedEra era = inject w

Rationale: It's more common to have the type attached to the variable

@@ -274,7 +275,7 @@ queryStakeDelegDeposits
queryStakeDelegDeposits era stakeCreds
| S.null stakeCreds = pure . pure $ pure mempty
| otherwise = do
let sbe = babbageEraOnwardsToShelleyBasedEra era
let sbe = inject era :: ShelleyBasedEra era
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let sbe = inject era :: ShelleyBasedEra era
let sbe :: ShelleyBasedEra era = inject era

@@ -398,12 +399,12 @@ queryDRepState
(Either EraMismatch (Map (L.Credential L.DRepRole L.StandardCrypto) (L.DRepState L.StandardCrypto)))
)
queryDRepState era drepCreds = do
let sbe = conwayEraOnwardsToShelleyBasedEra era
let sbe = inject era :: ShelleyBasedEra era
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let sbe = inject era :: ShelleyBasedEra era
let sbe :: ShelleyBasedEra era = inject era

@@ -472,12 +473,12 @@ queryStakeVoteDelegatees
(Either EraMismatch (Map StakeCredential (L.DRep L.StandardCrypto)))
)
queryStakeVoteDelegatees era stakeCredentials = do
let sbe = conwayEraOnwardsToShelleyBasedEra era
let sbe = inject era :: ShelleyBasedEra era
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let sbe = inject era :: ShelleyBasedEra era
let sbe :: ShelleyBasedEra era = inject era

@@ -2049,12 +2048,11 @@ fromAlonzoTxOut w txOut =
(fromAlonzoTxOutDatumHash w (txOut ^. L.dataHashTxOutL))
ReferenceScriptNone
where
sbe = alonzoEraOnwardsToShelleyBasedEra w
sbe = inject w :: ShelleyBasedEra era
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
sbe = inject w :: ShelleyBasedEra era
sbe :: ShelleyBasedEra era = inject w

@@ -2069,7 +2067,7 @@ fromBabbageTxOut w txdatums txout =
SJust rScript -> fromShelleyScriptToReferenceScript shelleyBasedEra rScript
)
where
sbe = babbageEraOnwardsToShelleyBasedEra w
sbe = inject w :: ShelleyBasedEra era
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
sbe = inject w :: ShelleyBasedEra era
sbe :: ShelleyBasedEra era = inject w

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.

We are adding an additional step to the deprecation of these era conversion functions where what we should be doing is figuring out how to change the interface then deprecating and eventually remove the functions. Creating Inject instances for them seems to be an additional unnecessary step.

@carbolymer
Copy link
Contributor Author

carbolymer commented Sep 16, 2024

@Jimbo4350 the goal of this PR is to make the codebase more pleasant to work with until we get rid of Eons. There's still significant amount of work left to do, before we arrive there.

I disagree that it adds an additional step in deprecation, I see Inject as a general purpose tool for total conversions from one to the another type. Those Inject instances would be gone together with Eons as well.

If you think this PR is changing too much, what do you think of just using inject in the glue code for experimental API. I mean the changes in cardano-api/internal/Cardano/Api/Experimental/Eras.hs ?

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