Skip to content

Commit

Permalink
Bump the ledger version.
Browse files Browse the repository at this point in the history
- JSON instances have now been moved to the ledger.
- Various things move to cardano-protocol-tpraos.
  • Loading branch information
nc6 committed Jan 26, 2022
1 parent 5e9f4d5 commit 35703e8
Show file tree
Hide file tree
Showing 36 changed files with 137 additions and 161 deletions.
8 changes: 4 additions & 4 deletions cabal.project
Expand Up @@ -219,8 +219,8 @@ source-repository-package
source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-ledger
tag: 1a9ec4ae9e0b09d54e49b2a40c4ead37edadcce5
--sha256: 0avzyiqq0m8njd41ck9kpn992yq676b1az9xs77977h7cf85y4wm
tag: d6a4e1098e08e1231684d6bb05a0d08fdc00c5bf
--sha256: 1b8nj9976zimg0nk613dhkwb9v8vra4kmbychx3069w7lg44vycq
subdir:
eras/alonzo/impl
eras/alonzo/test-suite
Expand All @@ -247,8 +247,8 @@ source-repository-package
source-repository-package
type: git
location: https://github.com/input-output-hk/plutus
tag: 2f08f29732e602c5f3afc174bd381a17eb49b041
--sha256: 1j4zinp6rfa78842cqfdwzr08jnnn05k6w0sqg5vf1vw80kl7w83
tag: 180191c3108a78580d6f13f820742c71a174a459
--sha256: 13si8vq01hnk2g102fdv235z4ylrw8naip623y6c3b26vf9bb87z
subdir:
plutus-ledger-api
plutus-tx
Expand Down
Binary file not shown.
@@ -0,0 +1 @@
*
Expand Up @@ -37,6 +37,7 @@ library
, cardano-crypto-wrapper
, cardano-slotting
, containers
, compact-map
, mtl
, QuickCheck
, sop-core
Expand Down
Expand Up @@ -55,6 +55,7 @@ import Ouroboros.Consensus.Cardano.Block (CardanoEras, GenTx (..),
ShelleyEra)
import Ouroboros.Consensus.Cardano.Node (CardanoHardForkConstraints)

import qualified Data.Compact.SplitMap as SplitMap
import qualified Test.ThreadNet.Infra.Shelley as Shelley
import Test.ThreadNet.TxGen

Expand Down Expand Up @@ -140,8 +141,8 @@ migrateUTxO migrationInfo curSlot lcfg lst
| Just utxo <- mbUTxO =

let picked :: Map (SL.TxIn c) (SL.TxOut (ShelleyEra c))
picked =
Map.filter pick $ SL.unUTxO utxo
picked = SplitMap.toMap $
SplitMap.filter pick $ SL.unUTxO utxo
where
pick (SL.TxOut addr _) =
addr == SL.AddrBootstrap (SL.BootstrapAddress byronAddr)
Expand Down
Expand Up @@ -39,6 +39,7 @@ import qualified Cardano.Chain.Genesis as CC.Genesis
import Cardano.Chain.ProtocolConstants (kEpochSlots)
import Cardano.Chain.Slotting (unEpochSlots)
import qualified Cardano.Chain.Update as CC.Update
import qualified Cardano.Protocol.TPraos.OCert as SL

import Ouroboros.Consensus.Byron.Ledger.Block (ByronBlock)
import Ouroboros.Consensus.Byron.Ledger.Conversions
Expand Down
Expand Up @@ -28,6 +28,7 @@ import Test.Tasty
import Test.Tasty.QuickCheck

import Cardano.Crypto.Hash (ShortHash)
import qualified Cardano.Protocol.TPraos.OCert as SL
import Cardano.Slotting.Slot (EpochSize (..), SlotNo (..))

