Skip to content

Remove the era case combinators in favour of inEonForEra - #1326

Merged
Jimbo4350 merged 5 commits into
masterfrom
jordan/remove-case-shelley-era-only-or-allegra-era-onwards
Sep 4, 2026
Merged

Remove the era case combinators in favour of inEonForEra#1326
Jimbo4350 merged 5 commits into
masterfrom
jordan/remove-case-shelley-era-only-or-allegra-era-onwards

Conversation

@Jimbo4350

@Jimbo4350 Jimbo4350 commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Context

Removes all three era case combinators and the Cardano.Api.Era.Internal.Case module they lived in. Call sites use inEonForEra / inEonForShelleyBasedEra, or match on the era constructors where both branches need era constraints.

  • caseShelleyEraOnlyOrAllegraEraOnwards — internal only, never re-exported. Two of three call sites ignored the ShelleyEraOnly witness; the third, invalidHereAfterTxBodyL, needs it for ttlAsInvalidHereAfterTxBodyL and now matches on constructors.
  • caseByronOrShelleyBasedEra — no call sites left, and its own comment marked it for deletion once build-raw --byron-era was deprecated in cardano-cli. The Cardano.Api.Network.IPC haddock example now shows inEonForEra instead.
  • caseShelleyToBabbageOrConwayEraOnwards — 16 of 19 call sites ignored one of the two witnesses. In toConsensusQueryShelleyBased the eon is the experimental Era, which is what obtainCommonConstraints wants, so 11 convert calls go away too. The last three are certificate generators in Test.Gen.Cardano.Api.Typed needing ShelleyEraTxCert pre-Conway and ConwayEraTxCert after; they match on constructors.

Note that inEonForShelleyBasedEra hands the callback a witness but no constraints, unlike the case combinators' rank-2 arguments — so a few sites now call shelleyToBabbageEraConstraints / obtainCommonConstraints explicitly.

Downstream: cardano-cli has 5 uses of caseShelleyToBabbageOrConwayEraOnwards (Compatible/Transaction/Run.hs, Compatible/Transaction/Option.hs, Compatible/Governance/Option.hs) that will need the same treatment. All but pRefScriptFp discard a witness, so they map straight onto inEonForShelleyBasedEra.

How to trust this PR

No behaviour change: each branch of the removed combinators maps one-to-one onto the new code, and the era partitions are unchanged.

cabal build all -j4 --enable-tests
cabal test cardano-api-test cardano-api-golden -j4

Locally: clean build under -Werror, 259/259 and 125/125 tests pass. cardano-rpc-test fails to build on master already (Not in scope: T.show, Test/Cardano/Rpc/Pagination.hs:89) — untouched here.

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
  • Changelog fragment added in .changes/

Copilot AI lite review requested due to automatic review settings September 3, 2026 15:28
@Jimbo4350
Jimbo4350 force-pushed the jordan/remove-case-shelley-era-only-or-allegra-era-onwards branch from 32a8d98 to 80f0897 Compare September 3, 2026 15:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The refactor cleanly removes an internal-only combinator, updates all call sites, and preserves the Shelley vs. Allegra-onwards partitioning without introducing API or behavioral changes.

Pull request overview

This PR refactors internal era-case handling by removing the internal caseShelleyEraOnlyOrAllegraEraOnwards combinator from Cardano.Api.Era.Internal.Case and rewriting its former call sites to use inEonForShelleyBasedEra (when no Shelley witness is needed) or direct ShelleyBasedEra constructor matching (when a Shelley witness is required). This keeps behavior the same while reducing bespoke combinators and simplifying call-site intent.

Changes:

  • Removed caseShelleyEraOnlyOrAllegraEraOnwards from Cardano.Api.Era.Internal.Case.
  • Updated fromLedgerTxValidityLowerBound and fromLedgerTxAuxiliaryData to use inEonForShelleyBasedEra with a Shelley default value.
  • Reworked invalidHereAfterTxBodyL to match directly on ShelleyBasedEra constructors, using a local AllegraEraOnwards helper to avoid repeating the Allegra-onwards lens chain.
