Skip to content

Conversation

@Lucsanszky
Copy link
Contributor

@Lucsanszky Lucsanszky commented Oct 29, 2025

Description

Resolves #5342

Checklist

  • Commits in meaningful sequence and with useful messages.
  • Tests added or updated when needed.
  • CHANGELOG.md files updated for packages with externally visible changes.
    NOTE: New section is never added with the code changes. (See RELEASING.md).
  • Versions updated in .cabal and CHANGELOG.md files when necessary, according to the
    versioning process.
  • Version bounds in .cabal files updated when necessary.
    NOTE: If bounds change in a cabal file, that package itself must have a version increase. (See RELEASING.md).
  • Code formatted (use scripts/fourmolize.sh).
  • Cabal files formatted (use scripts/cabal-format.sh).
  • CDDL files are up to date (use scripts/gen-cddl.sh)
  • hie.yaml updated (use scripts/gen-hie.sh).
  • Self-reviewed the diff.

@Lucsanszky Lucsanszky force-pushed the ldan/alonzogen-cm-injection branch 5 times, most recently from 31af8b6 to 262c0b3 Compare October 30, 2025 22:22
@Lucsanszky Lucsanszky force-pushed the ldan/alonzogen-cm-injection branch 2 times, most recently from d9f0fd1 to 91bd434 Compare November 10, 2025 15:15
@Lucsanszky Lucsanszky force-pushed the ldan/alonzogen-cm-injection branch 4 times, most recently from 412397f to 6f33fbc Compare November 12, 2025 14:07
@Lucsanszky Lucsanszky marked this pull request as ready for review November 12, 2025 14:07
@Lucsanszky Lucsanszky requested a review from a team as a code owner November 12, 2025 14:07
Copy link
Collaborator

@lehins lehins left a comment

Choose a reason for hiding this comment

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

This is close to what we need, but with current PR extraConfig is completely unused. In other words, it is not enough to add a field to the Genesis file, we need to get it to inject into the ledger state. For this you need to modify this function that will take this cost models from extra config and inject it into the ledger state, potentially overriding a PlutusV1 cost model if one is also supplied through "extraConfig": https://github.com/IntersectMBO/cardano-ledger/blob/d120d9613810c0dc9e22fe2d1c104d8240aeb163/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Transition.hs#L30C3-L30C22

So, this function should be used for injecting, so that only the supplied cost models gets overridden:

-- | Updates the first @`CostModels`@ with the second one, so that only the cost models
-- that are present in the second one get updated while all the others stay
-- unchanged. Language specific errors and unknown cost models are removed, whenever a
-- valid `CostModel` for the language is supplied in the update.
updateCostModels ::
-- | Old CostModels that will be overwritten
CostModels ->
-- | New CostModels that will overwrite
CostModels ->
CostModels
updateCostModels (CostModels oldValid oldUnk) (CostModels modValid modUnk) =

One last thing, but extremely important one, we are not allowed to change Genesis files after the era has been hard forked into.

@Lucsanszky Lucsanszky force-pushed the ldan/alonzogen-cm-injection branch 4 times, most recently from bd913d7 to e419167 Compare November 18, 2025 15:03
Copy link
Contributor Author

@Lucsanszky Lucsanszky left a comment

Choose a reason for hiding this comment

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

I addressed the suggestions, so it is now actually overriding the cost models by using updateCostModels in Alonzo injectIntoTestState and also keeps the JSON and binary representations intact while making the Haskell representation more restrictive (only PlutusV1 cost models are allowed outside the extra config). Hope this is more inline with what we need!

@Lucsanszky Lucsanszky requested a review from lehins November 18, 2025 20:08
@Lucsanszky Lucsanszky force-pushed the ldan/alonzogen-cm-injection branch from e419167 to b081d49 Compare November 19, 2025 09:39
@lehins lehins force-pushed the ldan/alonzogen-cm-injection branch from b081d49 to 1cf7578 Compare November 20, 2025 01:48
Copy link
Collaborator

@lehins lehins left a comment

Choose a reason for hiding this comment

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

Looks good. Some changes are still needed though.

@Lucsanszky Lucsanszky force-pushed the ldan/alonzogen-cm-injection branch from 3ce4054 to c6148bc Compare November 24, 2025 16:28
Copy link
Collaborator

@lehins lehins left a comment

Choose a reason for hiding this comment

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

Perfect! Thank you!

Only allow `PlutusV1` when parsing cost models in `AlonzoGenesis`
and `UpgradeAlonzoPParams`.
* Override cost models when injecting into test state (if extra config
cost models are provided)
* Preserve `AlonzoGenesis` JSON and binary representations but change
the Haskell side representation
@Lucsanszky Lucsanszky force-pushed the ldan/alonzogen-cm-injection branch from 41ce2a0 to 3e1ff5f Compare November 25, 2025 14:00
@Lucsanszky Lucsanszky enabled auto-merge November 25, 2025 14:03
@Lucsanszky Lucsanszky merged commit c041632 into master Nov 25, 2025
120 of 122 checks passed
@Lucsanszky Lucsanszky deleted the ldan/alonzogen-cm-injection branch November 25, 2025 15:53
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.

Ability to inject any CostModel through AlonzoGenesis

3 participants