import Ouroboros.Consensus.BlockchainTime
Expand Down
Expand Up @@ -49,6 +49,7 @@ library
, cardano-ledger-shelley
, cardano-ledger-shelley-ma
, cardano-prelude
, cardano-protocol-tpraos
, cardano-slotting

, ouroboros-network
Expand Down
Expand Up @@ -76,8 +76,13 @@ import Cardano.Ledger.Allegra.Translation ()
import qualified Cardano.Ledger.Alonzo.Genesis as Alonzo
import Cardano.Ledger.Crypto (ADDRHASH, DSIGN, HASH)
import qualified Cardano.Ledger.Era as SL
import Cardano.Ledger.Hashes (EraIndependentTxBody)
import Cardano.Ledger.Keys (DSignable, Hash)
import Cardano.Ledger.Mary.Translation ()
import qualified Cardano.Ledger.Shelley.API as SL
import qualified Cardano.Protocol.TPraos.API as SL
import qualified Cardano.Protocol.TPraos.Rules.Prtcl as SL
import qualified Cardano.Protocol.TPraos.Rules.Tickn as SL

import Ouroboros.Consensus.Cardano.Block

Expand Down Expand Up @@ -481,7 +486,7 @@ translateLedgerViewByronToShelleyWrapper =
-------------------------------------------------------------------------------}

translateLedgerStateShelleyToAllegraWrapper ::
PraosCrypto c
(PraosCrypto c, DSignable c (Hash c EraIndependentTxBody))
=> RequiringBoth
WrapLedgerConfig
(Translate LedgerState)
Expand All @@ -493,15 +498,15 @@ translateLedgerStateShelleyToAllegraWrapper =
unComp . SL.translateEra' () . Comp

translateTxShelleyToAllegraWrapper ::
PraosCrypto c
(PraosCrypto c, DSignable c (Hash c EraIndependentTxBody))
=> InjectTx
(ShelleyBlock (ShelleyEra c))
(ShelleyBlock (AllegraEra c))
translateTxShelleyToAllegraWrapper = InjectTx $
fmap unComp . eitherToMaybe . runExcept . SL.translateEra () . Comp

translateValidatedTxShelleyToAllegraWrapper ::
PraosCrypto c
(PraosCrypto c, DSignable c (Hash c EraIndependentTxBody))
=> InjectValidatedTx
(ShelleyBlock (ShelleyEra c))
(ShelleyBlock (AllegraEra c))
Expand All @@ -513,7 +518,7 @@ translateValidatedTxShelleyToAllegraWrapper = InjectValidatedTx $
-------------------------------------------------------------------------------}

translateLedgerStateAllegraToMaryWrapper ::
PraosCrypto c
(PraosCrypto c, DSignable c (Hash c EraIndependentTxBody))
=> RequiringBoth
WrapLedgerConfig
(Translate LedgerState)
Expand All @@ -529,15 +534,15 @@ translateLedgerStateAllegraToMaryWrapper =
-------------------------------------------------------------------------------}

translateTxAllegraToMaryWrapper ::
PraosCrypto c
(PraosCrypto c, DSignable c (Hash c EraIndependentTxBody))
=> InjectTx
(ShelleyBlock (AllegraEra c))
(ShelleyBlock (MaryEra c))
translateTxAllegraToMaryWrapper = InjectTx $
fmap unComp . eitherToMaybe . runExcept . SL.translateEra () . Comp

translateValidatedTxAllegraToMaryWrapper ::
PraosCrypto c
(PraosCrypto c, DSignable c (Hash c EraIndependentTxBody))
=> InjectValidatedTx
(ShelleyBlock (AllegraEra c))
(ShelleyBlock (MaryEra c))
Expand All @@ -549,7 +554,7 @@ translateValidatedTxAllegraToMaryWrapper = InjectValidatedTx $
-------------------------------------------------------------------------------}