File summaries
File Description
cardano-api/src/Cardano/Api/Tx/Internal/Body/Lens.hs Replaces the removed combinator usage with explicit ShelleyBasedEra matching and a local helper for the Allegra-onwards lens path.
cardano-api/src/Cardano/Api/Tx/Internal/Body.hs Switches two call sites to inEonForShelleyBasedEra to select a Shelley default vs. Allegra-onwards witness-based logic.
cardano-api/src/Cardano/Api/Era/Internal/Case.hs Removes the internal caseShelleyEraOnlyOrAllegraEraOnwards function and its exports/imports.
.changes/remove-case-shelley-era-only-or-allegra-era-onwards.yml Adds a refactoring changelog fragment describing the internal removal and call-site rewrites.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@Jimbo4350
Jimbo4350 force-pushed the jordan/remove-case-shelley-era-only-or-allegra-era-onwards branch from 80f0897 to ac923b4 Compare September 3, 2026 15:39
@Jimbo4350 Jimbo4350 changed the title Remove caseShelleyEraOnlyOrAllegraEraOnwards Remove caseShelleyEraOnlyOrAllegraEraOnwards and caseByronOrShelleyBasedEra Sep 3, 2026
@Jimbo4350
Jimbo4350 force-pushed the jordan/remove-case-shelley-era-only-or-allegra-era-onwards branch from ac923b4 to 6eb957a Compare September 3, 2026 15:50
@Jimbo4350 Jimbo4350 changed the title Remove caseShelleyEraOnlyOrAllegraEraOnwards and caseByronOrShelleyBasedEra Simplify era case handling in favour of inEonForShelleyBasedEra Sep 3, 2026
@Jimbo4350
Jimbo4350 force-pushed the jordan/remove-case-shelley-era-only-or-allegra-era-onwards branch from 6eb957a to b1c2cf1 Compare September 3, 2026 15:58
@Jimbo4350 Jimbo4350 changed the title Simplify era case handling in favour of inEonForShelleyBasedEra Remove the era case combinators in favour of inEonForEra Sep 3, 2026
@Jimbo4350
Jimbo4350 force-pushed the jordan/remove-case-shelley-era-only-or-allegra-era-onwards branch from b1c2cf1 to 9316e8a Compare September 3, 2026 18:15

@palas palas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All good except for the shrinking Era issue

)
( \w ->
obtainCommonConstraints (convert w) $
obtainCommonConstraints w $

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same problem as here in all this file:

Because of the use of inEonForShelleyBasedEra, when Conway goes out of Era, then it will lose the conway related commands (like drep), and we won't get any compilation error that warns about it here.
So maybe we should do something like postConway below.

@Jimbo4350
Jimbo4350 force-pushed the jordan/remove-case-shelley-era-only-or-allegra-era-onwards branch 3 times, most recently from 12f2690 to 26fadf5 Compare September 4, 2026 15:21
Two of the three call sites discarded the `ShelleyEraOnly` witness
entirely, so they are expressed directly with `inEonForShelleyBasedEra`
and an `AllegraEraOnwards` default.

`invalidHereAfterTxBodyL` needs the `ShelleyEraOnly` witness in the
Shelley branch to reach `ttlAsInvalidHereAfterTxBodyL`, which
`inEonForShelleyBasedEra` cannot supply, so it now matches on the
`ShelleyBasedEra` constructors directly.
It had no call sites left, and its own comment marked it for deletion
once `build-raw --byron-era` was deprecated in cardano-cli. Callers
needing the same split can use `inEonForEra` with `ShelleyBasedEra`,
which is what the `Cardano.Api.Network.IPC` haddock example now shows.
…wards

Sixteen of the nineteen call sites ignored one of the two witnesses, so
they are expressed with `inEonForShelleyBasedEra` and a default for the
eras outside the eon.

Unlike the case combinator, `inEonForShelleyBasedEra` hands the callback
a witness but no constraints, so `maybeFromLedgerTxUpdateProposal` now
calls `shelleyToBabbageEraConstraints` itself.

In `toConsensusQueryShelleyBased` the eleven Conway-onwards queries go
through a local `conwayOnwards` witness which matches on
`ShelleyBasedEra` exhaustively instead of using an eon, so adding or
retiring an era is a compile error at that match rather than a silent
fall through to the unsupported branch. The witness is
`ConwayEraOnwards` and the constraints come from
`conwayEraOnwardsConstraints`, so these queries no longer depend on the
experimental `Era`, whose constructors only cover the currently
supported eras.

`nextEpochEligibleLeadershipSlots` needs a visible type application
because neither branch mentions the witness.
The three remaining call sites are certificate generators whose
pre-Conway branch needs `ShelleyEraTxCert` and whose Conway branch needs
`ConwayEraTxCert`. `inEonForShelleyBasedEra` supplies a witness but no
constraints, and its default argument has no witness at all, so these
match on the `ShelleyBasedEra` constructors and obtain the constraints
from the witness in each branch.

That empties `Cardano.Api.Era.Internal.Case`, so the module goes too.
@Jimbo4350
Jimbo4350 force-pushed the jordan/remove-case-shelley-era-only-or-allegra-era-onwards branch from 26fadf5 to df6b4ac Compare September 4, 2026 17:13
@Jimbo4350
Jimbo4350 added this pull request to the merge queue Sep 4, 2026
Merged via the queue into master with commit 3419989 Sep 4, 2026
31 checks passed
@Jimbo4350
Jimbo4350 deleted the jordan/remove-case-shelley-era-only-or-allegra-era-onwards branch September 4, 2026 19:27
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