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

Basic Alonzo node #2657

Merged
merged 7 commits into from
May 20, 2021
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
35 changes: 29 additions & 6 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ package ouroboros-network
package ouroboros-network-framework
tests: False

package plutus-tx
tests: False

package prettyprinter-configurable
tests: False

package small-steps
tests: False

Expand Down Expand Up @@ -99,8 +105,8 @@ source-repository-package
source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-base
tag: 0f409343c3655c4bacd7fab385d392ec5d5cca98
--sha256: 0js76inb7avg8c39c9k2zsr77sycg2vadylgvsswdsba808p6hr9
tag: a715c7f420770b70bbe95ca51d3dec83866cb1bd
--sha256: 06l06mmb8cd4q37bnvfpgx1c5zgsl4xaf106dqva98738i8asj7j
subdir:
binary
binary/test
Expand All @@ -119,9 +125,10 @@ source-repository-package
source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-ledger-specs
tag: e8f19bcc9c8f405131cb95ca6ada26b2b4eac638
--sha256: 1v36d3lyhmadzj0abdfsppjna7n7llzqzp9ikx5yq28l2kda2f1p
tag: 41b02e51d3e0a4826264fc4ae595a9dd6a7d8849
--sha256: 0gn3qiq4n8xgb038qravwiikjf26i5fshkh7w16s3gax6z7c9i3b
subdir:
alonzo/impl
byron/chain/executable-spec
byron/crypto
byron/crypto/test
Expand All @@ -134,6 +141,7 @@ source-repository-package
shelley/chain-and-ledger/dependencies/non-integer
shelley/chain-and-ledger/executable-spec
shelley/chain-and-ledger/shelley-spec-ledger-test
shelley-ma/shelley-ma-test
shelley-ma/impl
shelley-ma/shelley-ma-test

Expand Down Expand Up @@ -176,8 +184,8 @@ source-repository-package
source-repository-package
type: git
location: https://github.com/input-output-hk/ouroboros-network
tag: 8d44955afdebcf9cc521f60e3a9f31e853ace2c1
--sha256: 1vv40h3ljnyi67jy8mjj1bd97pjlb5lsc2praf92sdc132bqyzz7
tag: 8bbded8a3a6e967ce67fbcaf50579d3719e52bef
--sha256: 1j9vdfvqkdl6qs6xp9n19y9hvfnxqii6awqwrf1ahlfbk9r3fwmb
subdir:
io-sim
io-sim-classes
Expand All @@ -192,6 +200,17 @@ source-repository-package
typed-protocols
typed-protocols-examples

source-repository-package
type: git
location: https://github.com/input-output-hk/plutus
tag: 530d3f7940319788a49c7ecb017f8366994990b0
--sha256: 01jzrl04zyp63c9sxd1qgdy4nxbnaz7n2g1pw4x2d5y9562mrq6v
subdir:
plutus-core
plutus-ledger-api
plutus-tx
prettyprinter-configurable

constraints:
hedgehog >= 1.0
, bimap >= 0.4.0
Expand All @@ -203,3 +222,7 @@ constraints:

package comonad
flags: -test-doctests

allow-newer:
monoidal-containers:aeson,
size-based:template-haskell
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 @@ -132,6 +132,9 @@ instance Show (Block era) where
. showsPrec 11 block
)

showsPrec _ (ShelleyBlock ShelleyBasedEraAlonzo _) =
error "Show (Block era): Alonzo not implemented yet"