translateLedgerStateMaryToAlonzoWrapper ::
PraosCrypto c
(PraosCrypto c, DSignable c (Hash c EraIndependentTxBody))
=> RequiringBoth
WrapLedgerConfig
(Translate LedgerState)
Expand All @@ -567,7 +572,7 @@ getAlonzoTranslationContext =
shelleyLedgerTranslationContext . unwrapLedgerConfig

translateTxMaryToAlonzoWrapper ::
PraosCrypto c
(PraosCrypto c, DSignable c (Hash c EraIndependentTxBody))
=> Alonzo.AlonzoGenesis
-> InjectTx
(ShelleyBlock (MaryEra c))
Expand All @@ -577,7 +582,7 @@ translateTxMaryToAlonzoWrapper ctxt = InjectTx $

translateValidatedTxMaryToAlonzoWrapper ::
forall c.
PraosCrypto c
(PraosCrypto c, DSignable c (Hash c EraIndependentTxBody))
=> Alonzo.AlonzoGenesis
-> InjectValidatedTx
(ShelleyBlock (MaryEra c))
Expand Down
Expand Up @@ -12,6 +12,8 @@ import Data.SOP.Strict

import Ouroboros.Consensus.HardFork.Combinator

import Cardano.Ledger.Hashes (EraIndependentTxBody)
import Cardano.Ledger.Keys (DSignable, Hash)
import Ouroboros.Consensus.Cardano.Block
import Ouroboros.Consensus.Protocol.TPraos (PraosCrypto)
import Ouroboros.Consensus.Shelley.Ledger (ShelleyBlock)
Expand All @@ -20,7 +22,8 @@ import Ouroboros.Consensus.Shelley.ShelleyBased
-- | When the given ledger state corresponds to a Shelley-based era, apply the
-- given function to it.
overShelleyBasedLedgerState ::
forall c. PraosCrypto c
forall c.
(PraosCrypto c, DSignable c (Hash c EraIndependentTxBody))
=> ( forall era. (EraCrypto era ~ c, ShelleyBasedEra era)
=> LedgerState (ShelleyBlock era)
-> LedgerState (ShelleyBlock era)
Expand Down
109 changes: 6 additions & 103 deletions ouroboros-consensus-cardano/tools/db-analyser/Block/Alonzo.hs
@@ -1,39 +1,25 @@
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}

{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}

