Skip to content

Remove ProtocolParametersUpdate#1103

Open
Jimbo4350 wants to merge 3 commits intomasterfrom
jordan/remove-ProtocolParametersUpdate
Open

Remove ProtocolParametersUpdate#1103
Jimbo4350 wants to merge 3 commits intomasterfrom
jordan/remove-ProtocolParametersUpdate

Conversation

@Jimbo4350
Copy link
Copy Markdown
Contributor

@Jimbo4350 Jimbo4350 commented Feb 6, 2026

Changelog

- description: |
    Remove deprecated `ProtocolParametersUpdate` type and associated conversion functions
    (`toLedgerUpdate`, `toLedgerProposedPPUpdates`, `fromLedgerProposedPPUpdates`,
    `toLedgerPParamsUpdate`, `fromLedgerPParamsUpdate`).
    Remove `makeShelleyTransactionBody` and accompanying internal functions.
  type:
    - breaking
    - refactoring
  projects:
    - cardano-api

Context

Removes deprecated code that has been superseded by era-based protocol parameter updates. This cleans up ProtocolParameters.hs and Tx.Internal.Body significantly (~1000 lines removed).

How to trust this PR

Straightforward removal of deprecated, unused code. Build passes cleanly.

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated
  • Self-reviewed the diff

@@ -0,0 +1,71 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE EmptyCase #-}

Check warning

Code scanning / HLint

Unused LANGUAGE pragma Warning generated

cardano-api/gen/Test/Gen/Cardano/Api/Internal/Shared.hs:2:1-26: Warning: Unused LANGUAGE pragma
  
