-
Notifications
You must be signed in to change notification settings - Fork 16
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
create-protocol-parameters-update: validate cost models' size #1012
base: master
Are you sure you want to change the base?
Conversation
Just (model :: L.CostModel) -> do | ||
let actual = Map.size (L.costModelToMap model) | ||
expected = languageToParameterCount lang | ||
unless (expected == actual) $ throwE $ CostModelsErrorWrongSize expected actual | ||
return () |
Check warning
Code scanning / HLint
Redundant return Warning
Found:
do let actual = Map.size (L.costModelToMap model)
expected = languageToParameterCount lang
unless (expected == actual)
$ throwE $ CostModelsErrorWrongSize expected actual
return ()
Perhaps:
do let actual = Map.size (L.costModelToMap model)
expected = languageToParameterCount lang
unless (expected == actual)
$ throwE $ CostModelsErrorWrongSize expected actual
hprop_golden_conway_governance_action_create_protocol_parameters_bad_costmodel_size = | ||
propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do | ||
-- This file has 184 entries, whereas PV1 requires 166 | ||
-- TODO @smelc this test does not pass: the command succeeds, whereas it should fail! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My guess is that for PV1 the ledger deserialization fixes the problem by filling in missing parameters. Investigating. (this could also be an issue if the ledger is automatically trimming extra parameters, I need to check that too).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's something along those lines. The defaulting logic may also change depending whether the cost model is an array or a map. 🫠
ledger is automatically trimming extra parameters
I think it is not, we're only doing trimming in alonzo genesis reading, because the node didn't want to start in some cases.
L.PlutusV2 -> | ||
let nbParamNames = length $ allValues @PlutusV2.ParamName in -- 185 | ||
caseShelleyToBabbageOrConwayEraOnwards | ||
(const $ nbParamNames - 10) -- Ten parameters were added to V2 in Conway, need to remove them here |
There was a problem hiding this 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 hardcoding that number 10. We should account for the fact that the number of params can change in the future, however it's unlikely. That's why there's jumping over many hoops in Cardano.Api.Genesis
and Test.Cardano.Api.Genesis
, so we will get a clear signal when things unexpectedly change.
return costModels | ||
where | ||
checkCostModelSize :: L.CostModels -> L.Language -> ExceptT CostModelsError IO () | ||
checkCostModelSize models lang = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think those checks should be in cardano-api
so we can reuse them in decoding genesis as well, because genesis can contain PV2 and PV3 models. This is used only in starting testnets afaik.
hprop_golden_conway_governance_action_create_protocol_parameters_bad_costmodel_size = | ||
propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do | ||
-- This file has 184 entries, whereas PV1 requires 166 | ||
-- TODO @smelc this test does not pass: the command succeeds, whereas it should fail! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's something along those lines. The defaulting logic may also change depending whether the cost model is an array or a map. 🫠
ledger is automatically trimming extra parameters
I think it is not, we're only doing trimming in alonzo genesis reading, because the node didn't want to start in some cases.
languageToParameterCount = \case | ||
L.PlutusV1 -> length $ allValues @PlutusV1.ParamName -- 166 | ||
L.PlutusV2 -> | ||
let nbParamNames = length $ allValues @PlutusV2.ParamName in -- 185 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let nbParamNames = length $ allValues @PlutusV2.ParamName in -- 185 | |
let nParamNames = length $ allValues @PlutusV2.ParamName in -- 185 |
😄
ad333c5
to
20fee47
Compare
20fee47
to
a2ce41c
Compare
Changelog
Context
Fixes #928
How to trust this PR
Checklist