{-# OPTIONS_GHC -Wno-orphans #-}

module Block.Alonzo (
AlonzoBlockArgs
, Args (..)
) where

import Control.Applicative
import qualified Data.Map.Strict as Map
import Data.Text (Text)
import Data.Word (Word64)
import Options.Applicative
import Prelude

import Data.Aeson (FromJSON (..), (.:), (.:?))
import qualified Data.Aeson as Aeson
import Data.Aeson.Types (FromJSONKey (..))

import qualified Cardano.Ledger.Alonzo.Genesis as Alonzo
import qualified Cardano.Ledger.Alonzo.Language as Alonzo
import qualified Cardano.Ledger.Alonzo.Scripts as Alonzo
import qualified Cardano.Ledger.BaseTypes as Ledger
import HasAnalysis (HasProtocolInfo (..))
import Ouroboros.Consensus.Shelley.Eras (StandardAlonzo)
import Ouroboros.Consensus.Shelley.Ledger.Block (ShelleyBlock)

import Plutus.V1.Ledger.Api (defaultCostModelParams)

instance HasProtocolInfo (ShelleyBlock StandardAlonzo) where
data Args (ShelleyBlock StandardAlonzo) = AlonzoBlockArgs {
Expand All @@ -55,86 +41,3 @@ instance HasProtocolInfo (ShelleyBlock StandardAlonzo) where
<> "anticipate running an 'Alonzo only' chain."

type AlonzoBlockArgs = Args (ShelleyBlock StandardAlonzo)


{-------------------------------------------------------------------------------
FromJSON instances copied from cardano-node.Cardano.Api.Orphans
-------------------------------------------------------------------------------}

instance FromJSON Alonzo.AlonzoGenesis where
parseJSON = Aeson.withObject "Alonzo Genesis" $ \o -> do
coinsPerUTxOWord <- o .: "lovelacePerUTxOWord"
<|> o .: "adaPerUTxOWord"
cModels <- o .:? "costModels"
prices <- o .: "executionPrices"
maxTxExUnits <- o .: "maxTxExUnits"
maxBlockExUnits <- o .: "maxBlockExUnits"
maxValSize <- o .: "maxValueSize"
collateralPercentage <- o .: "collateralPercentage"
maxCollateralInputs <- o .: "maxCollateralInputs"
case cModels of
Nothing -> case Alonzo.CostModel <$> defaultCostModelParams of
Just m -> return Alonzo.AlonzoGenesis
{ Alonzo.coinsPerUTxOWord
, Alonzo.costmdls = Map.singleton Alonzo.PlutusV1 m
, Alonzo.prices
, Alonzo.maxTxExUnits
, Alonzo.maxBlockExUnits
, Alonzo.maxValSize
, Alonzo.collateralPercentage
, Alonzo.maxCollateralInputs
}
Nothing -> fail "Failed to extract the cost model params from defaultCostModel"
Just costmdls -> return Alonzo.AlonzoGenesis
{ Alonzo.coinsPerUTxOWord
, Alonzo.costmdls
, Alonzo.prices
, Alonzo.maxTxExUnits
, Alonzo.maxBlockExUnits
, Alonzo.maxValSize
, Alonzo.collateralPercentage
, Alonzo.maxCollateralInputs
}

deriving instance FromJSON a => FromJSON (Alonzo.ExUnits' a)

instance FromJSON Alonzo.ExUnits where
parseJSON = Aeson.withObject "exUnits" $ \o -> do
mem <- o .: "exUnitsMem"
steps <- o .: "exUnitsSteps"
bmem <- checkWord64Bounds mem
bsteps <- checkWord64Bounds steps
return $ Alonzo.ExUnits bmem bsteps
where
checkWord64Bounds n =
if n >= fromIntegral (minBound @Word64)
&& n <= fromIntegral (maxBound @Word64)
then pure n
else fail ("Unit out of bounds for Word64: " <> show n)

instance FromJSON Alonzo.Language where
parseJSON = Aeson.withText "Language" languageFromText

instance FromJSONKey Alonzo.Language where
fromJSONKey = Aeson.FromJSONKeyTextParser languageFromText

instance FromJSON Alonzo.Prices where
parseJSON =
Aeson.withObject "prices" $ \o -> do
steps <- o .: "prSteps"
mem <- o .: "prMem"
prSteps <- checkBoundedRational steps
prMem <- checkBoundedRational mem
return Alonzo.Prices { Alonzo.prSteps, Alonzo.prMem }
where
-- We cannot round-trip via NonNegativeInterval, so we go via Rational
checkBoundedRational r =
case Ledger.boundRational r of
Nothing -> fail ("too much precision for bounded rational: " ++ show r)
Just s -> return s

deriving newtype instance FromJSON Alonzo.CostModel

languageFromText :: MonadFail m => Text -> m Alonzo.Language
languageFromText "PlutusV1" = pure Alonzo.PlutusV1
languageFromText lang = fail $ "Error decoding Language: " ++ show lang
Expand Up @@ -71,8 +71,13 @@ import qualified Cardano.Ledger.BaseTypes as SL (ActiveSlotCoeff, Seed)
import Cardano.Ledger.Crypto (StandardCrypto, VRF)
import qualified Cardano.Ledger.Keys as SL
import qualified Cardano.Ledger.Shelley.API as SL
import qualified Cardano.Protocol.TPraos.BHeader as SL (mkSeed, seedEta, seedL)
import qualified Cardano.Protocol.TPraos.API as SL
import qualified Cardano.Protocol.TPraos.BHeader as SL (BHeader, mkSeed,
seedEta, seedL)
import qualified Cardano.Protocol.TPraos.OCert as Absolute (KESPeriod (..))
import qualified Cardano.Protocol.TPraos.OCert as SL
import qualified Cardano.Protocol.TPraos.Rules.Overlay as SL
import qualified Cardano.Protocol.TPraos.Rules.Tickn as SL

import Ouroboros.Consensus.Protocol.Ledger.HotKey (HotKey)
import qualified Ouroboros.Consensus.Protocol.Ledger.HotKey as HotKey
Expand Down
Expand Up @@ -49,6 +49,7 @@ library
, cardano-ledger-shelley-ma
, cardano-ledger-shelley-ma-test
, cardano-ledger-shelley-test
, cardano-protocol-tpraos
, small-steps

, ouroboros-network
Expand Down Expand Up @@ -94,6 +95,7 @@ test-suite test
, cardano-ledger-alonzo-test
, cardano-ledger-core
, cardano-ledger-shelley
, cardano-protocol-tpraos

, ouroboros-network
, ouroboros-consensus
Expand Down
Expand Up @@ -36,6 +36,7 @@ import Test.Util.Orphans.Arbitrary ()
import Test.Util.Serialisation.Roundtrip (Coherent (..),
SomeResult (..), WithVersion (..))

import qualified Cardano.Protocol.TPraos.API as SL
import Test.Cardano.Ledger.AllegraEraGen ()
import Test.Cardano.Ledger.Alonzo.AlonzoEraGen ()
import Test.Cardano.Ledger.MaryEraGen ()
Expand Down
Expand Up @@ -22,6 +22,7 @@ import qualified Cardano.Ledger.Core as Core
import Cardano.Ledger.Crypto (Crypto (..))
import qualified Cardano.Ledger.Shelley.API as SL
import qualified Cardano.Ledger.Shelley.Tx as SL (ValidateScript)
import qualified Cardano.Protocol.TPraos.API as SL
import Control.State.Transition.Extended (PredicateFailure)

import Test.Cardano.Crypto.VRF.Fake (FakeVRF)
Expand Down
Expand Up @@ -86,7 +86,10 @@ import qualified Cardano.Ledger.Shelley.Tx as SL (WitnessSetHKD (..))
import qualified Cardano.Ledger.Shelley.UTxO as SL (makeWitnessesVKey)
import qualified Cardano.Ledger.ShelleyMA.TxBody as MA
import qualified Cardano.Ledger.Val as SL
import qualified Cardano.Protocol.TPraos.OCert as SL (OCertSignable (..))
import Cardano.Protocol.TPraos.OCert
(OCert (ocertKESPeriod, ocertN, ocertSigma, ocertVkHot))
import qualified Cardano.Protocol.TPraos.OCert as SL (KESPeriod, OCert (OCert),
OCertSignable (..))

import Ouroboros.Consensus.Protocol.TPraos
import Ouroboros.Consensus.Shelley.Eras (EraCrypto, ShelleyEra)
Expand Down
Expand Up @@ -35,6 +35,7 @@ import Test.Util.Slots (NumSlots (..))
import qualified Cardano.Ledger.BaseTypes as SL (UnitInterval,
mkNonceFromNumber, unboundRational)
import qualified Cardano.Ledger.Shelley.API as SL
import qualified Cardano.Protocol.TPraos.OCert as SL

import Ouroboros.Consensus.Shelley.Eras (EraCrypto)
import Ouroboros.Consensus.Shelley.Ledger (ShelleyBlock)
Expand Down
@@ -0,0 +1 @@
X ���np��+�t���3N��Ue�<Ҷ���=�
@@ -0,0 +1 @@
*
@@ -0,0 +1 @@
X ���np��+�t���3N��Ue�<Ҷ���=�

0 comments on commit 35703e8

Please sign in to comment.