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

Add Vasil hardfork to cardano-api and cardano-cli #3765

Merged
merged 18 commits into from
Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ assumeMapCosts _proxy = stepFunction [
ShelleyBasedEraMary -> 39
-- Unconfirmed ! update when alonzo is runnable.
ShelleyBasedEraAlonzo -> error "39"
ShelleyBasedEraBabbage -> error "39"

-- Bytestring costs are not LINEAR !!
-- Costs are piecewise linear for payload sizes [0..23] and [24..64].
Expand Down Expand Up @@ -127,6 +128,7 @@ metadataInEra (Just m) = case shelleyBasedEra @ era of
ShelleyBasedEraAllegra -> TxMetadataInEra TxMetadataInAllegraEra m
ShelleyBasedEraMary -> TxMetadataInEra TxMetadataInMaryEra m
ShelleyBasedEraAlonzo -> TxMetadataInEra TxMetadataInAlonzoEra m
ShelleyBasedEraBabbage -> TxMetadataInEra TxMetadataInBabbageEra m

mkMetadata :: forall era . IsShelleyBasedEra era => Int -> Either String (TxMetadataInEra era)
mkMetadata 0 = Right $ metadataInEra Nothing
Expand All @@ -140,6 +142,7 @@ mkMetadata size
ShelleyBasedEraAllegra -> 39
ShelleyBasedEraMary -> 39
ShelleyBasedEraAlonzo -> 39 -- TODO: check minSize for Alonzo
ShelleyBasedEraBabbage -> 39 -- TODO: check minSize for Babbage
nettoSize = size - minSize

-- At 24 the CBOR representation changes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ txSubmissionClient tr bmtr initialTxSource endOfProtocolCallback =
(ShelleyBasedEraAllegra, ShelleyTx _ tx') -> GenTxAllegra (mkShelleyTx tx')
(ShelleyBasedEraMary, ShelleyTx _ tx') -> GenTxMary (mkShelleyTx tx')
(ShelleyBasedEraAlonzo, ShelleyTx _ tx') -> GenTxAlonzo (mkShelleyTx tx')
(ShelleyBasedEraBabbage, ShelleyTx _ _tx') -> error "TODO:Babbage"

fromGenTxId :: GenTxId CardanoBlock -> TxId
fromGenTxId (Block.GenTxIdShelley (Mempool.ShelleyTxId i)) = fromShelleyTxId i
Expand Down
10 changes: 8 additions & 2 deletions bench/tx-generator/src/Cardano/Benchmarking/GeneratorTx/Tx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,14 @@ mkGenesisTransaction key _payloadSize ttl fee txins txouts
ShelleyBasedEraAllegra -> TxFeeExplicit TxFeesExplicitInAllegraEra fee
ShelleyBasedEraMary -> TxFeeExplicit TxFeesExplicitInMaryEra fee
ShelleyBasedEraAlonzo -> TxFeeExplicit TxFeesExplicitInAlonzoEra fee
ShelleyBasedEraBabbage -> TxFeeExplicit TxFeesExplicitInBabbageEra fee
validityUpperBound = case shelleyBasedEra @ era of
ShelleyBasedEraShelley -> TxValidityUpperBound ValidityUpperBoundInShelleyEra ttl
ShelleyBasedEraAllegra -> TxValidityUpperBound ValidityUpperBoundInAllegraEra ttl
ShelleyBasedEraMary -> TxValidityUpperBound ValidityUpperBoundInMaryEra ttl
ShelleyBasedEraAlonzo -> TxValidityUpperBound ValidityUpperBoundInAlonzoEra ttl

ShelleyBasedEraBabbage -> TxValidityUpperBound ValidityUpperBoundInBabbageEra ttl

mkTransaction :: forall era .
IsShelleyBasedEra era
=> SigningKey PaymentKey
Expand Down Expand Up @@ -132,6 +134,7 @@ mkFee f = case shelleyBasedEra @ era of
ShelleyBasedEraAllegra -> TxFeeExplicit TxFeesExplicitInAllegraEra f
ShelleyBasedEraMary -> TxFeeExplicit TxFeesExplicitInMaryEra f
ShelleyBasedEraAlonzo -> TxFeeExplicit TxFeesExplicitInAlonzoEra f
ShelleyBasedEraBabbage -> TxFeeExplicit TxFeesExplicitInBabbageEra f

mkValidityUpperBound :: forall era .
IsShelleyBasedEra era
Expand All @@ -142,6 +145,7 @@ mkValidityUpperBound ttl = case shelleyBasedEra @ era of
ShelleyBasedEraAllegra -> TxValidityUpperBound ValidityUpperBoundInAllegraEra ttl
ShelleyBasedEraMary -> TxValidityUpperBound ValidityUpperBoundInMaryEra ttl
ShelleyBasedEraAlonzo -> TxValidityUpperBound ValidityUpperBoundInAlonzoEra ttl
ShelleyBasedEraBabbage -> TxValidityUpperBound ValidityUpperBoundInBabbageEra ttl

mkTransactionGen :: forall era .
IsShelleyBasedEra era
Expand Down Expand Up @@ -206,7 +210,8 @@ mkTxOutValueAdaOnly l = case shelleyBasedEra @ era of
ShelleyBasedEraAllegra -> TxOutAdaOnly AdaOnlyInAllegraEra l
ShelleyBasedEraMary -> TxOutValue MultiAssetInMaryEra $ lovelaceToValue l
ShelleyBasedEraAlonzo -> TxOutValue MultiAssetInAlonzoEra $ lovelaceToValue l

ShelleyBasedEraBabbage -> TxOutValue MultiAssetInBabbageEra $ lovelaceToValue l

txOutValueToLovelace :: TxOutValue era -> Lovelace
txOutValueToLovelace = \case
TxOutAdaOnly AdaOnlyInByronEra x -> x
Expand All @@ -222,3 +227,4 @@ txInModeCardano tx = case shelleyBasedEra @ era of
ShelleyBasedEraAllegra -> TxInMode tx AllegraEraInCardanoMode
ShelleyBasedEraMary -> TxInMode tx MaryEraInCardanoMode
ShelleyBasedEraAlonzo -> TxInMode tx AlonzoEraInCardanoMode
ShelleyBasedEraBabbage -> TxInMode tx BabbageEraInCardanoMode
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ withEra :: (forall era. IsShelleyBasedEra era => AsType era -> ActionM x) -> Act
withEra action = do
era <- get $ User TEra
case era of
AnyCardanoEra BabbageEra -> action AsBabbageEra
AnyCardanoEra AlonzoEra -> action AsAlonzoEra
AnyCardanoEra MaryEra -> action AsMaryEra
AnyCardanoEra AllegraEra -> action AsAllegraEra
Expand Down
2 changes: 2 additions & 0 deletions bench/tx-generator/src/Cardano/Benchmarking/Wallet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ genTx protocolParameters (collateral, collFunds) fee metadata witness inFunds ou
ShelleyBasedEraAllegra -> TxValidityNoUpperBound ValidityNoUpperBoundInAllegraEra
ShelleyBasedEraMary -> TxValidityNoUpperBound ValidityNoUpperBoundInMaryEra
ShelleyBasedEraAlonzo -> TxValidityNoUpperBound ValidityNoUpperBoundInAlonzoEra
ShelleyBasedEraBabbage -> TxValidityNoUpperBound ValidityNoUpperBoundInBabbageEra

newtype WalletScript era = WalletScript { runWalletScript :: IO (WalletStep era) }

Expand Down Expand Up @@ -232,3 +233,4 @@ mkTxOutValueAdaOnly l = case shelleyBasedEra @ era of
ShelleyBasedEraAllegra -> TxOutAdaOnly AdaOnlyInAllegraEra l
ShelleyBasedEraMary -> TxOutValue MultiAssetInMaryEra $ lovelaceToValue l
ShelleyBasedEraAlonzo -> TxOutValue MultiAssetInAlonzoEra $ lovelaceToValue l
ShelleyBasedEraBabbage -> TxOutValue MultiAssetInBabbageEra $ lovelaceToValue l
1 change: 1 addition & 0 deletions cardano-api/cardano-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ library
, cardano-crypto-wrapper
, cardano-data
, cardano-ledger-alonzo
, cardano-ledger-babbage
, cardano-ledger-byron
, cardano-ledger-core
, cardano-ledger-shelley-ma
Expand Down
1 change: 1 addition & 0 deletions cardano-api/gen/Gen/Cardano/Api/Typed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,7 @@ genTxOutDatumHash era = case era of
, TxOutDatumHash ScriptDataInAlonzoEra <$> genHashScriptData
, TxOutDatum ScriptDataInAlonzoEra <$> genScriptData
]
BabbageEra -> pure TxOutDatumNone -- TODO: Babbage Era

mkDummyHash :: forall h a. CRYPTO.HashAlgorithm h => Int -> CRYPTO.Hash h a
mkDummyHash = coerce . CRYPTO.hashWithSerialiser @h CBOR.toCBOR
Expand Down
9 changes: 9 additions & 0 deletions cardano-api/src/Cardano/Api/Block.hs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ instance Show (Block era) where
. showsPrec 11 block
)

