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 cost models file to protocol parameter update command #405

Merged
merged 5 commits into from
Nov 23, 2023

Conversation

carlhammann
Copy link
Contributor

@carlhammann carlhammann commented Oct 26, 2023

Changelog

- description: |
    Add cost models file to the protocol parameter update commands
# 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
  # - improvement    # QoL changes e.g. refactoring
  # - 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

This PR closes #386, by adding a --new-cost-model-file to the cardano-cli * governance action create-protocol-parameters-update and the cardano-cli [legacy] governance create-update-proposal commands. The option only appears from Alonzo era onwards.

I also disambiguated the flags of these commands, because there was a collision:--governance-action-deposit is required for every governance action, and thus the name of the flag to specify a proposed change in that parameter has to have a different name. I chose let all flags for proposed changes have the format --new-*.

There is a test that the proposal is generated correctly in Conway era. I couldn't find a valid PlutusV3 cost model to add to my tests, though. So, the test currently only covers PlutusV1 and PlutusV2. @CarlosLopezDeLara do you know where I could find such a thing? I couldn't find a valid Plutus V3 cost model anywhere. There's no PlutusV3 cost model in the book, and the one in the one here (which @CarlosLopezDeLara pointed me to) doesn't deserialise. So, I built my own V3 cost model to use as input for the tests: I had a look here to find the right ordering of the parameters and then just set each of them to 1.

How to trust this PR

I realise this is a big diff, so I'll leave some pointers in separate comments below.

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

Comment on lines +106 to +115
-- | New parameters to be proposed. From Alonzo onwards, the type
-- 'EraBasedProtocolParametersUpdate' also contains cost models. Since all
-- other protocol parameters are read from command line arguments, whereas
-- the cost models are read from a file, we separate the cost models from
-- the rest of the protocol parameters to ease parsing.
, uppNewPParams :: !(EraBasedProtocolParametersUpdate era)
-- | The new cost models proposed. See the comment at 'uppNewPParams' for
-- why this is a separate field.
, uppCostModelsFile :: !(Maybe (CostModelsFile era))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the core of the PR: I'm adding a separate field for the cost models. Notice that CostmodelsFile contains an AlonzoEraOnwards witness.

Comment on lines 212 to 216
pCostModelsFile :: ShelleyBasedEra era -> Parser (Maybe (Cmd.CostModelsFile era))
pCostModelsFile =
caseShelleyToMaryOrAlonzoEraOnwards
(const $ pure Nothing)
(\alonzoOnwards -> fmap (fmap $ Cmd.CostModelsFile alonzoOnwards . File) . optional $ pCostModels (Just "new"))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the era-sensitive parser for the cost models file. Compare the golden files for the help texts of Alonzo and Mary, say.

Copy link
Contributor

@carbolymer carbolymer left a comment

Choose a reason for hiding this comment

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

I'm not so sure about prefixes to the CLI parameters - I'm leaving the final approval to the others. Otherwise, LGTM, good work!

@carlhammann carlhammann changed the title Ch/update costmodels Add cost models file to protocol parameter update command Nov 1, 2023
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.

A couple of comments

cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs Outdated Show resolved Hide resolved
@@ -302,6 +320,26 @@ runGovernanceActionCreateProtocolParametersUpdateCmd eraBasedPParams' = do
)
sbe

addCostModelsToEraBasedProtocolParametersUpdate
Copy link
Contributor

Choose a reason for hiding this comment

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

We should write a round trip property test for this.

@carlhammann carlhammann force-pushed the ch/update-costmodels branch 2 times, most recently from 4a81c6c to 2e034e9 Compare November 2, 2023 14:47
@carlhammann carlhammann force-pushed the ch/update-costmodels branch 5 times, most recently from bf5523f to 038547c Compare November 20, 2023 11:38
@carlhammann
Copy link
Contributor Author

With #463 merged, we can now use the generators from cardano-api in the roundtrip property test. I think this is now ready.

@carlhammann carlhammann requested review from a team as code owners November 21, 2023 10:08
"blake2b_224-cpu-arguments-slope": 1,
"blake2b_224-memory-arguments": 1
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Where did this file come from?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made it, because I couldn't find a valid Plutus V3 cost model anywhere. There's no valid PlutusV3 cost model in the book, and the one in the one here (which @CarlosLopezDeLara pointed me to) doesn't deserialise. So I had a look here to find the right ordering of the parameters and then just set each of them to 1.

For sure, this is sub-optimal.

Copy link
Contributor

@Jimbo4350 Jimbo4350 Nov 22, 2023

Choose a reason for hiding this comment

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

@newhoggy newhoggy self-requested a review November 21, 2023 10:35
@carlhammann carlhammann dismissed Jimbo4350’s stale review November 21, 2023 11:03

The requested property tests are now implemented

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.

Nice work 👍. This one looked a little finicky 😁.

"blake2b_224-cpu-arguments-slope": 1,
"blake2b_224-memory-arguments": 1
}
}
Copy link
Contributor

@Jimbo4350 Jimbo4350 Nov 22, 2023

Choose a reason for hiding this comment

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

@carlhammann carlhammann added this pull request to the merge queue Nov 23, 2023
Merged via the queue into main with commit cead75f Nov 23, 2023
19 checks passed
@carlhammann carlhammann deleted the ch/update-costmodels branch November 23, 2023 16:30
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.

Fix action create-protocol-parameters-update to take plutusV1, plutusV2 cost models
5 participants