Found:
  {-# LANGUAGE EmptyCase #-}
  
Perhaps you should remove it.
{-# LANGUAGE EmptyCase #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE NamedFieldPuns #-}

Check warning

Code scanning / HLint

Unused LANGUAGE pragma Warning generated

cardano-api/gen/Test/Gen/Cardano/Api/Internal/Shared.hs:5:1-31: Warning: Unused LANGUAGE pragma
  
Found:
  {-# LANGUAGE NamedFieldPuns #-}
  
Perhaps you should remove it.
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}

Check warning

Code scanning / HLint

Unused LANGUAGE pragma Warning generated

cardano-api/gen/Test/Gen/Cardano/Api/Internal/Shared.hs:6:1-34: Warning: Unused LANGUAGE pragma
  
Found:
  {-# LANGUAGE OverloadedStrings #-}
  
Perhaps you should remove it.
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}

Check warning

Code scanning / HLint

Unused LANGUAGE pragma Warning generated

cardano-api/gen/Test/Gen/Cardano/Api/Internal/Shared.hs:8:1-32: Warning: Unused LANGUAGE pragma
  
Found:
  {-# LANGUAGE RecordWildCards #-}
  
Perhaps you should remove it.
  
Note: may require {-# LANGUAGE DisambiguateRecordFields #-} adding to the top of the file
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

Check warning

Code scanning / HLint

Unused LANGUAGE pragma Warning generated

cardano-api/gen/Test/Gen/Cardano/Api/Internal/Shared.hs:10:1-30: Warning: Unused LANGUAGE pragma
  
Found:
  {-# LANGUAGE TupleSections #-}
  
Perhaps you should remove it.
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeApplications #-}

Check warning

Code scanning / HLint

Unused LANGUAGE pragma Warning generated

cardano-api/gen/Test/Gen/Cardano/Api/Internal/Shared.hs:11:1-33: Warning: Unused LANGUAGE pragma
  
Found:
  {-# LANGUAGE TypeApplications #-}
  
Perhaps you should remove it.
@Jimbo4350 Jimbo4350 force-pushed the jordan/remove-ProtocolParametersUpdate branch 2 times, most recently from 0d214de to 3686dc7 Compare February 12, 2026 12:15
@Jimbo4350 Jimbo4350 force-pushed the jordan/remove-ProtocolParametersUpdate branch from 3686dc7 to 0cb8e81 Compare March 12, 2026 14:41
@Jimbo4350
Copy link
Copy Markdown
Contributor Author

⚠️ Do not merge until node version 11 is released.

@Jimbo4350 Jimbo4350 force-pushed the jordan/remove-ProtocolParametersUpdate branch 4 times, most recently from 8056c64 to 48922cd Compare March 24, 2026 17:50
@Jimbo4350 Jimbo4350 force-pushed the jordan/remove-ProtocolParametersUpdate branch from 48922cd to 28f167f Compare April 7, 2026 16:20
@Jimbo4350 Jimbo4350 force-pushed the jordan/remove-ProtocolParametersUpdate branch from 28f167f to 5529e54 Compare April 21, 2026 17:08
Jimbo4350 added 2 commits May 1, 2026 12:13
- Remove UpdateProposal CBOR roundtrip test since EraBasedProtocolParametersUpdate
  has stub ToCBOR/FromCBOR instances
- Set cost models to SNothing in genAlonzoOnwardsPParams since cost models
  don't survive CBOR roundtrip (matching the old generator behaviour)
- Fix unused import in Shared.hs
@Jimbo4350 Jimbo4350 force-pushed the jordan/remove-ProtocolParametersUpdate branch from 5529e54 to 51b9c73 Compare May 1, 2026 16:26
@Jimbo4350 Jimbo4350 marked this pull request as ready for review May 1, 2026 16:57
@Jimbo4350 Jimbo4350 requested a review from erikd as a code owner May 1, 2026 16:57
Copilot AI review requested due to automatic review settings May 1, 2026 16:57
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Removes the deprecated ProtocolParametersUpdate API and related conversion code, shifting update proposals to use era-based protocol parameter updates and simplifying transaction-body construction.

Changes:

  • Deletes deprecated ProtocolParametersUpdate type and large blocks of legacy conversion logic.
  • Refactors UpdateProposal to be era-parameterized and updates transaction update-proposal plumbing.
  • Reorganizes generators by extracting shared helpers into a new internal test module.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
cardano-api/test/cardano-api-test/Test/Cardano/Api/CBOR.hs Removes CBOR roundtrip property for UpdateProposal.
cardano-api/src/Cardano/Api/Tx/Internal/Body.hs Updates TxUpdateProposal to carry UpdateProposal era; adds ledger conversion helpers.
cardano-api/src/Cardano/Api/ProtocolParameters.hs Removes deprecated type; reworks update proposals to use EraBasedProtocolParametersUpdate; adds new “from ledger” mapping helpers.
cardano-api/src/Cardano/Api/Compatible/Tx.hs Adjusts compatible tx creation to use pure toLedgerUpdate.
cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs Moves shared generator utilities out; re-exports genTxUpdateProposal from new module.
cardano-api/gen/Test/Gen/Cardano/Api/ProtocolParameters.hs Adds generators for era-based protocol parameter updates and update proposals.
cardano-api/gen/Test/Gen/Cardano/Api/Internal/Shared.hs New shared generator helpers (keys, epoch, seeds, cost models).
cardano-api/cardano-api.cabal Registers the new generator module.
.changes/20260501_cardano_api_remove_ProtocolParametersUpdate.yml Adds changelog entry for the breaking removal.

Comment on lines +218 to +222
instance Typeable era => ToCBOR (EraBasedProtocolParametersUpdate era) where
toCBOR = error "toCBOR not implemented for EraBasedProtocolParametersUpdate"

instance Typeable era => FromCBOR (EraBasedProtocolParametersUpdate era) where
fromCBOR = error "fromCBOR not implemented for EraBasedProtocolParametersUpdate"
Copy link

Copilot AI May 1, 2026

Choose a reason for hiding this comment

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

These instances will crash at runtime for any CBOR serialization/deserialization of EraBasedProtocolParametersUpdate (and therefore UpdateProposal era, which encodes its map values via toCBOR). Either implement real CBOR encoding/decoding for EraBasedProtocolParametersUpdate (e.g., via a tagged union that roundtrips per-era payloads), or remove these instances and any public CBOR surface depending on them.

Suggested change
instance Typeable era => ToCBOR (EraBasedProtocolParametersUpdate era) where
toCBOR = error "toCBOR not implemented for EraBasedProtocolParametersUpdate"
instance Typeable era => FromCBOR (EraBasedProtocolParametersUpdate era) where
fromCBOR = error "fromCBOR not implemented for EraBasedProtocolParametersUpdate"
encodeEraBasedProtocolParametersUpdate :: EraBasedProtocolParametersUpdate era -> Encoding
encodeEraBasedProtocolParametersUpdate = \case
ShelleyEraBasedProtocolParametersUpdate common ->
encodeListLen 2
<> encodeWord 0
<> toCBOR common
AllegraEraBasedProtocolParametersUpdate common ->
encodeListLen 2
<> encodeWord 1
<> toCBOR common
MaryEraBasedProtocolParametersUpdate common ->
encodeListLen 2
<> encodeWord 2
<> toCBOR common
AlonzoEraBasedProtocolParametersUpdate common alonzo ->
encodeListLen 3
<> encodeWord 3
<> toCBOR common
<> toCBOR alonzo
BabbageEraBasedProtocolParametersUpdate common alonzo babbage ->
encodeListLen 4
<> encodeWord 4
<> toCBOR common
<> toCBOR alonzo
<> toCBOR babbage
ConwayEraBasedProtocolParametersUpdate common alonzo babbage conway ->
encodeListLen 5
<> encodeWord 5
<> toCBOR common
<> toCBOR alonzo
<> toCBOR babbage
<> toCBOR conway
decodeEraBasedProtocolParametersUpdate
:: Typeable era
=> Decoder s (EraBasedProtocolParametersUpdate era)
decodeEraBasedProtocolParametersUpdate = do
len <- decodeListLen
tag <- decodeWord
case (tag, len) of
(0, 2) ->
castDecoded
=<< (ShelleyEraBasedProtocolParametersUpdate <$> fromCBOR)
(1, 2) ->
castDecoded
=<< (AllegraEraBasedProtocolParametersUpdate <$> fromCBOR)
(2, 2) ->
castDecoded
=<< (MaryEraBasedProtocolParametersUpdate <$> fromCBOR)
(3, 3) ->
castDecoded
=<< (AlonzoEraBasedProtocolParametersUpdate <$> fromCBOR <*> fromCBOR)
(4, 4) ->
castDecoded
=<< (BabbageEraBasedProtocolParametersUpdate <$> fromCBOR <*> fromCBOR <*> fromCBOR)
(5, 5) ->
castDecoded
=<< (ConwayEraBasedProtocolParametersUpdate <$> fromCBOR <*> fromCBOR <*> fromCBOR <*> fromCBOR)
_ ->
fail $
"Invalid CBOR for EraBasedProtocolParametersUpdate: unexpected tag/length combination "
++ show (tag, len)
where
castDecoded
:: (Typeable era', Typeable era)
=> EraBasedProtocolParametersUpdate era'
-> Decoder s (EraBasedProtocolParametersUpdate era)
castDecoded decoded =
case cast decoded of
Just decoded' -> pure decoded'
Nothing ->
fail "CBOR era tag does not match requested EraBasedProtocolParametersUpdate era"
instance Typeable era => ToCBOR (EraBasedProtocolParametersUpdate era) where
toCBOR = encodeEraBasedProtocolParametersUpdate
instance Typeable era => FromCBOR (EraBasedProtocolParametersUpdate era) where
fromCBOR = decodeEraBasedProtocolParametersUpdate

Copilot uses AI. Check for mistakes.
instance FromCBOR UpdateProposal where
instance Typeable era => FromCBOR (UpdateProposal era) where
fromCBOR = do
CBOR.enforceSize "ProtocolParametersUpdate" 2
Copy link

Copilot AI May 1, 2026

Choose a reason for hiding this comment

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

The CBOR decoder uses CBOR.enforceSize \"ProtocolParametersUpdate\" 2, which is misleading for failures when decoding an UpdateProposal. Update the label string to match the actual type being decoded (e.g., \"UpdateProposal\") to make decode errors actionable.

Suggested change
CBOR.enforceSize "ProtocolParametersUpdate" 2
CBOR.enforceSize "UpdateProposal" 2

Copilot uses AI. Check for mistakes.
<$> fromCBOR
<*> fromCBOR

-- TODO: LLeft off here. You need to implement the relevant FromCBOR instance
Copy link

Copilot AI May 1, 2026

Choose a reason for hiding this comment

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

Correct typo in comment: 'LLeft' should be 'Left'.

Suggested change
-- TODO: LLeft off here. You need to implement the relevant FromCBOR instance
-- TODO: Left off here. You need to implement the relevant FromCBOR instance

Copilot uses AI. Check for mistakes.
Comment on lines +988 to +989
ShelleyBasedEraDijkstra ->
error "Dijkstra era should never be used with fromLedgerPParamsUpdate"
Copy link

Copilot AI May 1, 2026

Choose a reason for hiding this comment

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

This introduces a runtime crash path in production code. Prefer making the impossible case unrepresentable (e.g., adjust the function’s input type/constraints so Dijkstra cannot be passed), or return a structured error instead of calling error.

Copilot uses AI. Check for mistakes.
Comment on lines +105 to +117
:: MonadGen m
=> CardanoEra era
-> m (EraBasedProtocolParametersUpdate era)
genEraBasedProtocolParametersUpdate era =
case era of
ByronEra -> error ""
ShelleyEra -> genShelleyEraBasedProtocolParametersUpdate
AllegraEra -> genAllegraEraBasedProtocolParametersUpdate
MaryEra -> genMaryEraBasedProtocolParametersUpdate
AlonzoEra -> genAlonzoEraBasedProtocolParametersUpdate
BabbageEra -> genBabbageEraBasedProtocolParametersUpdate
ConwayEra -> genConwayEraBasedProtocolParametersUpdate
DijkstraEra -> error "Dijkstra era should never be used with genEraBasedProtocolParametersUpdate"
Copy link

Copilot AI May 1, 2026

Choose a reason for hiding this comment

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

Using error \"\" in a generator makes failures opaque and can crash test runs if this branch becomes reachable. Consider either (a) changing the function signature to only accept eras where updates are valid (e.g., Shelley-based eras), or (b) using a generator-level failure/discard with a clear message (Gen.discard or fail with context) instead of error.

Suggested change
:: MonadGen m
=> CardanoEra era
-> m (EraBasedProtocolParametersUpdate era)
genEraBasedProtocolParametersUpdate era =
case era of
ByronEra -> error ""
ShelleyEra -> genShelleyEraBasedProtocolParametersUpdate
AllegraEra -> genAllegraEraBasedProtocolParametersUpdate
MaryEra -> genMaryEraBasedProtocolParametersUpdate
AlonzoEra -> genAlonzoEraBasedProtocolParametersUpdate
BabbageEra -> genBabbageEraBasedProtocolParametersUpdate
ConwayEra -> genConwayEraBasedProtocolParametersUpdate
DijkstraEra -> error "Dijkstra era should never be used with genEraBasedProtocolParametersUpdate"
:: (MonadGen m, MonadFail m)
=> CardanoEra era
-> m (EraBasedProtocolParametersUpdate era)
genEraBasedProtocolParametersUpdate era =
case era of
ByronEra -> fail "genEraBasedProtocolParametersUpdate: ByronEra does not support protocol parameter updates"
ShelleyEra -> genShelleyEraBasedProtocolParametersUpdate
AllegraEra -> genAllegraEraBasedProtocolParametersUpdate
MaryEra -> genMaryEraBasedProtocolParametersUpdate
AlonzoEra -> genAlonzoEraBasedProtocolParametersUpdate
BabbageEra -> genBabbageEraBasedProtocolParametersUpdate
ConwayEra -> genConwayEraBasedProtocolParametersUpdate
DijkstraEra -> fail "genEraBasedProtocolParametersUpdate: DijkstraEra should never be used"

Copilot uses AI. Check for mistakes.
Comment on lines 205 to +208
, mkCommonTxBody
, toAuxiliaryData
, toByronTxId
, toLedgerUpdate
Copy link

Copilot AI May 1, 2026

Choose a reason for hiding this comment

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

The PR description and changelog state that toLedgerUpdate (and related conversion functions) are removed, but this PR adds/export toLedgerUpdate from Tx.Internal.Body. If the intent is to fully remove this conversion API, consider keeping it unexported/internal (or renaming/scoping it to avoid reintroducing the removed surface). Otherwise, update the PR description/changelog to reflect that the conversion still exists (albeit relocated).

Copilot uses AI. Check for mistakes.
@@ -387,12 +387,6 @@ prop_roundtrip_ScriptData_CBOR = H.property $ do
x <- H.forAll genHashableScriptData
H.trippingCbor AsHashableScriptData x

Copy link

Copilot AI May 1, 2026

Choose a reason for hiding this comment

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

The UpdateProposal CBOR roundtrip property was removed. Given UpdateProposal era still has CBOR instances and the PR changes their representation, add/restore a CBOR roundtrip property for the new era-parameterized UpdateProposal (and/or for EraBasedProtocolParametersUpdate) once the CBOR instances are implemented, to prevent regressions like runtime error implementations slipping through.

Suggested change
prop_roundtrip_UpdateProposal_CBOR :: Property
prop_roundtrip_UpdateProposal_CBOR = H.property $ do
AnyShelleyBasedEra era <- H.noteShowM . H.forAll $ Gen.element [minBound .. maxBound]
x <- forAll $ genUpdateProposal era
shelleyBasedEraConstraints era $
H.trippingCbor (proxyToAsType (getProxy x)) x
where
getProxy :: forall a. a -> Proxy a
getProxy _ = Proxy

Copilot uses AI. Check for mistakes.
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