showsPrec p (ShelleyBlock ShelleyBasedEraBabbage _block) =
showParen (p >= 11)
( showString "ShelleyBlock ShelleyBasedEraBabbage "
. error "TODO: Babbage era" --showsPrec 11 block
)

getBlockTxs :: forall era . Block era -> [Tx era]
getBlockTxs (ByronBlock Consensus.ByronBlock { Consensus.byronBlockRaw }) =
case byronBlockRaw of
Expand Down Expand Up @@ -180,6 +186,7 @@ obtainConsensusShelleyBasedEra ShelleyBasedEraShelley f = f
obtainConsensusShelleyBasedEra ShelleyBasedEraAllegra f = f
obtainConsensusShelleyBasedEra ShelleyBasedEraMary f = f
obtainConsensusShelleyBasedEra ShelleyBasedEraAlonzo f = f
obtainConsensusShelleyBasedEra ShelleyBasedEraBabbage _f = error "TODO: Babbage era"


-- ----------------------------------------------------------------------------
Expand Down Expand Up @@ -245,6 +252,7 @@ toConsensusBlock bInMode =
BlockInMode (ShelleyBlock ShelleyBasedEraAllegra b') AllegraEraInCardanoMode -> Consensus.BlockAllegra b'
BlockInMode (ShelleyBlock ShelleyBasedEraMary b') MaryEraInCardanoMode -> Consensus.BlockMary b'
BlockInMode (ShelleyBlock ShelleyBasedEraAlonzo b') AlonzoEraInCardanoMode -> Consensus.BlockAlonzo b'
BlockInMode (ShelleyBlock ShelleyBasedEraBabbage _b') BabbageEraInCardanoMode -> error "TODO: Babbage"

-- ----------------------------------------------------------------------------
-- Block headers
Expand Down Expand Up @@ -281,6 +289,7 @@ getBlockHeader (ShelleyBlock shelleyEra block) = case shelleyEra of
ShelleyBasedEraAllegra -> go
ShelleyBasedEraMary -> go
ShelleyBasedEraAlonzo -> go
ShelleyBasedEraBabbage -> error "TODO: Babbage era"
where
go :: Consensus.ShelleyBasedEra (ShelleyLedgerEra era) => BlockHeader
go = BlockHeader headerFieldSlot (HeaderHash hashSBS) headerFieldBlockNo
Expand Down
57 changes: 47 additions & 10 deletions cardano-api/src/Cardano/Api/Eras.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module Cardano.Api.Eras
, AllegraEra
, MaryEra
, AlonzoEra
, BabbageEra
, CardanoEra(..)
, IsCardanoEra(..)
, AnyCardanoEra(..)
Expand All @@ -25,6 +26,7 @@ module Cardano.Api.Eras
, Shelley
, Allegra
, Mary
, Babbage

-- * Shelley-based eras
, ShelleyBasedEra(..)
Expand All @@ -40,8 +42,8 @@ module Cardano.Api.Eras
, cardanoEraStyle

-- * Data family instances
, AsType(AsByronEra, AsShelleyEra, AsAllegraEra, AsMaryEra, AsAlonzoEra,
AsByron, AsShelley, AsAllegra, AsMary)
, AsType(AsByronEra, AsShelleyEra, AsAllegraEra, AsMaryEra, AsAlonzoEra, AsBabbageEra,
AsByron, AsShelley, AsAllegra, AsMary, AsAlonzo, AsBabbage)
) where

import Prelude
Expand All @@ -51,7 +53,9 @@ import qualified Data.Text as Text
import Data.Type.Equality (TestEquality (..), (:~:) (Refl))

import Ouroboros.Consensus.Shelley.Eras as Ledger (StandardAllegra, StandardAlonzo,
StandardMary, StandardShelley)
StandardCrypto, StandardMary, StandardShelley)

import qualified Cardano.Ledger.Babbage as Babbage

import Cardano.Api.HasTypeProxy

Expand All @@ -71,6 +75,9 @@ data MaryEra
-- | A type used as a tag to distinguish the Alonzo era.
data AlonzoEra

-- | A type used as a tag to distinguish the Babbage era.
data BabbageEra

instance HasTypeProxy ByronEra where
data AsType ByronEra = AsByronEra
proxyToAsType _ = AsByronEra
Expand All @@ -91,6 +98,9 @@ instance HasTypeProxy AlonzoEra where
data AsType AlonzoEra = AsAlonzoEra
proxyToAsType _ = AsAlonzoEra

instance HasTypeProxy BabbageEra where
data AsType BabbageEra = AsBabbageEra
proxyToAsType _ = AsBabbageEra

-- ----------------------------------------------------------------------------
-- Deprecated aliases
Expand All @@ -100,6 +110,7 @@ type Byron = ByronEra
type Shelley = ShelleyEra
type Allegra = AllegraEra
type Mary = MaryEra
type Babbage = BabbageEra

{-# DEPRECATED Byron "Use 'ByronEra' or 'ByronAddr' as appropriate" #-}
{-# DEPRECATED Shelley "Use 'ShelleyEra' or 'ShelleyAddr' as appropriate" #-}
Expand All @@ -118,6 +129,13 @@ pattern AsAllegra = AsAllegraEra
pattern AsMary :: AsType MaryEra
pattern AsMary = AsMaryEra


pattern AsAlonzo :: AsType AlonzoEra
pattern AsAlonzo = AsAlonzoEra

pattern AsBabbage :: AsType BabbageEra
pattern AsBabbage = AsBabbageEra

{-# DEPRECATED AsByron "Use 'AsByronEra' instead" #-}
{-# DEPRECATED AsShelley "Use 'AsShelleyEra' instead" #-}
{-# DEPRECATED AsAllegra "Use 'AsAllegraEra' instead" #-}
Expand All @@ -143,6 +161,7 @@ data CardanoEra era where
AllegraEra :: CardanoEra AllegraEra
MaryEra :: CardanoEra MaryEra
AlonzoEra :: CardanoEra AlonzoEra
BabbageEra :: CardanoEra BabbageEra
-- when you add era here, change `instance Bounded AnyCardanoEra`

deriving instance Eq (CardanoEra era)
Expand All @@ -155,13 +174,15 @@ instance ToJSON (CardanoEra era) where
toJSON AllegraEra = "Allegra"
toJSON MaryEra = "Mary"
toJSON AlonzoEra = "Alonzo"
toJSON BabbageEra = "Babbage"

instance TestEquality CardanoEra where
testEquality ByronEra ByronEra = Just Refl
testEquality ShelleyEra ShelleyEra = Just Refl
testEquality AllegraEra AllegraEra = Just Refl
testEquality MaryEra MaryEra = Just Refl
testEquality AlonzoEra AlonzoEra = Just Refl
testEquality BabbageEra BabbageEra = Just Refl
testEquality _ _ = Nothing


Expand All @@ -187,6 +208,10 @@ instance IsCardanoEra MaryEra where
instance IsCardanoEra AlonzoEra where
cardanoEra = AlonzoEra

instance IsCardanoEra BabbageEra where
cardanoEra = BabbageEra


data AnyCardanoEra where
AnyCardanoEra :: IsCardanoEra era -- Provide class constraint
=> CardanoEra era -- and explicit value.
Expand All @@ -202,26 +227,28 @@ instance Eq AnyCardanoEra where

instance Bounded AnyCardanoEra where
minBound = AnyCardanoEra ByronEra
maxBound = AnyCardanoEra AlonzoEra
maxBound = AnyCardanoEra BabbageEra

instance Enum AnyCardanoEra where

-- [e..] = [e..maxBound]
enumFrom e = enumFromTo e maxBound

fromEnum = \case
AnyCardanoEra ByronEra -> 0
AnyCardanoEra ShelleyEra -> 1
AnyCardanoEra AllegraEra -> 2
AnyCardanoEra MaryEra -> 3
AnyCardanoEra AlonzoEra -> 4
AnyCardanoEra ByronEra -> 0
AnyCardanoEra ShelleyEra -> 1
AnyCardanoEra AllegraEra -> 2
AnyCardanoEra MaryEra -> 3
AnyCardanoEra AlonzoEra -> 4
AnyCardanoEra BabbageEra -> 5

toEnum = \case
0 -> AnyCardanoEra ByronEra
1 -> AnyCardanoEra ShelleyEra
2 -> AnyCardanoEra AllegraEra
3 -> AnyCardanoEra MaryEra
4 -> AnyCardanoEra AlonzoEra
5 -> AnyCardanoEra BabbageEra
n ->
error $
"AnyCardanoEra.toEnum: " <> show n
Expand All @@ -238,6 +265,7 @@ instance FromJSON AnyCardanoEra where
"Allegra" -> pure $ AnyCardanoEra AllegraEra
"Mary" -> pure $ AnyCardanoEra MaryEra
"Alonzo" -> pure $ AnyCardanoEra AlonzoEra
"Babbage" -> pure $ AnyCardanoEra BabbageEra
wrong -> fail $ "Failed to parse unknown era: " <> Text.unpack wrong


Expand All @@ -250,6 +278,7 @@ anyCardanoEra ShelleyEra = AnyCardanoEra ShelleyEra
anyCardanoEra AllegraEra = AnyCardanoEra AllegraEra
anyCardanoEra MaryEra = AnyCardanoEra MaryEra
anyCardanoEra AlonzoEra = AnyCardanoEra AlonzoEra
anyCardanoEra BabbageEra = AnyCardanoEra BabbageEra

-- | This pairs up some era-dependent type with a 'CardanoEra' value that tells
-- us what era it is, but hides the era type. This is useful when the era is
Expand Down Expand Up @@ -279,6 +308,7 @@ data ShelleyBasedEra era where
ShelleyBasedEraAllegra :: ShelleyBasedEra AllegraEra
ShelleyBasedEraMary :: ShelleyBasedEra MaryEra
ShelleyBasedEraAlonzo :: ShelleyBasedEra AlonzoEra
ShelleyBasedEraBabbage :: ShelleyBasedEra BabbageEra

deriving instance Eq (ShelleyBasedEra era)
deriving instance Ord (ShelleyBasedEra era)
Expand All @@ -303,6 +333,10 @@ instance IsShelleyBasedEra MaryEra where
instance IsShelleyBasedEra AlonzoEra where
shelleyBasedEra = ShelleyBasedEraAlonzo


instance IsShelleyBasedEra BabbageEra where
shelleyBasedEra = ShelleyBasedEraBabbage

-- | This pairs up some era-dependent type with a 'ShelleyBasedEra' value that
-- tells us what era it is, but hides the era type. This is useful when the era
-- is not statically known, for example when deserialising from a file.
Expand All @@ -320,7 +354,7 @@ shelleyBasedToCardanoEra ShelleyBasedEraShelley = ShelleyEra
shelleyBasedToCardanoEra ShelleyBasedEraAllegra = AllegraEra
shelleyBasedToCardanoEra ShelleyBasedEraMary = MaryEra
shelleyBasedToCardanoEra ShelleyBasedEraAlonzo = AlonzoEra

shelleyBasedToCardanoEra ShelleyBasedEraBabbage = BabbageEra

-- ----------------------------------------------------------------------------
-- Cardano eras factored as Byron vs Shelley-based
Expand Down Expand Up @@ -352,6 +386,7 @@ cardanoEraStyle ShelleyEra = ShelleyBasedEra ShelleyBasedEraShelley
cardanoEraStyle AllegraEra = ShelleyBasedEra ShelleyBasedEraAllegra
cardanoEraStyle MaryEra = ShelleyBasedEra ShelleyBasedEraMary
cardanoEraStyle AlonzoEra = ShelleyBasedEra ShelleyBasedEraAlonzo
cardanoEraStyle BabbageEra = ShelleyBasedEra ShelleyBasedEraBabbage


-- ----------------------------------------------------------------------------
Expand All @@ -371,3 +406,5 @@ type family ShelleyLedgerEra era where
ShelleyLedgerEra AllegraEra = Ledger.StandardAllegra
ShelleyLedgerEra MaryEra = Ledger.StandardMary
ShelleyLedgerEra AlonzoEra = Ledger.StandardAlonzo
ShelleyLedgerEra BabbageEra = Babbage.BabbageEra StandardCrypto

Loading