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

Plutus cost model: validate sizes in genesis files #724

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

smelc
Copy link
Contributor

@smelc smelc commented Jan 14, 2025

Changelog

- description: |
    Plutus cost model: validate sizes in genesis files
# 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
  # - refactoring    # QoL changes
  # - 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

API part of IntersectMBO/cardano-cli#928

How to trust this PR

TBD

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

@smelc smelc force-pushed the smelc/validate-cost-models-upon-deserialization branch 2 times, most recently from e7abb54 to 82c6d28 Compare January 14, 2025 21:03
@smelc smelc force-pushed the smelc/validate-cost-models-upon-deserialization branch from 82c6d28 to 6632c4c Compare January 14, 2025 21:04
, protocolUpdateUTxOCostPerByte = Nothing
}
where
mCostModels :: Maybe (Plutus.CostModels)

Check warning

Code scanning / HLint

Redundant bracket Warning

cardano-api/internal/Cardano/Api/ProtocolParameters.hs:1478:24-42: Warning: Redundant bracket
  
Found:
  (Plutus.CostModels)
  
Perhaps:
  Plutus.CostModels
costModels :: Either
CostModelNotEnoughParametersError
(Maybe (Map AnyPlutusScriptVersion CostModel))
costModels = sequence $ fromAlonzoCostModels <$> mCostModels

Check warning

Code scanning / HLint

Use mapM Warning

cardano-api/internal/Cardano/Api/ProtocolParameters.hs:1484:16-62: Warning: Use mapM
  
Found:
  sequence $ fromAlonzoCostModels <$> mCostModels
  
Perhaps:
  mapM fromAlonzoCostModels mCostModels
(\(Ledger.ProtVer a b) -> (Ledger.getVersion a, b))
<$> strictMaybeToMaybe (ppu ^. ppuProtocolVersionL)
}
(fromAlonzoCommonPParamsUpdate ppu) <&> \ppu' ->

Check notice

Code scanning / HLint

Redundant bracket Note

cardano-api/internal/Cardano/Api/ProtocolParameters.hs:1491:3-37: Suggestion: Redundant bracket
  
Found:
  (fromAlonzoCommonPParamsUpdate ppu)
    <&>
      \\ ppu'
        -> ppu'
             {protocolUpdateProtocolVersion = (\\ (Ledger.ProtVer a b)
                                                 -> (Ledger.getVersion a, b))
                                                <$> strictMaybeToMaybe (ppu ^. ppuProtocolVersionL)}
  
Perhaps:
  fromAlonzoCommonPParamsUpdate ppu
    <&>
      \\ ppu'
        -> ppu'
             {protocolUpdateProtocolVersion = (\\ (Ledger.ProtVer a b)
                                                 -> (Ledger.getVersion a, b))
                                                <$> strictMaybeToMaybe (ppu ^. ppuProtocolVersionL)}
(fromAlonzoCommonPParamsUpdate ppu)
{ protocolUpdateUTxOCostPerByte = unCoinPerByte <$> strictMaybeToMaybe (ppu ^. ppuCoinsPerUTxOByteL)
}
(fromAlonzoCommonPParamsUpdate ppu) <&> \ppu' ->

Check notice

Code scanning / HLint

Redundant bracket Note

cardano-api/internal/Cardano/Api/ProtocolParameters.hs:1503:3-37: Suggestion: Redundant bracket
  
Found:
  (fromAlonzoCommonPParamsUpdate ppu)
    <&>
      \\ ppu'
        -> ppu'
             {protocolUpdateUTxOCostPerByte = unCoinPerByte
                                                <$> strictMaybeToMaybe (ppu ^. ppuCoinsPerUTxOByteL)}
  
Perhaps:
  fromAlonzoCommonPParamsUpdate ppu
    <&>
      \\ ppu'
        -> ppu'
             {protocolUpdateUTxOCostPerByte = unCoinPerByte
                                                <$> strictMaybeToMaybe (ppu ^. ppuCoinsPerUTxOByteL)}
(\(Ledger.ProtVer a b) -> (Ledger.getVersion a, b))
<$> strictMaybeToMaybe (ppu ^. ppuProtocolVersionL)
}
(fromBabbageCommonPParamsUpdate ppu) <&> \ppu' ->

Check notice

Code scanning / HLint

Redundant bracket Note

cardano-api/internal/Cardano/Api/ProtocolParameters.hs:1513:3-38: Suggestion: Redundant bracket
  
