Add experimental `AnyNewEpochState` parameterised on `Era` to eliminate partial `sbeToEra` conversions
Maintainers usually reply within 2 days
@carbolymer is already working on this.
Since Apr 27, 2026.
Assessment
This issue has not been assessed yet.
Description
Problem
AnyNewEpochState in Cardano.Api.LedgerState carries a ShelleyBasedEra era witness:
data AnyNewEpochState where
AnyNewEpochState
:: ShelleyBasedEra era
-> ShelleyAPI.NewEpochState (ShelleyLedgerEra era)
-> Ledger.LedgerTables ...
-> AnyNewEpochState
Consumers in cardano-testnet that need EraCommonConstraints (via obtainCommonConstraints) must first convert ShelleyBasedEra era to Exp.Era era using sbeToEra. Because Exp.Era only inhabits Conway and Dijkstra, sbeToEra is partial for pre-Conway eras, forcing every call site to use a helper like:
unsafeEraFromSbe :: HasCallStack => ShelleyBasedEra era -> Era era
unsafeEraFromSbe = withFrozenCallStack $
either (error . prettyShow . prettyError) id . sbeToEra
This appears in EpochStateProcessing.hs and is used across multiple modules (Components/Query.hs, Runtime.hs, Process/Cli/SPO.hs). Every pattern match on AnyNewEpochState in testnet code repeats the same partial conversion.
See cardano-node PR #6551 for context and the review discussion that motivated this issue.
Constraint
foldEpochState replays the chain from genesis via a pipelined chain-sync client. The callback receives blocks from all eras (Shelley through Dijkstra), so the existing AnyNewEpochState with ShelleyBasedEra must remain available for consumers that need full-era coverage (e.g. cardano-cli debug log-epoch-state).
Proposal
Add a new existential type in Cardano.Api.Experimental that carries an Era era witness instead of ShelleyBasedEra era:
-- | Like 'AnyNewEpochState' but restricted to experimental (Conway+) eras,
-- so that 'obtainCommonConstraints' is always total.
data AnyNewEpochState where
AnyNewEpochState
:: Era era
-> ShelleyAPI.NewEpochState (ShelleyLedgerEra era)
-> Ledger.LedgerTables ...
-> AnyNewEpochState
Optionally, provide one or both of:
- A conversion function from the legacy type to
Maybethe experimental type (fails for pre-Conway eras). - A wrapper around
foldEpochStatethat silently skips pre-Conway blocks and delivers onlyExp.AnyNewEpochStateto the callback, for consumers that only care about Conway+ governance state.
Migration path
- cardano-testnet: switch to the experimental
AnyNewEpochState. AllunsafeEraFromSbecalls and the helper itself can be removed;obtainCommonConstraintsworks directly on theErawitness. - cardano-cli (
debug log-epoch-state): continues using the legacyAnyNewEpochStatewithShelleyBasedEra, unaffected by this change.
Alternatives considered
- Make
sbeToEratotal: not possible without adding pre-Conway constructors toEra, which defeats the purpose of the experimental API. - Keep the status quo: every new testnet module repeats the same partial conversion boilerplate, and
errorcalls in test infrastructure are fragile.
- Dominant language
- Haskell
- Stars
- 41
- Forks
- 33
- Avg merge
- 3d 3h
- Merged PRs (30d)
- 15
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from IntersectMBO/cardano-api
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
IntersectMBO/cardano-api#1434 ·
Maintainers usually reply within 2 days
-
`Prelude.maximum: empty list` crash in fee estimation for empty `RequireAnyOf` (`{"type": "any", "scripts": []}`) scriptsPossibly taken @Jimbo4350 claimed this 8 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
IntersectMBO/cardano-api#1424 ·
Maintainers usually reply within 2 days
-
Difficulty 4/5 3-5 days Newbie friendliness 53/100
IntersectMBO/cardano-api#1431 ·
Maintainers usually reply within 2 days
-
type: enhancement
Difficulty 4/5 3-5 days Newbie friendliness 45/100
IntersectMBO/cardano-api#1423 ·
Maintainers usually reply within 2 days
-
Add a dedicated transaction viewing type to the experimental APIPossibly taken @palas claimed this 21 days ago. Opentype: enhancement
IntersectMBO/cardano-api#1416 · 1 assignee ·
Maintainers usually reply within 2 days
All issues in IntersectMBO/cardano-api
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
haskell/bytestring#730 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
seal-harness/seal-harness#399 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
fmidue/codeworld-tasks#124 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
reflex-frp/reflex#563 ·