From 1ae4d2fb9c318b2d5c1f2e46ca2a39bcf165f141 Mon Sep 17 00:00:00 2001 From: Lucsanszky Date: Tue, 23 Apr 2024 00:00:10 +0200 Subject: [PATCH] Integrate `ledger` and `consensus` --- cabal.project | 2 +- cardano-api/cardano-api.cabal | 19 +++++++++-------- cardano-api/internal/Cardano/Api/Genesis.hs | 21 ++++--------------- cardano-api/internal/Cardano/Api/Protocol.hs | 1 - .../Cardano/Api/ProtocolParameters.hs | 6 ++++-- .../Golden/Cardano/Api/ProtocolParameters.hs | 3 ++- flake.lock | 6 +++--- 7 files changed, 24 insertions(+), 34 deletions(-) diff --git a/cabal.project b/cabal.project index 8c194bb5ba..70c0208760 100644 --- a/cabal.project +++ b/cabal.project @@ -14,7 +14,7 @@ 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-14T00:00:00Z packages: cardano-api diff --git a/cardano-api/cardano-api.cabal b/cardano-api/cardano-api.cabal index b0b8c67c19..927e9ca05f 100644 --- a/cardano-api/cardano-api.cabal +++ b/cardano-api/cardano-api.cabal @@ -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 @@ -183,6 +183,7 @@ library internal , directory , either , errors + , FailT , filepath , formatting , groups @@ -192,19 +193,19 @@ library internal , mtl , network , optparse-applicative-fork - , ouroboros-consensus ^>= 0.17 - , ouroboros-consensus-cardano ^>= 0.15 - , ouroboros-consensus-diffusion ^>= 0.13 - , ouroboros-consensus-protocol ^>= 0.8 + , ouroboros-consensus ^>= 0.18 + , ouroboros-consensus-cardano ^>= 0.16 + , ouroboros-consensus-diffusion ^>= 0.16 + , ouroboros-consensus-protocol ^>= 0.9 , 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 @@ -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 diff --git a/cardano-api/internal/Cardano/Api/Genesis.hs b/cardano-api/internal/Cardano/Api/Genesis.hs index 98ef15f002..fc8962c729 100644 --- a/cardano-api/internal/Cardano/Api/Genesis.hs +++ b/cardano-api/internal/Cardano/Api/Genesis.hs @@ -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) @@ -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) @@ -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 @@ -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 @@ -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 - ] diff --git a/cardano-api/internal/Cardano/Api/Protocol.hs b/cardano-api/internal/Cardano/Api/Protocol.hs index 99016a1cfb..a79ea773a2 100644 --- a/cardano-api/internal/Cardano/Api/Protocol.hs +++ b/cardano-api/internal/Cardano/Api/Protocol.hs @@ -30,7 +30,6 @@ import Ouroboros.Consensus.HardFork.Combinator.Embed.Unary import qualified Ouroboros.Consensus.Ledger.SupportsProtocol as Consensus import Ouroboros.Consensus.Node.ProtocolInfo (ProtocolClientInfo (..), ProtocolInfo (..)) import Ouroboros.Consensus.Node.Run (RunNode) -import Ouroboros.Consensus.Protocol.Praos.Translate () import qualified Ouroboros.Consensus.Protocol.TPraos as Consensus import qualified Ouroboros.Consensus.Shelley.Eras as Consensus import qualified Ouroboros.Consensus.Shelley.Ledger.Block as Consensus diff --git a/cardano-api/internal/Cardano/Api/ProtocolParameters.hs b/cardano-api/internal/Cardano/Api/ProtocolParameters.hs index a5706dd282..767e08a613 100644 --- a/cardano-api/internal/Cardano/Api/ProtocolParameters.hs +++ b/cardano-api/internal/Cardano/Api/ProtocolParameters.hs @@ -136,6 +136,7 @@ import qualified Cardano.Ledger.Plutus.CostModels as Plutus import qualified Cardano.Ledger.Plutus.Language as Plutus import qualified Cardano.Ledger.Shelley.API as Ledger import Cardano.Slotting.Slot (EpochNo (..)) +import PlutusLedgerApi.Common (CostModelApplyError) import Control.Monad import Data.Aeson (FromJSON (..), ToJSON (..), object, withObject, (.!=), (.:), (.:?), @@ -144,6 +145,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) @@ -1081,7 +1083,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) @@ -1858,7 +1860,7 @@ instance Error ProtocolParametersError where data ProtocolParametersConversionError = PpceOutOfBounds !ProtocolParameterName !Rational | PpceVersionInvalid !ProtocolParameterVersion - | PpceInvalidCostModel !CostModel !Alonzo.CostModelApplyError + | PpceInvalidCostModel !CostModel !CostModelApplyError | PpceMissingParameter !ProtocolParameterName deriving (Eq, Show, Data) diff --git a/cardano-api/test/cardano-api-golden/Test/Golden/Cardano/Api/ProtocolParameters.hs b/cardano-api/test/cardano-api-golden/Test/Golden/Cardano/Api/ProtocolParameters.hs index 1e9df10ba0..54f720b692 100644 --- a/cardano-api/test/cardano-api-golden/Test/Golden/Cardano/Api/ProtocolParameters.hs +++ b/cardano-api/test/cardano-api-golden/Test/Golden/Cardano/Api/ProtocolParameters.hs @@ -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 (..)) @@ -107,7 +108,7 @@ legacyCardanoApiProtocolParameters = ProtocolParameters { protocolParamUTxOCostP , (AnyPlutusScriptVersion PlutusScriptV1, CostModel [1..numParams PlutusV1]) ] - numParams :: Language -> Integer + numParams :: Language -> Int64 numParams = fromIntegral . costModelParamsCount executionUnits :: ExecutionUnits diff --git a/flake.lock b/flake.lock index 693c097f89..5c75557f4a 100644 --- a/flake.lock +++ b/flake.lock @@ -3,11 +3,11 @@ "CHaP": { "flake": false, "locked": { - "lastModified": 1712227670, - "narHash": "sha256-VYqfCP/mElz0R5kEDwyFSAbAu9ZGW+TbQF57xza6vT4=", + "lastModified": 1715635762, + "narHash": "sha256-d5zfz+wE6Om29BI+wzNwA6VduNGHhJa+WPKct8hte50=", "owner": "intersectmbo", "repo": "cardano-haskell-packages", - "rev": "c34cde5a6377d120513caf1d8c5808e42f583308", + "rev": "2b6bac886a8236cf1c0b7353a88a2f10887f53f3", "type": "github" }, "original": {