getBlockTxs :: forall era . Block era -> [Tx era]
getBlockTxs (ByronBlock Consensus.ByronBlock { Consensus.byronBlockRaw }) =
case byronBlockRaw of
Expand All @@ -147,6 +150,8 @@ getBlockTxs (ShelleyBlock shelleyEra Consensus.ShelleyBlock{Consensus.shelleyBlo
ShelleyBasedEraShelley -> go
ShelleyBasedEraAllegra -> go
ShelleyBasedEraMary -> go
ShelleyBasedEraAlonzo ->
error "getBlockTxs: Alonzo era not implemented yet"
where
go :: Ledger.TxSeq (ShelleyLedgerEra era) ~ Shelley.TxSeq (ShelleyLedgerEra era)
=> SafeToHash (Core.Witnesses (ShelleyLedgerEra era))
Expand Down Expand Up @@ -198,6 +203,9 @@ fromConsensusBlock CardanoMode =
BlockInMode (ShelleyBlock ShelleyBasedEraMary b')
MaryEraInCardanoMode

Consensus.BlockAlonzo b' ->
BlockInMode (ShelleyBlock ShelleyBasedEraAlonzo b')
AlonzoEraInCardanoMode

-- ----------------------------------------------------------------------------
-- Block headers
Expand Down Expand Up @@ -229,6 +237,7 @@ getBlockHeader (ShelleyBlock shelleyEra block) = case shelleyEra of
ShelleyBasedEraShelley -> go
ShelleyBasedEraAllegra -> go
ShelleyBasedEraMary -> go
ShelleyBasedEraAlonzo -> error "getBlockHeader: Alonzo era not implemented yet"
where
go :: Consensus.ShelleyBasedEra (ShelleyLedgerEra era) => BlockHeader
go = BlockHeader headerFieldSlot (HeaderHash hashSBS) headerFieldBlockNo
Expand Down
26 changes: 22 additions & 4 deletions cardano-api/src/Cardano/Api/Eras.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module Cardano.Api.Eras
, ShelleyEra
, AllegraEra
, MaryEra
, AlonzoEra
, CardanoEra(..)
, IsCardanoEra(..)
, AnyCardanoEra(..)
Expand Down Expand Up @@ -48,8 +49,8 @@ import Data.Type.Equality (TestEquality (..), (:~:) (Refl))

import Cardano.Ledger.Era as Ledger (Crypto)

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

import Cardano.Api.HasTypeProxy

Expand All @@ -66,6 +67,10 @@ data AllegraEra
-- | A type used as a tag to distinguish the Mary era.
data MaryEra

-- | A type used as a tag to distingush the Alonzo era.
data AlonzoEra


instance HasTypeProxy ByronEra where
data AsType ByronEra = AsByronEra
proxyToAsType _ = AsByronEra
Expand All @@ -82,7 +87,9 @@ instance HasTypeProxy MaryEra where
data AsType MaryEra = AsMaryEra
proxyToAsType _ = AsMaryEra


instance HasTypeProxy AlonzoEra where
data AsType AlonzoEra = AsAlonzoEra
proxyToAsType _ = AsAlonzoEra
-- ----------------------------------------------------------------------------
-- Deprecated aliases
--
Expand Down Expand Up @@ -133,6 +140,7 @@ data CardanoEra era where
ShelleyEra :: CardanoEra ShelleyEra
AllegraEra :: CardanoEra AllegraEra
MaryEra :: CardanoEra MaryEra
AlonzoEra :: CardanoEra AlonzoEra

deriving instance Eq (CardanoEra era)
deriving instance Ord (CardanoEra era)
Expand All @@ -143,12 +151,14 @@ instance ToJSON (CardanoEra era) where
toJSON ShelleyEra = "Shelley"
toJSON AllegraEra = "Allegra"
toJSON MaryEra = "Mary"
toJSON AlonzoEra = "Alonzo"

instance TestEquality CardanoEra where
testEquality ByronEra ByronEra = Just Refl
Jimbo4350 marked this conversation as resolved.
Show resolved Hide resolved
testEquality ShelleyEra ShelleyEra = Just Refl
testEquality AllegraEra AllegraEra = Just Refl
testEquality MaryEra MaryEra = Just Refl
testEquality AlonzoEra AlonzoEra = Just Refl
testEquality _ _ = Nothing


Expand All @@ -171,6 +181,8 @@ instance IsCardanoEra AllegraEra where
instance IsCardanoEra MaryEra where
cardanoEra = MaryEra

instance IsCardanoEra AlonzoEra where
cardanoEra = AlonzoEra

data AnyCardanoEra where
AnyCardanoEra :: IsCardanoEra era -- Provide class constraint
Expand All @@ -196,7 +208,7 @@ anyCardanoEra ByronEra = AnyCardanoEra ByronEra
anyCardanoEra ShelleyEra = AnyCardanoEra ShelleyEra
anyCardanoEra AllegraEra = AnyCardanoEra AllegraEra
anyCardanoEra MaryEra = AnyCardanoEra MaryEra

anyCardanoEra AlonzoEra = AnyCardanoEra AlonzoEra

-- | 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 @@ -225,6 +237,7 @@ data ShelleyBasedEra era where
ShelleyBasedEraShelley :: ShelleyBasedEra ShelleyEra
ShelleyBasedEraAllegra :: ShelleyBasedEra AllegraEra
ShelleyBasedEraMary :: ShelleyBasedEra MaryEra
ShelleyBasedEraAlonzo :: ShelleyBasedEra AlonzoEra

deriving instance Eq (ShelleyBasedEra era)
deriving instance Ord (ShelleyBasedEra era)
Expand All @@ -247,6 +260,8 @@ instance IsShelleyBasedEra AllegraEra where
instance IsShelleyBasedEra MaryEra where
shelleyBasedEra = ShelleyBasedEraMary

instance IsShelleyBasedEra AlonzoEra where
shelleyBasedEra = ShelleyBasedEraAlonzo

-- | 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
Expand Down Expand Up @@ -288,6 +303,7 @@ cardanoEraStyle ByronEra = LegacyByronEra
cardanoEraStyle ShelleyEra = ShelleyBasedEra ShelleyBasedEraShelley
cardanoEraStyle AllegraEra = ShelleyBasedEra ShelleyBasedEraAllegra
cardanoEraStyle MaryEra = ShelleyBasedEra ShelleyBasedEraMary
cardanoEraStyle AlonzoEra = ShelleyBasedEra ShelleyBasedEraAlonzo


-- ----------------------------------------------------------------------------
Expand All @@ -306,3 +322,5 @@ type family ShelleyLedgerEra era where
ShelleyLedgerEra ShelleyEra = Ledger.StandardShelley
ShelleyLedgerEra AllegraEra = Ledger.StandardAllegra
ShelleyLedgerEra MaryEra = Ledger.StandardMary
ShelleyLedgerEra AlonzoEra = Ledger.StandardAlonzo

20 changes: 9 additions & 11 deletions cardano-api/src/Cardano/Api/Fees.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,15 @@ transactionFee :: forall era.
-> Natural -- ^ The tx fee per byte
-> Tx era
-> Lovelace
transactionFee txFeeFixed txFeePerByte (ShelleyTx _ tx) =
Lovelace (a * x + b)
where
a = toInteger txFeePerByte
x = getField @"txsize" tx
b = toInteger txFeeFixed

--TODO: This can be made to work for Byron txs too. Do that: fill in this case
-- and remove the IsShelleyBasedEra constraint.
transactionFee _ _ (ByronTx _) =
case shelleyBasedEra :: ShelleyBasedEra era of {}
transactionFee txFeeFixed txFeePerByte tx =
let a = toInteger txFeePerByte
b = toInteger txFeeFixed
in case tx of
ShelleyTx _ tx' -> let x = getField @"txsize" tx'
in Lovelace (a * x + b)
--TODO: This can be made to work for Byron txs too. Do that: fill in this case
-- and remove the IsShelleyBasedEra constraint.
ByronTx _ -> case shelleyBasedEra :: ShelleyBasedEra ByronEra of {}
dcoutts marked this conversation as resolved.
Show resolved Hide resolved


--TODO: in the Byron case the per-byte is non-integral, would need different
Expand Down
47 changes: 23 additions & 24 deletions cardano-api/src/Cardano/Api/LedgerState.hs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ applyBlock env oldState enableValidation block
ShelleyBasedEraShelley -> Consensus.BlockShelley shelleyBlock
ShelleyBasedEraAllegra -> Consensus.BlockAllegra shelleyBlock
ShelleyBasedEraMary -> Consensus.BlockMary shelleyBlock
ShelleyBasedEraAlonzo -> Consensus.BlockAlonzo shelleyBlock

pattern LedgerStateByron
:: Ledger.LedgerState Byron.ByronBlock
Expand Down Expand Up @@ -445,14 +446,16 @@ data NodeConfig = NodeConfig
, ncByronSoftwareVersion :: !Cardano.Chain.Update.SoftwareVersion
, ncByronProtocolVersion :: !Cardano.Chain.Update.ProtocolVersion

-- Shelley hardfok parameters
, ncByronToShelley :: !ByronToShelley

-- Allegra hardfok parameters
, ncShelleyToAllegra :: !ShelleyToAllegra

-- Mary hardfok parameters
, ncAllegraToMary :: !AllegraToMary
-- Per-era parameters for the hardfok transitions:
, ncByronToShelley :: !(Consensus.ProtocolTransitionParamsShelleyBased
Shelley.StandardShelley)
, ncShelleyToAllegra :: !(Consensus.ProtocolTransitionParamsShelleyBased
Shelley.StandardAllegra)
, ncAllegraToMary :: !(Consensus.ProtocolTransitionParamsShelleyBased
Shelley.StandardMary)
--TODO:
--, ncMaryToAlonzo :: !(Consensus.ProtocolTransitionParamsShelleyBased
-- Shelley.StandardAlonzo)
}

instance FromJSON NodeConfig where
Expand All @@ -470,9 +473,14 @@ instance FromJSON NodeConfig where
<*> o .: "RequiresNetworkMagic"
<*> parseByronSoftwareVersion o
<*> parseByronProtocolVersion o
<*> (Consensus.ProtocolParamsTransition <$> parseShelleyHardForkEpoch o)
<*> (Consensus.ProtocolParamsTransition <$> parseAllegraHardForkEpoch o)
<*> (Consensus.ProtocolParamsTransition <$> parseMaryHardForkEpoch o)
<*> (Consensus.ProtocolTransitionParamsShelleyBased ()
<$> parseShelleyHardForkEpoch o)
<*> (Consensus.ProtocolTransitionParamsShelleyBased ()
<$> parseAllegraHardForkEpoch o)
<*> (Consensus.ProtocolTransitionParamsShelleyBased ()
<$> parseMaryHardForkEpoch o)
-- <*> (Consensus.ProtocolTransitionParamsShelleyBased ({-alonzo genesis-})
-- <$> parseAlonzoHardForkEpoch o)

parseByronProtocolVersion :: Object -> Data.Aeson.Types.Internal.Parser Cardano.Chain.Update.ProtocolVersion
parseByronProtocolVersion o =
Expand Down Expand Up @@ -548,19 +556,6 @@ data ShelleyConfig = ShelleyConfig
, scGenesisHash :: !GenesisHashShelley
}

type ByronToShelley =
Consensus.ProtocolParamsTransition Byron.ByronBlock
(Shelley.ShelleyBlock Shelley.StandardShelley)

type ShelleyToAllegra =
Consensus.ProtocolParamsTransition
(Shelley.ShelleyBlock Shelley.StandardShelley)
(Shelley.ShelleyBlock Shelley.StandardAllegra)

type AllegraToMary =
Consensus.ProtocolParamsTransition
(Shelley.ShelleyBlock Shelley.StandardAllegra)
(Shelley.ShelleyBlock Shelley.StandardMary)

newtype GenesisFile = GenesisFile
{ unGenesisFile :: FilePath
Expand Down Expand Up @@ -619,9 +614,13 @@ mkProtocolInfoCardano (GenesisCardano dnc byronGenesis shelleyGenesis)
Consensus.ProtocolParamsMary
{ Consensus.maryProtVer = shelleyProtVer dnc
}
Consensus.ProtocolParamsAlonzo
{ Consensus.alonzoProtVer = error "mkProtocolInfoCardano: alonzoProtVer"
}
(ncByronToShelley dnc)
(ncShelleyToAllegra dnc)
(ncAllegraToMary dnc)
(error "mkProtocolInfoCardano: ProtocolTransitionParamsShelleyBased StandardAlonzo")

shelleyPraosNonce :: ShelleyConfig -> Shelley.Spec.Nonce
shelleyPraosNonce sCfg = Shelley.Spec.Nonce (Cardano.Crypto.Hash.Class.castHash . unGenesisHashShelley $ scGenesisHash sCfg)
Expand Down
Loading