Skip to content

Commit

Permalink
Integrate ledger and consensus
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucsanszky committed May 13, 2024
1 parent 00ea789 commit 1ae4d2f
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 34 deletions.
2 changes: 1 addition & 1 deletion cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 10 additions & 9 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 @@ -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
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
]
1 change: 0 additions & 1 deletion cardano-api/internal/Cardano/Api/Protocol.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions cardano-api/internal/Cardano/Api/ProtocolParameters.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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, (.!=), (.:), (.:?),
Expand All @@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down
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
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 1ae4d2f

Please sign in to comment.