Skip to content

Commit

Permalink
Integrate latest ledger, network, consensus
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucsanszky committed May 9, 2024
1 parent e90a14e commit 01b2b66
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 35 deletions.
56 changes: 55 additions & 1 deletion cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,66 @@ repository cardano-haskell-packages
-- you need to run if you change them
index-state:
, hackage.haskell.org 2024-03-18T13:14:14Z
, cardano-haskell-packages 2024-04-04T10:00:00Z
, cardano-haskell-packages 2024-05-08T00:00:00Z

packages:
cardano-api
cardano-api-gen

source-repository-package
type: git
location: https://github.com/IntersectMBO/cardano-ledger
tag: 15afd0483d81f281018cf7d42629ed561845bc86
--sha256: sha256-1YX3tq2+poqQULTccLh8oaKRWAlsaimtQVXDAmv1O+U=
subdir: eras/allegra/impl
eras/alonzo/impl
eras/alonzo/test-suite
eras/babbage/impl
eras/babbage/test-suite
eras/conway/impl
eras/conway/test-suite
eras/mary/impl
eras/shelley/impl
eras/shelley/test-suite
eras/shelley-ma/test-suite
libs/cardano-ledger-api
libs/cardano-ledger-core
libs/cardano-ledger-binary
libs/cardano-protocol-tpraos
libs/non-integral
libs/small-steps
libs/cardano-data
libs/set-algebra
libs/vector-map
eras/byron/chain/executable-spec
eras/byron/ledger/executable-spec
eras/byron/ledger/impl
eras/byron/ledger/impl/test
eras/byron/crypto
eras/byron/crypto/test

source-repository-package
type: git
location: https://github.com/IntersectMBO/ouroboros-network
tag: 821feaa29b9f82d1364345348b304484bc189283
--sha256: sha256-yQEj74pnTVJQeeHNRr5ejW1KSKp89OFbNROtOdthG/o=
subdir: ouroboros-network
ouroboros-network-api
ouroboros-network-framework
ouroboros-network-protocols

source-repository-package
type: git
location: https://github.com/IntersectMBO/ouroboros-consensus
tag: 3f873d650ce079796296ada20f117cf8f39e7462
--sha256: sha256-H+pxQgS4NKUQXb/TOX3r+K9fV6EW2ueAP9C80e83ir0=
subdir: ouroboros-consensus
ouroboros-consensus-cardano
ouroboros-consensus-protocol
ouroboros-consensus-diffusion
sop-extras
strict-sop-core

program-options
ghc-options: -Werror