Found:
  (fromBabbageCommonPParamsUpdate ppu)
    <&>
      \\ ppu'
        -> ppu'
             {protocolUpdateProtocolVersion = (\\ (Ledger.ProtVer a b)
                                                 -> (Ledger.getVersion a, b))
                                                <$> strictMaybeToMaybe (ppu ^. ppuProtocolVersionL)}
  
Perhaps:
  fromBabbageCommonPParamsUpdate ppu
    <&>
      \\ ppu'
        -> ppu'
             {protocolUpdateProtocolVersion = (\\ (Ledger.ProtVer a b)
                                                 -> (Ledger.getVersion a, b))
                                                <$> strictMaybeToMaybe (ppu ^. ppuProtocolVersionL)}
(fromAlonzoPParams pp)
{ protocolParamUTxOCostPerByte = Just . unCoinPerWord $ pp ^. ppCoinsPerUTxOWordL
}
(fromAlonzoPParams pp) <&> \pp' ->

Check notice

Code scanning / HLint

Redundant bracket Note

cardano-api/internal/Cardano/Api/ProtocolParameters.hs:1801:3-24: Suggestion: Redundant bracket
  
Found:
  (fromAlonzoPParams pp)
    <&>
      \\ pp'
        -> pp'
             {protocolParamUTxOCostPerByte = Just . unCoinPerWord
                                               $ pp ^. ppCoinsPerUTxOWordL}
  
Perhaps:
  fromAlonzoPParams pp
    <&>
      \\ pp'
        -> pp'
             {protocolParamUTxOCostPerByte = Just . unCoinPerWord
                                               $ pp ^. ppCoinsPerUTxOWordL}
{ protocolParamUTxOCostPerByte = Just . unCoinPerByte $ pp ^. ppCoinsPerUTxOByteL
, protocolParamDecentralization = Nothing
}
(fromAlonzoPParams pp) <&> \pp' ->

Check notice

Code scanning / HLint

Redundant bracket Note

cardano-api/internal/Cardano/Api/ProtocolParameters.hs:1815:3-24: Suggestion: Redundant bracket
  
Found:
  (fromAlonzoPParams pp)
    <&>
      \\ pp'
        -> pp'
             {protocolParamUTxOCostPerByte = Just . unCoinPerByte
                                               $ pp ^. ppCoinsPerUTxOByteL,
              protocolParamDecentralization = Nothing}
  
Perhaps:
  fromAlonzoPParams pp
    <&>
      \\ pp'
        -> pp'
             {protocolParamUTxOCostPerByte = Just . unCoinPerByte
                                               $ pp ^. ppCoinsPerUTxOByteL,
              protocolParamDecentralization = Nothing}
@smelc smelc force-pushed the smelc/validate-cost-models-upon-deserialization branch from 3d6de33 to dc0d52b Compare January 15, 2025 16:06
@smelc smelc force-pushed the smelc/validate-cost-models-upon-deserialization branch from dc0d52b to bb8f66f Compare January 15, 2025 17:05
maybeFromLedgerTxUpdateProposal sbe body =
caseShelleyToBabbageOrConwayEraOnwards
( \w ->
case body ^. L.updateTxBodyL of
SNothing -> TxUpdateProposalNone
SJust p -> TxUpdateProposal w (fromLedgerUpdate sbe p)
SNothing -> pure TxUpdateProposalNone

Check notice

Code scanning / HLint

Redundant bracket Note

cardano-api/internal/Cardano/Api/Tx/Body.hs:2548:45-68: Suggestion: Redundant bracket
  
Found:
  TxUpdateProposal w <$> (fromLedgerUpdate sbe p)
  
Perhaps:
  TxUpdateProposal w <$> fromLedgerUpdate sbe p
@smelc smelc force-pushed the smelc/validate-cost-models-upon-deserialization branch from bb8f66f to 2a1154b Compare January 16, 2025 13:33
@@ -1051,6 +1054,40 @@ toAlonzoCostModel (CostModel m) l = first (PpceInvalidCostModel (CostModel m)) $
fromAlonzoCostModel :: Alonzo.CostModel -> CostModel
fromAlonzoCostModel m = CostModel $ Alonzo.getCostModelParams m

validateCostModelSize
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use validateCostModel?

@smelc smelc mentioned this pull request Jan 16, 2025
2 tasks
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.

2 participants