Expand Down
13 changes: 7 additions & 6 deletions cardano-api/cardano-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ library internal
, cardano-crypto-class ^>= 2.1.2
, cardano-crypto-wrapper ^>= 1.5
, cardano-data >= 1.0
, cardano-ledger-alonzo >= 1.7.0
, cardano-ledger-alonzo >= 1.8.0
, cardano-ledger-allegra >= 1.3
, cardano-ledger-api ^>= 1.9
, cardano-ledger-babbage >= 1.6.0
Expand All @@ -183,6 +183,7 @@ library internal
, directory
, either
, errors
, FailT
, filepath
, formatting
, groups
Expand All @@ -194,17 +195,17 @@ library internal
, optparse-applicative-fork
, ouroboros-consensus ^>= 0.17
, ouroboros-consensus-cardano ^>= 0.15
, ouroboros-consensus-diffusion ^>= 0.13
, ouroboros-consensus-diffusion ^>= 0.15
, ouroboros-consensus-protocol ^>= 0.8
, ouroboros-network
, ouroboros-network-api ^>= 0.7
, ouroboros-network-framework
, ouroboros-network-protocols
, parsec
, plutus-ledger-api:{plutus-ledger-api, plutus-ledger-api-testlib} ^>= 1.23.0
, plutus-ledger-api:{plutus-ledger-api, plutus-ledger-api-testlib} ^>= 1.27.0
, prettyprinter
, prettyprinter-ansi-terminal
, prettyprinter-configurable ^>= 1.23.0
, prettyprinter-configurable ^>= 1.27.0
, random
, safe-exceptions
, scientific
Expand Down Expand Up @@ -377,8 +378,8 @@ test-suite cardano-api-golden
, hedgehog-extras ^>= 0.6.1.0
, microlens
, parsec
, plutus-core ^>= 1.23
, plutus-ledger-api ^>= 1.23.0
, plutus-core ^>= 1.27
, plutus-ledger-api ^>= 1.27.0
, tasty
, tasty-hedgehog
, time
Expand Down
21 changes: 4 additions & 17 deletions cardano-api/internal/Cardano/Api/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import Cardano.Ledger.Shelley.Genesis (NominalDiffTimeMicro, ShelleyGe
import qualified Cardano.Ledger.Shelley.Genesis as Ledger
import qualified Ouroboros.Consensus.Shelley.Eras as Shelley

import Control.Monad.Trans.Fail.String (errorFail)
import Data.ByteString (ByteString)
import qualified Data.Default.Class as DefaultClass
import Data.Functor.Identity (Identity)
Expand All @@ -62,6 +63,7 @@ import GHC.Stack (HasCallStack)
import Lens.Micro

import Test.Cardano.Ledger.Core.Rational ((%!))
import Test.Cardano.Ledger.Plutus (testingCostModelV3)

data ShelleyConfig = ShelleyConfig
{ scConfig :: !(Ledger.ShelleyGenesis Shelley.StandardCrypto)
Expand Down Expand Up @@ -169,6 +171,7 @@ conwayGenesisDefaults = ConwayGenesis { cgUpgradePParams = defaultUpgradeConwayP
, ucppCommitteeMinSize = 0
, ucppCommitteeMaxTermLength = EpochInterval 200
, ucppMinFeeRefScriptCostPerByte = 0 %! 1 -- TODO: set to correct value after benchmarking
, ucppPlutusV3CostModel = testingCostModelV3
}
where
defaultPoolVotingThresholds :: PoolVotingThresholds
Expand Down Expand Up @@ -206,14 +209,13 @@ alonzoGenesisDefaults = AlonzoGenesis { agPrices = Prices { prSteps = 721 %! 100
, agMaxBlockExUnits = ExUnits { exUnitsMem = 62000000
, exUnitsSteps = 20000000000
}
, agCostModels = apiCostModels
, agCostModels = errorFail apiCostModels
, agCollateralPercentage = 150
, agCoinsPerUTxOWord = CoinPerWord $ Coin 34482
}
where
apiCostModels = mkCostModelsLenient $ Map.fromList [ (fromIntegral $ fromEnum PlutusV1, defaultV1CostModel)
, (fromIntegral $ fromEnum PlutusV2, defaultV2CostModel)
, (fromIntegral $ fromEnum PlutusV3, defaultV3CostModel)
]
where
defaultV1CostModel = [ 205665, 812, 1, 1, 1000, 571, 0, 1, 1000, 24177, 4, 1, 1000, 32, 117366, 10475, 4
Expand Down Expand Up @@ -241,18 +243,3 @@ alonzoGenesisDefaults = AlonzoGenesis { agPrices = Prices { prSteps = 721 %! 100
, 32, 32696, 32, 43357, 32, 32247, 32, 38314, 32, 35892428, 10, 9462713, 1021, 10, 38887044
, 32947, 10
]
-- taken from https://github.com/IntersectMBO/plutus/blob/master/plutus-core/cost-model/data/builtinCostModel.json
defaultV3CostModel = [ 205665, 812, 1, 1, 1000, 571, 0, 1, 1000, 24177, 4, 1, 1000, 32, 117366, 10475, 4, 117366, 10475, 4, 832808, 18
, 3209094, 6, 331451, 1, 65990684, 23097, 18, 114242, 18, 94393407
, 87060, 18, 16420089, 18, 2145798, 36, 3795345, 12, 889023, 1, 204237282, 23271, 36, 129165, 36, 189977790
, 85902, 36, 33012864, 36, 388443360, 1, 401885761, 72, 2331379, 72, 23000, 100, 23000, 100, 23000, 100, 23000, 100, 23000
, 100, 23000, 100, 23000, 100, 23000, 100, 100, 100, 23000, 100
, 19537, 32, 175354, 32, 46417, 4, 221973, 511, 0, 1, 89141, 32, 497525, 14068, 4, 2, 196500, 453240, 220, 0, 1, 1, 1000, 28662
, 4, 2, 245000, 216773, 62, 1, 1060367, 12586, 1, 208512, 421, 1, 187000, 1000, 52998, 1, 80436, 32
, 43249, 1000, 32, 32, 80556, 1, 57667, 4, 1927926, 82523, 4, 1000, 10, 197145, 156, 1, 197145, 156, 1, 204924, 473, 1, 208896
, 511, 1, 52467, 32, 64832, 32, 65493, 32, 22558, 32, 16563, 32, 76511, 32, 196500, 453240, 220, 0
, 1, 1, 69522, 11687, 0, 1, 60091, 32, 196500, 453240, 220, 0, 1, 1, 196500, 453240, 220, 0, 1, 1, 1159724, 392670, 0, 2, 806990
, 30482, 4, 1927926, 82523, 4, 265318, 0, 4, 0, 85931, 32, 205665, 812, 1, 1, 41182
, 32, 212342, 32, 31220, 32, 32696, 32, 43357, 32, 32247, 32, 38314, 32, 35190005, 10, 57996947, 18975, 10, 39121781, 32260, 10
, 1292075, 24469, 74, 0, 1, 936157, 49601, 237, 0, 1
]
10 changes: 4 additions & 6 deletions cardano-api/internal/Cardano/Api/ProtocolParameters.hs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ import Data.Bifunctor (bimap, first)
import Data.ByteString (ByteString)
import Data.Data (Data)
import Data.Either.Combinators (maybeToRight)
import Data.Int (Int64)
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.Maybe (isJust)
Expand Down Expand Up @@ -1081,7 +1082,7 @@ fromAlonzoPrices Alonzo.Prices{Alonzo.prSteps, Alonzo.prMem} =
-- Script cost models
--

newtype CostModel = CostModel [Integer]
newtype CostModel = CostModel [Int64]
deriving (Eq, Show, Data)
deriving newtype (ToCBOR, FromCBOR)

Expand Down Expand Up @@ -1127,8 +1128,8 @@ fromAlonzoScriptLanguage Plutus.PlutusV1 = AnyPlutusScriptVersion PlutusScriptV1
fromAlonzoScriptLanguage Plutus.PlutusV2 = AnyPlutusScriptVersion PlutusScriptV2
fromAlonzoScriptLanguage Plutus.PlutusV3 = AnyPlutusScriptVersion PlutusScriptV3

toAlonzoCostModel :: CostModel -> Plutus.Language -> Either ProtocolParametersConversionError Alonzo.CostModel
toAlonzoCostModel (CostModel m) l = first (PpceInvalidCostModel (CostModel m)) $ Alonzo.mkCostModel l m
toAlonzoCostModel :: CostModel -> Plutus.Language -> Alonzo.CostModel
toAlonzoCostModel (CostModel m) l = Alonzo.mkCostModel l m

fromAlonzoCostModel :: Alonzo.CostModel -> CostModel
fromAlonzoCostModel m = CostModel $ Alonzo.getCostModelParams m
Expand Down Expand Up @@ -1858,7 +1859,6 @@ instance Error ProtocolParametersError where
data ProtocolParametersConversionError
= PpceOutOfBounds !ProtocolParameterName !Rational
| PpceVersionInvalid !ProtocolParameterVersion
| PpceInvalidCostModel !CostModel !Alonzo.CostModelApplyError
| PpceMissingParameter !ProtocolParameterName
deriving (Eq, Show, Data)

Expand All @@ -1872,7 +1872,5 @@ instance Error ProtocolParametersConversionError where
"Value for '" <> pretty name <> "' is outside of bounds: " <> pretty (fromRational r :: Double)
PpceVersionInvalid majorProtVer ->
"Major protocol version is invalid: " <> pretty majorProtVer
PpceInvalidCostModel cm err ->
"Invalid cost model: " <> pretty @Text (display err) <> " Cost model: " <> pshow cm
PpceMissingParameter name ->
"Missing parameter: " <> pretty name
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import Cardano.Ledger.Shelley.PParams (ShelleyPParams (..))
import Data.Aeson (FromJSON, eitherDecode, encode)
import Data.ByteString.Lazy (ByteString)
import Data.Functor.Identity (Identity)
import Data.Int (Int64)
import Data.Map (Map)
import qualified Data.Map as M
import Data.Proxy (Proxy (..))
Expand Down Expand Up @@ -107,7 +108,7 @@ legacyCardanoApiProtocolParameters = ProtocolParameters { protocolParamUTxOCostP
, (AnyPlutusScriptVersion PlutusScriptV1, CostModel [1..numParams PlutusV1])
]

numParams :: Language -> Integer
numParams :: Language -> Int64
numParams = fromIntegral . costModelParamsCount

executionUnits :: ExecutionUnits
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ test_ProtocolParametersConversionError =
testAllErrorMessages @ProtocolParametersConversionError
[ PpceOutOfBounds "pparam" 0.1
, PpceVersionInvalid 99999
, PpceInvalidCostModel costModel (Plutus.CMInternalWriteError string)
, PpceMissingParameter "pparam"
]

Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 01b2b66

Please sign in to comment.