diff --git a/cabal.project b/cabal.project index ba8625124e7..25f27a41674 100644 --- a/cabal.project +++ b/cabal.project @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -203,3 +222,7 @@ constraints: package comonad flags: -test-doctests + +allow-newer: + monoidal-containers:aeson, + size-based:template-haskell diff --git a/cardano-api/src/Cardano/Api/Block.hs b/cardano-api/src/Cardano/Api/Block.hs index ebc5fea447d..4c716185c72 100644 --- a/cardano-api/src/Cardano/Api/Block.hs +++ b/cardano-api/src/Cardano/Api/Block.hs @@ -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 @@ -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)) @@ -198,6 +203,9 @@ fromConsensusBlock CardanoMode = BlockInMode (ShelleyBlock ShelleyBasedEraMary b') MaryEraInCardanoMode + Consensus.BlockAlonzo b' -> + BlockInMode (ShelleyBlock ShelleyBasedEraAlonzo b') + AlonzoEraInCardanoMode -- ---------------------------------------------------------------------------- -- Block headers @@ -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 diff --git a/cardano-api/src/Cardano/Api/Eras.hs b/cardano-api/src/Cardano/Api/Eras.hs index b25687f757c..2e0881377fa 100644 --- a/cardano-api/src/Cardano/Api/Eras.hs +++ b/cardano-api/src/Cardano/Api/Eras.hs @@ -12,6 +12,7 @@ module Cardano.Api.Eras , ShelleyEra , AllegraEra , MaryEra + , AlonzoEra , CardanoEra(..) , IsCardanoEra(..) , AnyCardanoEra(..) @@ -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 @@ -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 @@ -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 -- @@ -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) @@ -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 testEquality ShelleyEra ShelleyEra = Just Refl testEquality AllegraEra AllegraEra = Just Refl testEquality MaryEra MaryEra = Just Refl + testEquality AlonzoEra AlonzoEra = Just Refl testEquality _ _ = Nothing @@ -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 @@ -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 @@ -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) @@ -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 @@ -288,6 +303,7 @@ cardanoEraStyle ByronEra = LegacyByronEra cardanoEraStyle ShelleyEra = ShelleyBasedEra ShelleyBasedEraShelley cardanoEraStyle AllegraEra = ShelleyBasedEra ShelleyBasedEraAllegra cardanoEraStyle MaryEra = ShelleyBasedEra ShelleyBasedEraMary +cardanoEraStyle AlonzoEra = ShelleyBasedEra ShelleyBasedEraAlonzo -- ---------------------------------------------------------------------------- @@ -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 + diff --git a/cardano-api/src/Cardano/Api/Fees.hs b/cardano-api/src/Cardano/Api/Fees.hs index 00397a1945b..358da79d595 100644 --- a/cardano-api/src/Cardano/Api/Fees.hs +++ b/cardano-api/src/Cardano/Api/Fees.hs @@ -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 {} --TODO: in the Byron case the per-byte is non-integral, would need different diff --git a/cardano-api/src/Cardano/Api/LedgerState.hs b/cardano-api/src/Cardano/Api/LedgerState.hs index 2ba25cb54f7..1ea2bd01ef4 100644 --- a/cardano-api/src/Cardano/Api/LedgerState.hs +++ b/cardano-api/src/Cardano/Api/LedgerState.hs @@ -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 @@ -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 @@ -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 = @@ -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 @@ -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) diff --git a/cardano-api/src/Cardano/Api/Modes.hs b/cardano-api/src/Cardano/Api/Modes.hs index 5f284855cb1..66296a978c5 100644 --- a/cardano-api/src/Cardano/Api/Modes.hs +++ b/cardano-api/src/Cardano/Api/Modes.hs @@ -50,9 +50,9 @@ import qualified Ouroboros.Consensus.Cardano.ByronHFC as Consensus (ByronBlockHF import Ouroboros.Consensus.HardFork.Combinator as Consensus (EraIndex (..), eraIndexSucc, eraIndexZero) import Ouroboros.Consensus.Shelley.Eras (StandardAllegra, StandardMary, StandardShelley) -import qualified Ouroboros.Consensus.Shelley.ShelleyHFC as Consensus (ShelleyBlockHFC) import qualified Ouroboros.Consensus.Shelley.Ledger as Consensus import Ouroboros.Consensus.Shelley.Protocol (StandardCrypto) +import qualified Ouroboros.Consensus.Shelley.ShelleyHFC as Consensus (ShelleyBlockHFC) import qualified Cardano.Chain.Slotting as Byron (EpochSlots (..)) @@ -145,6 +145,7 @@ data EraInMode era mode where ShelleyEraInCardanoMode :: EraInMode ShelleyEra CardanoMode AllegraEraInCardanoMode :: EraInMode AllegraEra CardanoMode MaryEraInCardanoMode :: EraInMode MaryEra CardanoMode + AlonzoEraInCardanoMode :: EraInMode AlonzoEra CardanoMode deriving instance Show (EraInMode era mode) @@ -156,6 +157,7 @@ eraInModeToEra ByronEraInCardanoMode = ByronEra eraInModeToEra ShelleyEraInCardanoMode = ShelleyEra eraInModeToEra AllegraEraInCardanoMode = AllegraEra eraInModeToEra MaryEraInCardanoMode = MaryEra +eraInModeToEra AlonzoEraInCardanoMode = AlonzoEra data AnyEraInMode mode where @@ -173,6 +175,7 @@ anyEraInModeToAnyEra (AnyEraInMode erainmode) = ShelleyEraInCardanoMode -> AnyCardanoEra ShelleyEra AllegraEraInCardanoMode -> AnyCardanoEra AllegraEra MaryEraInCardanoMode -> AnyCardanoEra MaryEra + AlonzoEraInCardanoMode -> AnyCardanoEra AlonzoEra -- | The consensus-mode-specific parameters needed to connect to a local node @@ -234,6 +237,8 @@ eraIndex2 = eraIndexSucc eraIndex1 eraIndex3 :: Consensus.EraIndex (x3 : x2 : x1 : x0 : xs) eraIndex3 = eraIndexSucc eraIndex2 +eraIndex4 :: Consensus.EraIndex (x4 : x3 : x2 : x1 : x0 : xs) +eraIndex4 = eraIndexSucc eraIndex3 toConsensusEraIndex :: ConsensusBlockForMode mode ~ Consensus.HardForkBlock xs => EraInMode era mode @@ -245,6 +250,7 @@ toConsensusEraIndex ByronEraInCardanoMode = eraIndex0 toConsensusEraIndex ShelleyEraInCardanoMode = eraIndex1 toConsensusEraIndex AllegraEraInCardanoMode = eraIndex2 toConsensusEraIndex MaryEraInCardanoMode = eraIndex3 +toConsensusEraIndex AlonzoEraInCardanoMode = eraIndex4 fromConsensusEraIndex :: ConsensusBlockForMode mode ~ Consensus.HardForkBlock xs @@ -285,3 +291,6 @@ fromConsensusEraIndex CardanoMode = fromShelleyEraIndex fromShelleyEraIndex (Consensus.EraIndex (S (S (S (Z (K ())))))) = AnyEraInMode MaryEraInCardanoMode + fromShelleyEraIndex (Consensus.EraIndex (S (S (S (S (Z (K ()))))))) = + AnyEraInMode AlonzoEraInCardanoMode + diff --git a/cardano-api/src/Cardano/Api/Orphans.hs b/cardano-api/src/Cardano/Api/Orphans.hs index 9d522303419..a9319746672 100644 --- a/cardano-api/src/Cardano/Api/Orphans.hs +++ b/cardano-api/src/Cardano/Api/Orphans.hs @@ -74,7 +74,7 @@ instance ToJSON Shelley.AccountState where instance ( Consensus.ShelleyBasedEra era , ToJSON (Core.TxOut era) , ToJSON (Core.PParams era) - , ToJSON (Shelley.PParamsDelta era) + , ToJSON (Core.PParamsDelta era) ) => ToJSON (Shelley.EpochState era) where toJSON eState = object [ "esAccountState" .= Shelley.esAccountState eState , "esSnapshots" .= Shelley.esSnapshots eState @@ -86,7 +86,7 @@ instance ( Consensus.ShelleyBasedEra era instance ( Consensus.ShelleyBasedEra era , ToJSON (Core.TxOut era) - , ToJSON (Shelley.PParamsDelta era) + , ToJSON (Core.PParamsDelta era) ) => ToJSON (Shelley.LedgerState era) where toJSON lState = object [ "utxoState" .= Shelley._utxoState lState , "delegationState" .= Shelley._delegationState lState @@ -94,7 +94,7 @@ instance ( Consensus.ShelleyBasedEra era instance ( Consensus.ShelleyBasedEra era , ToJSON (Core.TxOut era) - , ToJSON (Shelley.PParamsDelta era) + , ToJSON (Core.PParamsDelta era) ) => ToJSON (Shelley.UTxOState era) where toJSON utxoState = object [ "utxo" .= Shelley._utxo utxoState , "deposited" .= Shelley._deposited utxoState @@ -102,14 +102,14 @@ instance ( Consensus.ShelleyBasedEra era , "ppups" .= Shelley._ppups utxoState ] -instance ( ToJSON (Shelley.PParamsDelta era) +instance ( ToJSON (Core.PParamsDelta era) , Shelley.UsesPParams era ) => ToJSON (Shelley.PPUPState era) where toJSON ppUpState = object [ "proposals" .= Shelley.proposals ppUpState , "futureProposals" .= Shelley.futureProposals ppUpState ] -instance ( ToJSON (Shelley.PParamsDelta era) +instance ( ToJSON (Core.PParamsDelta era) , Shelley.UsesPParams era ) => ToJSON (Shelley.ProposedPPUpdates era) where toJSON (Shelley.ProposedPPUpdates ppUpdates) = toJSON $ Map.toList ppUpdates diff --git a/cardano-api/src/Cardano/Api/Protocol/Types.hs b/cardano-api/src/Cardano/Api/Protocol/Types.hs index 51cfa81be81..2d4e8b0bafc 100644 --- a/cardano-api/src/Cardano/Api/Protocol/Types.hs +++ b/cardano-api/src/Cardano/Api/Protocol/Types.hs @@ -20,15 +20,13 @@ import Cardano.Prelude import Cardano.Chain.Slotting (EpochSlots) -import Ouroboros.Consensus.Byron.Ledger (ByronBlock) import Ouroboros.Consensus.Cardano -import Ouroboros.Consensus.Cardano.Node import Ouroboros.Consensus.Cardano.Block import Ouroboros.Consensus.Cardano.ByronHFC (ByronBlockHFC) +import Ouroboros.Consensus.Cardano.Node import Ouroboros.Consensus.HardFork.Combinator.Embed.Unary -import Ouroboros.Consensus.Node.ProtocolInfo (ProtocolClientInfo(..), ProtocolInfo(..)) +import Ouroboros.Consensus.Node.ProtocolInfo (ProtocolClientInfo (..), ProtocolInfo (..)) import Ouroboros.Consensus.Node.Run (RunNode) -import Ouroboros.Consensus.Shelley.Ledger (ShelleyBlock) import Ouroboros.Consensus.Shelley.ShelleyHFC (ShelleyBlockHFC) import Ouroboros.Consensus.Util.IOLike (IOLike) @@ -52,33 +50,41 @@ instance IOLike m => Protocol m ByronBlockHFC where protocolInfo (ProtocolInfoArgsByron params) = inject $ protocolInfoByron params instance IOLike m => Protocol m (CardanoBlock StandardCrypto) where - data ProtocolInfoArgs m (CardanoBlock StandardCrypto) = ProtocolInfoArgsCardano - ProtocolParamsByron - (ProtocolParamsShelleyBased StandardShelley) - ProtocolParamsShelley - ProtocolParamsAllegra - ProtocolParamsMary - (ProtocolParamsTransition ByronBlock (ShelleyBlock StandardShelley)) - (ProtocolParamsTransition (ShelleyBlock StandardShelley) (ShelleyBlock StandardAllegra)) - (ProtocolParamsTransition (ShelleyBlock StandardAllegra) (ShelleyBlock StandardMary)) + data ProtocolInfoArgs m (CardanoBlock StandardCrypto) = + ProtocolInfoArgsCardano + ProtocolParamsByron + (ProtocolParamsShelleyBased StandardShelley) + ProtocolParamsShelley + ProtocolParamsAllegra + ProtocolParamsMary + ProtocolParamsAlonzo + (ProtocolTransitionParamsShelleyBased StandardShelley) + (ProtocolTransitionParamsShelleyBased StandardAllegra) + (ProtocolTransitionParamsShelleyBased StandardMary) + (ProtocolTransitionParamsShelleyBased StandardAlonzo) + protocolInfo (ProtocolInfoArgsCardano paramsByron paramsShelleyBased paramsShelley paramsAllegra paramsMary + paramsAlonzo paramsByronShelley paramsShelleyAllegra - paramsAllegraMary) = + paramsAllegraMary + paramsMaryAlonzo) = protocolInfoCardano paramsByron paramsShelleyBased paramsShelley paramsAllegra paramsMary + paramsAlonzo paramsByronShelley paramsShelleyAllegra paramsAllegraMary + paramsMaryAlonzo instance ProtocolClient ByronBlockHFC where data ProtocolClientInfoArgs ByronBlockHFC = diff --git a/cardano-api/src/Cardano/Api/ProtocolParameters.hs b/cardano-api/src/Cardano/Api/ProtocolParameters.hs index b54f0d2e37e..c4e85f7b4bd 100644 --- a/cardano-api/src/Cardano/Api/ProtocolParameters.hs +++ b/cardano-api/src/Cardano/Api/ProtocolParameters.hs @@ -66,8 +66,8 @@ import qualified Cardano.Binary as CBOR import qualified Cardano.Crypto.Hash.Class as Crypto import Cardano.Slotting.Slot (EpochNo, EpochSize (..)) +import qualified Cardano.Ledger.Core as Ledger import qualified Cardano.Ledger.Era as Ledger -import qualified Cardano.Ledger.Shelley.Constraints as Shelley import Ouroboros.Consensus.Shelley.Eras (StandardShelley) import Ouroboros.Consensus.Shelley.Protocol.Crypto (StandardCrypto) @@ -78,8 +78,8 @@ import qualified Shelley.Spec.Ledger.Keys as Shelley import qualified Shelley.Spec.Ledger.PParams as Shelley import Cardano.Api.Address -import Cardano.Api.Hash import Cardano.Api.HasTypeProxy +import Cardano.Api.Hash import Cardano.Api.KeysByron import Cardano.Api.KeysShelley import Cardano.Api.NetworkId @@ -88,7 +88,6 @@ import Cardano.Api.SerialiseTextEnvelope import Cardano.Api.StakePoolMetadata import Cardano.Api.TxMetadata import Cardano.Api.Value -import Cardano.Binary -- | The values of the set of /updateable/ protocol paramaters. At any @@ -479,7 +478,7 @@ instance HasTextEnvelope UpdateProposal where instance SerialiseAsCBOR UpdateProposal where serialiseToCBOR = CBOR.serializeEncoding' . toCBOR . toShelleyUpdate @StandardShelley deserialiseFromCBOR _ bs = - fromShelleyUpdate @StandardShelley <$> decodeFull (LBS.fromStrict bs) + fromShelleyUpdate @StandardShelley <$> CBOR.decodeFull (LBS.fromStrict bs) makeShelleyUpdateProposal :: ProtocolParametersUpdate @@ -492,7 +491,7 @@ makeShelleyUpdateProposal params genesisKeyHashes = -- ---------------------------------------------------------------------------- --- Genesis paramaters +-- Genesis parameters -- data GenesisParameters = @@ -563,7 +562,7 @@ data GenesisParameters = -- toShelleyUpdate :: ( Ledger.Crypto ledgerera ~ StandardCrypto - , Shelley.PParamsDelta ledgerera + , Ledger.PParamsDelta ledgerera ~ Shelley.PParamsUpdate ledgerera ) => UpdateProposal -> Shelley.Update ledgerera @@ -573,7 +572,7 @@ toShelleyUpdate (UpdateProposal ppup epochno) = toShelleyProposedPPUpdates :: forall ledgerera. ( Ledger.Crypto ledgerera ~ StandardCrypto - , Shelley.PParamsDelta ledgerera + , Ledger.PParamsDelta ledgerera ~ Shelley.PParamsUpdate ledgerera ) => Map (Hash GenesisKey) ProtocolParametersUpdate @@ -636,7 +635,7 @@ toShelleyPParamsUpdate } fromShelleyUpdate :: ( Ledger.Crypto ledgerera ~ StandardCrypto - , Shelley.PParamsDelta ledgerera + , Ledger.PParamsDelta ledgerera ~ Shelley.PParamsUpdate ledgerera ) => Shelley.Update ledgerera -> UpdateProposal @@ -645,7 +644,7 @@ fromShelleyUpdate (Shelley.Update ppup epochno) = fromShelleyProposedPPUpdates :: ( Ledger.Crypto ledgerera ~ StandardCrypto - , Shelley.PParamsDelta ledgerera + , Ledger.PParamsDelta ledgerera ~ Shelley.PParamsUpdate ledgerera ) => Shelley.ProposedPPUpdates ledgerera diff --git a/cardano-api/src/Cardano/Api/Query.hs b/cardano-api/src/Cardano/Api/Query.hs index 27291647532..6af03722ff8 100644 --- a/cardano-api/src/Cardano/Api/Query.hs +++ b/cardano-api/src/Cardano/Api/Query.hs @@ -62,6 +62,7 @@ import qualified Ouroboros.Consensus.HardFork.Combinator.Degenerate as Consensus import qualified Ouroboros.Consensus.HardFork.History as History import qualified Ouroboros.Consensus.HardFork.History.Qry as Qry +import qualified Ouroboros.Consensus.Ledger.Query as Consensus import qualified Ouroboros.Consensus.Byron.Ledger as Consensus import Ouroboros.Consensus.Cardano.Block (StandardCrypto) import qualified Ouroboros.Consensus.Cardano.Block as Consensus @@ -73,7 +74,6 @@ import qualified Cardano.Chain.Update.Validation.Interface as Byron.Update import qualified Cardano.Ledger.Core as Core import qualified Cardano.Ledger.Era as Ledger -import qualified Cardano.Ledger.Shelley.Constraints as Shelley import qualified Shelley.Spec.Ledger.API as Shelley import qualified Shelley.Spec.Ledger.LedgerState as Shelley import qualified Shelley.Spec.Ledger.PParams as Shelley @@ -213,7 +213,7 @@ instance ( IsShelleyBasedEra era , ShelleyLedgerEra era ~ ledgerera , Consensus.ShelleyBasedEra ledgerera , ToJSON (Core.PParams ledgerera) - , ToJSON (Shelley.PParamsDelta ledgerera) + , ToJSON (Core.PParamsDelta ledgerera) , ToJSON (Core.TxOut ledgerera)) => ToJSON (DebugLedgerState era) where toJSON (DebugLedgerState newEpochS) = object [ "lastEpoch" .= Shelley.nesEL newEpochS , "blocksBefore" .= Shelley.nesBprev newEpochS @@ -255,6 +255,7 @@ fromUTxO eraConversion utxo = ShelleyBasedEraMary -> let Shelley.UTxO sUtxo = utxo in UTxO . Map.fromList . map (bimap fromShelleyTxIn (fromTxOut ShelleyBasedEraMary)) $ Map.toList sUtxo + ShelleyBasedEraAlonzo -> error "fromUTxO: Alonzo not implemented yet" fromShelleyPoolDistr :: Shelley.PoolDistr StandardCrypto -> Map (Hash StakePoolKey) Rational @@ -297,16 +298,24 @@ toConsensusQuery :: forall mode block result. => QueryInMode mode result -> Some (Consensus.Query block) toConsensusQuery (QueryCurrentEra CardanoModeIsMultiEra) = - Some (Consensus.QueryHardFork Consensus.GetCurrentEra) + Some $ Consensus.BlockQuery $ + Consensus.QueryHardFork + Consensus.GetCurrentEra toConsensusQuery (QueryInEra ByronEraInByronMode QueryByronUpdateState) = - Some (Consensus.DegenQuery Consensus.GetUpdateInterfaceState) + Some $ Consensus.BlockQuery $ + Consensus.DegenQuery + Consensus.GetUpdateInterfaceState toConsensusQuery (QueryEraHistory CardanoModeIsMultiEra) = - Some (Consensus.QueryHardFork Consensus.GetInterpreter) + Some $ Consensus.BlockQuery $ + Consensus.QueryHardFork + Consensus.GetInterpreter toConsensusQuery (QueryInEra ByronEraInCardanoMode QueryByronUpdateState) = - Some (Consensus.QueryIfCurrentByron Consensus.GetUpdateInterfaceState) + Some $ Consensus.BlockQuery $ + Consensus.QueryIfCurrentByron + Consensus.GetUpdateInterfaceState toConsensusQuery (QueryInEra erainmode (QueryInShelleyBasedEra era q)) = case erainmode of @@ -316,6 +325,7 @@ toConsensusQuery (QueryInEra erainmode (QueryInShelleyBasedEra era q)) = ShelleyEraInCardanoMode -> toConsensusQueryShelleyBased erainmode q AllegraEraInCardanoMode -> toConsensusQueryShelleyBased erainmode q MaryEraInCardanoMode -> toConsensusQueryShelleyBased erainmode q + AlonzoEraInCardanoMode -> error "toConsensusQuery: Alonzo not implemented yet" toConsensusQueryShelleyBased @@ -374,14 +384,19 @@ consensusQueryInEraInMode => modeblock ~ Consensus.HardForkBlock xs => Consensus.HardForkQueryResult xs result ~ result' => EraInMode era mode - -> Consensus.Query erablock result + -> Consensus.BlockQuery erablock result -> Consensus.Query modeblock result' -consensusQueryInEraInMode ByronEraInByronMode = Consensus.DegenQuery -consensusQueryInEraInMode ShelleyEraInShelleyMode = Consensus.DegenQuery -consensusQueryInEraInMode ByronEraInCardanoMode = Consensus.QueryIfCurrentByron -consensusQueryInEraInMode ShelleyEraInCardanoMode = Consensus.QueryIfCurrentShelley -consensusQueryInEraInMode AllegraEraInCardanoMode = Consensus.QueryIfCurrentAllegra -consensusQueryInEraInMode MaryEraInCardanoMode = Consensus.QueryIfCurrentMary +consensusQueryInEraInMode erainmode = + Consensus.BlockQuery + . case erainmode of + ByronEraInByronMode -> Consensus.DegenQuery + ShelleyEraInShelleyMode -> Consensus.DegenQuery + ByronEraInCardanoMode -> Consensus.QueryIfCurrentByron + ShelleyEraInCardanoMode -> Consensus.QueryIfCurrentShelley + AllegraEraInCardanoMode -> Consensus.QueryIfCurrentAllegra + MaryEraInCardanoMode -> Consensus.QueryIfCurrentMary + AlonzoEraInCardanoMode -> + error "consensusQueryInEraInMode: Alonzo not implemented yet" -- ---------------------------------------------------------------------------- @@ -396,27 +411,29 @@ fromConsensusQueryResult :: forall mode block result result'. -> result fromConsensusQueryResult (QueryEraHistory CardanoModeIsMultiEra) q' r' = case q' of - Consensus.QueryHardFork Consensus.GetInterpreter -> EraHistory CardanoMode r' + Consensus.BlockQuery (Consensus.QueryHardFork Consensus.GetInterpreter) + -> EraHistory CardanoMode r' _ -> fromConsensusQueryResultMismatch fromConsensusQueryResult (QueryCurrentEra CardanoModeIsMultiEra) q' r' = case q' of - Consensus.QueryHardFork Consensus.GetCurrentEra -> - anyEraInModeToAnyEra (fromConsensusEraIndex CardanoMode r') + Consensus.BlockQuery (Consensus.QueryHardFork Consensus.GetCurrentEra) + -> anyEraInModeToAnyEra (fromConsensusEraIndex CardanoMode r') _ -> fromConsensusQueryResultMismatch fromConsensusQueryResult (QueryInEra ByronEraInByronMode QueryByronUpdateState) q' r' = case (q', r') of - (Consensus.DegenQuery Consensus.GetUpdateInterfaceState, - Consensus.DegenQueryResult r'') -> - Right (ByronUpdateState r'') + (Consensus.BlockQuery (Consensus.DegenQuery Consensus.GetUpdateInterfaceState), + Consensus.DegenQueryResult r'') + -> Right (ByronUpdateState r'') fromConsensusQueryResult (QueryInEra ByronEraInCardanoMode QueryByronUpdateState) q' r' = case q' of - Consensus.QueryIfCurrentByron Consensus.GetUpdateInterfaceState -> - bimap fromConsensusEraMismatch ByronUpdateState r' + Consensus.BlockQuery + (Consensus.QueryIfCurrentByron Consensus.GetUpdateInterfaceState) + -> bimap fromConsensusEraMismatch ByronUpdateState r' _ -> fromConsensusQueryResultMismatch fromConsensusQueryResult (QueryInEra ByronEraInByronMode @@ -426,8 +443,10 @@ fromConsensusQueryResult (QueryInEra ByronEraInByronMode fromConsensusQueryResult (QueryInEra ShelleyEraInShelleyMode (QueryInShelleyBasedEra _era q)) q' r' = case (q', r') of - (Consensus.DegenQuery q'', Consensus.DegenQueryResult r'') -> - Right (fromConsensusQueryResultShelleyBased ShelleyBasedEraShelley q q'' r'') + (Consensus.BlockQuery (Consensus.DegenQuery q''), + Consensus.DegenQueryResult r'') + -> Right (fromConsensusQueryResultShelleyBased + ShelleyBasedEraShelley q q'' r'') fromConsensusQueryResult (QueryInEra ByronEraInCardanoMode (QueryInShelleyBasedEra era _)) _ _ = @@ -436,41 +455,47 @@ fromConsensusQueryResult (QueryInEra ByronEraInCardanoMode fromConsensusQueryResult (QueryInEra ShelleyEraInCardanoMode (QueryInShelleyBasedEra _era q)) q' r' = case q' of - Consensus.QueryIfCurrentShelley q'' -> - bimap fromConsensusEraMismatch - (fromConsensusQueryResultShelleyBased ShelleyBasedEraShelley q q'') - r' + Consensus.BlockQuery (Consensus.QueryIfCurrentShelley q'') + -> bimap fromConsensusEraMismatch + (fromConsensusQueryResultShelleyBased + ShelleyBasedEraShelley q q'') + r' _ -> fromConsensusQueryResultMismatch fromConsensusQueryResult (QueryInEra AllegraEraInCardanoMode (QueryInShelleyBasedEra _era q)) q' r' = case q' of - Consensus.QueryIfCurrentAllegra q'' -> - bimap fromConsensusEraMismatch - (fromConsensusQueryResultShelleyBased ShelleyBasedEraAllegra q q'') - r' + Consensus.BlockQuery (Consensus.QueryIfCurrentAllegra q'') + -> bimap fromConsensusEraMismatch + (fromConsensusQueryResultShelleyBased + ShelleyBasedEraAllegra q q'') + r' _ -> fromConsensusQueryResultMismatch fromConsensusQueryResult (QueryInEra MaryEraInCardanoMode (QueryInShelleyBasedEra _era q)) q' r' = case q' of - Consensus.QueryIfCurrentMary q'' -> - bimap fromConsensusEraMismatch - (fromConsensusQueryResultShelleyBased ShelleyBasedEraMary q q'') - r' + Consensus.BlockQuery (Consensus.QueryIfCurrentMary q'') + -> bimap fromConsensusEraMismatch + (fromConsensusQueryResultShelleyBased + ShelleyBasedEraMary q q'') + r' _ -> fromConsensusQueryResultMismatch +fromConsensusQueryResult (QueryInEra AlonzoEraInCardanoMode + (QueryInShelleyBasedEra _ _)) _ _ = + error "fromConsensusQueryResult: Alonzo not implemented yet" fromConsensusQueryResultShelleyBased :: forall era ledgerera result result'. ShelleyLedgerEra era ~ ledgerera - => Shelley.PParams ledgerera ~ Core.PParams ledgerera - => Shelley.PParamsDelta ledgerera ~ Shelley.PParamsUpdate ledgerera + => Core.PParams ledgerera ~ Shelley.PParams ledgerera + => Core.PParamsDelta ledgerera ~ Shelley.PParamsUpdate ledgerera => Consensus.ShelleyBasedEra ledgerera => Ledger.Crypto ledgerera ~ Consensus.StandardCrypto => ShelleyBasedEra era -> QueryInShelleyBasedEra era result - -> Consensus.Query (Consensus.ShelleyBlock ledgerera) result' + -> Consensus.BlockQuery (Consensus.ShelleyBlock ledgerera) result' -> result' -> result fromConsensusQueryResultShelleyBased _ QueryChainPoint q' point = diff --git a/cardano-api/src/Cardano/Api/Script.hs b/cardano-api/src/Cardano/Api/Script.hs index af3898a7198..e9bedbf710a 100644 --- a/cardano-api/src/Cardano/Api/Script.hs +++ b/cardano-api/src/Cardano/Api/Script.hs @@ -465,6 +465,7 @@ instance IsShelleyBasedEra era => HasTextEnvelope (ScriptInEra era) where ShelleyBasedEraShelley -> "ScriptInEra ShelleyEra" ShelleyBasedEraAllegra -> "ScriptInEra AllegraEra" ShelleyBasedEraMary -> "ScriptInEra MaryEra" + ShelleyBasedEraAlonzo -> "ScriptInEra AlonzoEra" -- | Check if a given script language is supported in a given era, and if so @@ -769,6 +770,8 @@ fromShelleyBasedScript era script = ScriptInEra SimpleScriptV2InMary $ SimpleScript SimpleScriptV2 $ fromAllegraTimelock TimeLocksInSimpleScriptV2 script + ShelleyBasedEraAlonzo -> + error "fromShelleyBasedScript: Alonzo era not implemented yet" -- | Conversion for the 'Shelley.MultiSig' language used by the Shelley era. @@ -924,6 +927,7 @@ instance IsCardanoEra era => FromJSON (ScriptInEra era) where Just s' -> ScriptInEra SimpleScriptV1InMary (SimpleScript SimpleScriptV1 s') + AlonzoEra -> error "JSON support for Plutus scripts not implemented" instance IsSimpleScriptLanguage lang => FromJSON (SimpleScript lang) where parseJSON = parseSimpleScript simpleScriptVersion diff --git a/cardano-api/src/Cardano/Api/Tx.hs b/cardano-api/src/Cardano/Api/Tx.hs index 7f816b0fb53..da7dcc57f3a 100644 --- a/cardano-api/src/Cardano/Api/Tx.hs +++ b/cardano-api/src/Cardano/Api/Tx.hs @@ -134,6 +134,7 @@ instance Eq (Tx era) where ShelleyBasedEraShelley -> txA == txB ShelleyBasedEraAllegra -> txA == txB ShelleyBasedEraMary -> txA == txB + ShelleyBasedEraAlonzo -> txA == txB (==) ByronTx{} (ShelleyTx era _) = case era of {} @@ -159,6 +160,11 @@ instance Show (Tx era) where showString "ShelleyTx ShelleyBasedEraMary " . showsPrec 11 tx + showsPrec p (ShelleyTx ShelleyBasedEraAlonzo tx) = + showParen (p >= 11) $ + showString "ShelleyTx ShelleyBasedEraAlonzo " + . showsPrec 11 tx + instance HasTypeProxy era => HasTypeProxy (Tx era) where data AsType (Tx era) = AsTx (AsType era) @@ -181,6 +187,8 @@ instance IsCardanoEra era => SerialiseAsCBOR (Tx era) where ShelleyBasedEraShelley -> serialiseShelleyBasedTx tx ShelleyBasedEraAllegra -> serialiseShelleyBasedTx tx ShelleyBasedEraMary -> serialiseShelleyBasedTx tx + ShelleyBasedEraAlonzo -> + error "serialiseShelleyBasedTx: Alonzo era not implemented yet" deserialiseFromCBOR _ bs = case cardanoEra :: CardanoEra era of @@ -196,6 +204,7 @@ instance IsCardanoEra era => SerialiseAsCBOR (Tx era) where (ShelleyTx ShelleyBasedEraAllegra) bs MaryEra -> deserialiseShelleyBasedTx (ShelleyTx ShelleyBasedEraMary) bs + AlonzoEra -> error "deserialiseFromCBOR: Alonzo era not implemented yet" -- | The serialisation format for the different Shelley-based eras are not the -- same, but they can be handled generally with one overloaded implementation. @@ -218,6 +227,7 @@ instance IsCardanoEra era => HasTextEnvelope (Tx era) where ShelleyEra -> "TxSignedShelley" AllegraEra -> "Tx AllegraEra" MaryEra -> "Tx MaryEra" + AlonzoEra -> "Tx AlonzoEra" data KeyWitness era where @@ -248,6 +258,8 @@ instance Eq (KeyWitness era) where ShelleyBasedEraShelley -> wA == wB ShelleyBasedEraAllegra -> wA == wB ShelleyBasedEraMary -> wA == wB + ShelleyBasedEraAlonzo -> + error "Eq (KeyWitness era): Alonzo not implemented yet" (==) (ShelleyKeyWitness era wA) (ShelleyKeyWitness _ wB) = @@ -255,6 +267,8 @@ instance Eq (KeyWitness era) where ShelleyBasedEraShelley -> wA == wB ShelleyBasedEraAllegra -> wA == wB ShelleyBasedEraMary -> wA == wB + ShelleyBasedEraAlonzo -> + error "Eq (KeyWitness era): Alonzo not implemented yet" (==) _ _ = False @@ -282,6 +296,9 @@ instance Show (KeyWitness era) where showString "ShelleyBootstrapWitness ShelleyBasedEraMary " . showsPrec 11 tx + showsPrec _ (ShelleyBootstrapWitness ShelleyBasedEraAlonzo _) = + error "Show (KeyWitness era): Alonzo era not implemented yet" + showsPrec p (ShelleyKeyWitness ShelleyBasedEraShelley tx) = showParen (p >= 11) $ showString "ShelleyKeyWitness ShelleyBasedEraShelley " @@ -297,6 +314,9 @@ instance Show (KeyWitness era) where showString "ShelleyKeyWitness ShelleyBasedEraMary " . showsPrec 11 tx + showsPrec _ (ShelleyKeyWitness ShelleyBasedEraAlonzo _) = + error "Show (KeyWitness era): Alonzo era not implemented yet" + instance HasTypeProxy era => HasTypeProxy (KeyWitness era) where data AsType (KeyWitness era) = AsKeyWitness (AsType era) @@ -320,6 +340,8 @@ instance IsCardanoEra era => SerialiseAsCBOR (KeyWitness era) where ShelleyBasedEraShelley -> encodeShelleyBasedKeyWitness wit ShelleyBasedEraAllegra -> encodeShelleyBasedKeyWitness wit ShelleyBasedEraMary -> encodeShelleyBasedKeyWitness wit + ShelleyBasedEraAlonzo -> + error "serialiseToCBOR: Alonzo era not implemented yet" serialiseToCBOR (ShelleyBootstrapWitness era wit) = CBOR.serializeEncoding' $ @@ -327,6 +349,9 @@ instance IsCardanoEra era => SerialiseAsCBOR (KeyWitness era) where ShelleyBasedEraShelley -> encodeShelleyBasedBootstrapWitness wit ShelleyBasedEraAllegra -> encodeShelleyBasedBootstrapWitness wit ShelleyBasedEraMary -> encodeShelleyBasedBootstrapWitness wit + ShelleyBasedEraAlonzo -> + error "serialiseToCBOR: Alonzo era not implemented yet" + deserialiseFromCBOR _ bs = case cardanoEra :: CardanoEra era of @@ -337,6 +362,7 @@ instance IsCardanoEra era => SerialiseAsCBOR (KeyWitness era) where ShelleyEra -> decodeShelleyBasedWitness ShelleyBasedEraShelley bs AllegraEra -> decodeShelleyBasedWitness ShelleyBasedEraAllegra bs MaryEra -> decodeShelleyBasedWitness ShelleyBasedEraMary bs + AlonzoEra -> error "decodeShelleyBasedWitness: Alonzo era not implemented yet" encodeShelleyBasedKeyWitness :: ToCBOR w => w -> CBOR.Encoding @@ -372,6 +398,7 @@ instance IsCardanoEra era => HasTextEnvelope (KeyWitness era) where ShelleyEra -> "TxWitnessShelley" AllegraEra -> "TxWitness AllegraEra" MaryEra -> "TxWitness MaryEra" + AlonzoEra -> "TxWitness AlonzoEra" pattern Tx :: Ledger.Era era => TxBody era -> [KeyWitness era] -> Tx era @@ -391,6 +418,8 @@ getTxBody (ShelleyTx era tx) = ShelleyBasedEraShelley -> getShelleyTxBody tx ShelleyBasedEraAllegra -> getShelleyTxBody tx ShelleyBasedEraMary -> getShelleyTxBody tx + ShelleyBasedEraAlonzo -> + error "getShelleyTxBody: Alonzo era not implemented yet" where getShelleyTxBody :: forall ledgerera. ShelleyLedgerEra era ~ ledgerera @@ -423,6 +452,8 @@ getTxWitnesses (ShelleyTx era tx) = ShelleyBasedEraShelley -> getShelleyTxWitnesses tx ShelleyBasedEraAllegra -> getShelleyTxWitnesses tx ShelleyBasedEraMary -> getShelleyTxWitnesses tx + ShelleyBasedEraAlonzo -> + error "getShelleyTxWitnesses: Alonzo era not implementd yet" where getShelleyTxWitnesses :: forall ledgerera. Ledger.Crypto ledgerera ~ StandardCrypto @@ -458,6 +489,8 @@ makeSignedTransaction witnesses (ShelleyTxBody era txbody txscripts txmetadata) ShelleyBasedEraShelley -> makeShelleySignedTransaction txbody ShelleyBasedEraAllegra -> makeShelleySignedTransaction txbody ShelleyBasedEraMary -> makeShelleySignedTransaction txbody + ShelleyBasedEraAlonzo -> + error "makeSignedTransaction: Alonzo era not implemented yet" where makeShelleySignedTransaction :: forall ledgerera. ShelleyLedgerEra era ~ ledgerera @@ -545,6 +578,8 @@ makeShelleyBootstrapWitness nwOrAddr (ShelleyTxBody era txbody _ _) sk = makeShelleyBasedBootstrapWitness era nwOrAddr txbody sk ShelleyBasedEraMary -> makeShelleyBasedBootstrapWitness era nwOrAddr txbody sk + ShelleyBasedEraAlonzo -> + error "makeShelleyBootstrapWitness: Alonzo era not implemented yet" makeShelleyBasedBootstrapWitness :: forall era. (Ledger.HashAnnotated @@ -653,6 +688,8 @@ makeShelleyKeyWitness (ShelleyTxBody era txbody _ _) = ShelleyBasedEraShelley -> makeShelleyBasedKeyWitness txbody ShelleyBasedEraAllegra -> makeShelleyBasedKeyWitness txbody ShelleyBasedEraMary -> makeShelleyBasedKeyWitness txbody + ShelleyBasedEraAlonzo -> + error "makeShelleyKeyWitness: Alonzo era not implemented yet" where makeShelleyBasedKeyWitness :: Shelley.ShelleyBased ledgerera => ShelleyLedgerEra era ~ ledgerera diff --git a/cardano-api/src/Cardano/Api/TxBody.hs b/cardano-api/src/Cardano/Api/TxBody.hs index 3093ee33c14..3347e623d86 100644 --- a/cardano-api/src/Cardano/Api/TxBody.hs +++ b/cardano-api/src/Cardano/Api/TxBody.hs @@ -231,6 +231,7 @@ getTxId (ShelleyTxBody era tx _ _) = ShelleyBasedEraShelley -> getTxIdShelley tx ShelleyBasedEraAllegra -> getTxIdShelley tx ShelleyBasedEraMary -> getTxIdShelley tx + ShelleyBasedEraAlonzo -> error "getTxId: Alonzo not implemented yet" where getTxIdShelley :: Ledger.Crypto (ShelleyLedgerEra era) ~ StandardCrypto => Ledger.UsesTxBody (ShelleyLedgerEra era) @@ -366,6 +367,7 @@ fromTxOut shelleyBasedEra' ledgerTxOut = in TxOut (fromShelleyAddr addr) (TxOutValue MultiAssetInMaryEra (fromMaryValue value)) + ShelleyBasedEraAlonzo -> error "fromTxOut: Alonzo not implemented yet" -- ---------------------------------------------------------------------------- -- Era-dependent transaction body features @@ -412,6 +414,8 @@ multiAssetSupportedInEra ByronEra = Left AdaOnlyInByronEra multiAssetSupportedInEra ShelleyEra = Left AdaOnlyInShelleyEra multiAssetSupportedInEra AllegraEra = Left AdaOnlyInAllegraEra multiAssetSupportedInEra MaryEra = Right MultiAssetInMaryEra +multiAssetSupportedInEra AlonzoEra = + error "multiAssetSupportedInEra: Alonzo not implemented yet" -- | A representation of whether the era requires explicitly specified fees in @@ -448,6 +452,7 @@ txFeesExplicitInEra ByronEra = Left TxFeesImplicitInByronEra txFeesExplicitInEra ShelleyEra = Right TxFeesExplicitInShelleyEra txFeesExplicitInEra AllegraEra = Right TxFeesExplicitInAllegraEra txFeesExplicitInEra MaryEra = Right TxFeesExplicitInMaryEra +txFeesExplicitInEra AlonzoEra = error "txFeesExplicitInEra: Alonzo not implemented yet" -- | A representation of whether the era supports transactions with an upper @@ -472,6 +477,8 @@ validityUpperBoundSupportedInEra ByronEra = Nothing validityUpperBoundSupportedInEra ShelleyEra = Just ValidityUpperBoundInShelleyEra validityUpperBoundSupportedInEra AllegraEra = Just ValidityUpperBoundInAllegraEra validityUpperBoundSupportedInEra MaryEra = Just ValidityUpperBoundInMaryEra +validityUpperBoundSupportedInEra AlonzoEra = + error "validityUpperBoundSupportedInEra: Alonzo not implemented yet" -- | A representation of whether the era supports transactions having /no/ @@ -499,6 +506,8 @@ validityNoUpperBoundSupportedInEra ByronEra = Just ValidityNoUpperBoundInByron validityNoUpperBoundSupportedInEra ShelleyEra = Nothing validityNoUpperBoundSupportedInEra AllegraEra = Just ValidityNoUpperBoundInAllegraEra validityNoUpperBoundSupportedInEra MaryEra = Just ValidityNoUpperBoundInMaryEra +validityNoUpperBoundSupportedInEra AlonzoEra = + error "validityNoUpperBoundSupportedInEra: Alonzo not implemented yet" -- | A representation of whether the era supports transactions with a lower @@ -522,7 +531,8 @@ validityLowerBoundSupportedInEra ByronEra = Nothing validityLowerBoundSupportedInEra ShelleyEra = Nothing validityLowerBoundSupportedInEra AllegraEra = Just ValidityLowerBoundInAllegraEra validityLowerBoundSupportedInEra MaryEra = Just ValidityLowerBoundInMaryEra - +validityLowerBoundSupportedInEra AlonzoEra = + error "validityLowerBoundSupportedInEra: Alonzo not implemented yet" -- | A representation of whether the era supports transaction metadata. -- @@ -543,6 +553,8 @@ txMetadataSupportedInEra ByronEra = Nothing txMetadataSupportedInEra ShelleyEra = Just TxMetadataInShelleyEra txMetadataSupportedInEra AllegraEra = Just TxMetadataInAllegraEra txMetadataSupportedInEra MaryEra = Just TxMetadataInMaryEra +txMetadataSupportedInEra AlonzoEra = + error "txMetadataSupportedInEra: Alonzo not implemented yet" -- | A representation of whether the era supports auxiliary scripts in @@ -564,6 +576,8 @@ auxScriptsSupportedInEra ByronEra = Nothing auxScriptsSupportedInEra ShelleyEra = Nothing auxScriptsSupportedInEra AllegraEra = Just AuxScriptsInAllegraEra auxScriptsSupportedInEra MaryEra = Just AuxScriptsInMaryEra +auxScriptsSupportedInEra AlonzoEra = + error "auxScriptsSupportedInEra: Alonzo not supported yet" -- | A representation of whether the era supports withdrawals from reward @@ -587,6 +601,8 @@ withdrawalsSupportedInEra ByronEra = Nothing withdrawalsSupportedInEra ShelleyEra = Just WithdrawalsInShelleyEra withdrawalsSupportedInEra AllegraEra = Just WithdrawalsInAllegraEra withdrawalsSupportedInEra MaryEra = Just WithdrawalsInMaryEra +withdrawalsSupportedInEra AlonzoEra = + error "withdrawalsSupportedInEra: Alonzo not implemented yet" -- | A representation of whether the era supports 'Certificate's embedded in @@ -609,6 +625,8 @@ certificatesSupportedInEra ByronEra = Nothing certificatesSupportedInEra ShelleyEra = Just CertificatesInShelleyEra certificatesSupportedInEra AllegraEra = Just CertificatesInAllegraEra certificatesSupportedInEra MaryEra = Just CertificatesInMaryEra +certificatesSupportedInEra AlonzoEra = + error "certificatesSupportedInEra: Alonzo not implemented yet" -- | A representation of whether the era supports 'UpdateProposal's embedded in @@ -633,6 +651,8 @@ updateProposalSupportedInEra ByronEra = Nothing updateProposalSupportedInEra ShelleyEra = Just UpdateProposalInShelleyEra updateProposalSupportedInEra AllegraEra = Just UpdateProposalInAllegraEra updateProposalSupportedInEra MaryEra = Just UpdateProposalInMaryEra +updateProposalSupportedInEra AlonzoEra = + error "updateProposalSupportedInEra: Alonzo not implemented yet" -- ---------------------------------------------------------------------------- @@ -885,6 +905,8 @@ instance Eq (TxBody era) where ShelleyBasedEraMary -> txbodyA == txbodyB && txscriptsA == txscriptsB && txmetadataA == txmetadataB + ShelleyBasedEraAlonzo -> + error "Eq (TxBody era): Alonzo not implemented yet" (==) ByronTxBody{} (ShelleyTxBody era _ _ _) = case era of {} @@ -930,6 +952,18 @@ instance Show (TxBody era) where . showsPrec 11 txmetadata ) + showsPrec p (ShelleyTxBody ShelleyBasedEraAlonzo + txbody txscripts txmetadata) = + showParen (p >= 11) + ( showString "ShelleyTxBody ShelleyBasedEraMary " + . showsPrec 11 txbody + . showChar ' ' + . showsPrec 11 txscripts + . showChar ' ' + . showsPrec 11 txmetadata + ) + + instance HasTypeProxy era => HasTypeProxy (TxBody era) where data AsType (TxBody era) = AsTxBody (AsType era) proxyToAsType _ = AsTxBody (proxyToAsType (Proxy :: Proxy era)) @@ -957,6 +991,7 @@ instance IsCardanoEra era => SerialiseAsCBOR (TxBody era) where ShelleyBasedEraShelley -> serialiseShelleyBasedTxBody txbody txscripts txmetadata ShelleyBasedEraAllegra -> serialiseShelleyBasedTxBody txbody txscripts txmetadata ShelleyBasedEraMary -> serialiseShelleyBasedTxBody txbody txscripts txmetadata + ShelleyBasedEraAlonzo -> error "serialiseToCBOR: Alonzo era not implemented yet" deserialiseFromCBOR _ bs = case cardanoEra :: CardanoEra era of @@ -974,6 +1009,7 @@ instance IsCardanoEra era => SerialiseAsCBOR (TxBody era) where (ShelleyTxBody ShelleyBasedEraAllegra) bs MaryEra -> deserialiseShelleyBasedTxBody (ShelleyTxBody ShelleyBasedEraMary) bs + AlonzoEra -> error "deserialiseFromCBOR: Alonzo era not implemented yet" -- | The serialisation format for the different Shelley-based eras are not the -- same, but they can be handled generally with one overloaded implementation. @@ -1023,6 +1059,7 @@ instance IsCardanoEra era => HasTextEnvelope (TxBody era) where ShelleyEra -> "TxUnsignedShelley" AllegraEra -> "TxBodyAllegra" MaryEra -> "TxBodyMary" + AlonzoEra -> "TxBodyAlonzo" -- ---------------------------------------------------------------------------- @@ -1128,7 +1165,7 @@ checkAuxiliaryDataHash era body mAux = ShelleyBasedEraMary -> Mary.adHash' body == (Ledger.hashAuxiliaryData @StandardMary <$> mAux') - + ShelleyBasedEraAlonzo -> error "checkAuxiliaryDataHash: Alonzo era not implemented yet" fromLedgerTxIns :: ShelleyBasedEra era @@ -1141,6 +1178,7 @@ fromLedgerTxIns era body = ShelleyBasedEraShelley -> toList $ Shelley._inputs body ShelleyBasedEraAllegra -> toList $ Allegra.inputs' body ShelleyBasedEraMary -> toList $ Mary.inputs' body + ShelleyBasedEraAlonzo -> error "fromLedgerTxIns: Alonzo era not implemented yet" ] @@ -1152,6 +1190,7 @@ fromLedgerTxOuts era body = ShelleyBasedEraShelley -> toList $ Shelley._outputs body ShelleyBasedEraAllegra -> toList $ Allegra.outputs' body ShelleyBasedEraMary -> toList $ Mary.outputs' body + ShelleyBasedEraAlonzo -> error "fromLedgerTxOuts: Alonzo era not implemented yet" fromLedgerTxFee @@ -1167,7 +1206,7 @@ fromLedgerTxFee era body = ShelleyBasedEraMary -> TxFeeExplicit TxFeesExplicitInMaryEra $ fromShelleyLovelace $ Mary.txfee' body - + ShelleyBasedEraAlonzo -> error "fromLedgerTxFee: Alonzo era not implemented yet" fromLedgerTxValidityRange :: ShelleyBasedEra era @@ -1200,6 +1239,7 @@ fromLedgerTxValidityRange era body = ) where Mary.ValidityInterval{invalidBefore, invalidHereafter} = Mary.vldt' body + ShelleyBasedEraAlonzo -> error "fromLedgerTxValidityRange: Alonzo era not implemented yet" fromLedgerAuxiliaryData @@ -1216,7 +1256,8 @@ fromLedgerAuxiliaryData ShelleyBasedEraMary (Mary.AuxiliaryData ms ss) = ( fromShelleyMetadata ms , fromShelleyBasedScript ShelleyBasedEraMary <$> toList ss ) - +fromLedgerAuxiliaryData ShelleyBasedEraAlonzo _ = + error "fromLedgerAuxiliaryData: Alonzo era not implemented yet" fromLedgerTxAuxiliaryData :: ShelleyBasedEra era @@ -1250,6 +1291,7 @@ fromLedgerTxAuxiliaryData era (Just auxData) = [] -> TxAuxScriptsNone _ -> TxAuxScripts AuxScriptsInMaryEra ss ) + ShelleyBasedEraAlonzo -> error "fromLedgerTxAuxiliaryData: Alonzo era not implemented yet" where (ms, ss) = fromLedgerAuxiliaryData era auxData @@ -1280,7 +1322,7 @@ fromLedgerTxWithdrawals era body = TxWithdrawals WithdrawalsInMaryEra $ fromShelleyWithdrawal withdrawals where withdrawals = Mary.wdrls' body - + ShelleyBasedEraAlonzo -> error "fromLedgerTxWithdrawals: Alonzo era not implemented yet" fromLedgerTxCertificates :: ShelleyBasedEra era @@ -1315,7 +1357,7 @@ fromLedgerTxCertificates era body = ViewTx where certificates = Mary.certs' body - + ShelleyBasedEraAlonzo -> error "fromLedgerTxCertificates: Alonzo era not implemented yet" fromLedgerTxUpdateProposal :: ShelleyBasedEra era @@ -1338,6 +1380,7 @@ fromLedgerTxUpdateProposal era body = SNothing -> TxUpdateProposalNone SJust p -> TxUpdateProposal UpdateProposalInMaryEra $ fromShelleyUpdate p + ShelleyBasedEraAlonzo -> error "fromLedgerTxUpdateProposal: Alonzo era not implemented yet" fromLedgerTxMintValue @@ -1356,6 +1399,7 @@ fromLedgerTxMintValue era body = pure $ TxMintValue MultiAssetInMaryEra (fromMaryValue mint) ViewTx where mint = Mary.mint' body + ShelleyBasedEraAlonzo -> error "fromLedgerTxMintValue: Alonzo era not implemented yet" makeByronTransactionBody :: TxBodyContent BuildTx ByronEra @@ -1604,6 +1648,9 @@ makeShelleyTransactionBody era@ShelleyBasedEraMary TxAuxScriptsNone -> [] TxAuxScripts _ ss' -> ss' +makeShelleyTransactionBody ShelleyBasedEraAlonzo _ = + error "makeShelleyTransactionBody: Alonzo era not implemented yet" + data SimpleScriptInEra era where SimpleScriptInEra :: ScriptLanguageInEra lang era -> SimpleScriptVersion lang diff --git a/cardano-api/src/Cardano/Api/TxInMode.hs b/cardano-api/src/Cardano/Api/TxInMode.hs index 5c3a2fde8f7..f2e3e4bdf50 100644 --- a/cardano-api/src/Cardano/Api/TxInMode.hs +++ b/cardano-api/src/Cardano/Api/TxInMode.hs @@ -102,6 +102,13 @@ toConsensusGenTx (TxInMode (ShelleyTx _ tx) MaryEraInCardanoMode) = where tx' = Consensus.mkShelleyTx tx +toConsensusGenTx (TxInMode (ShelleyTx _ _tx) AlonzoEraInCardanoMode) = + Consensus.HardForkGenTx (Consensus.OneEraGenTx (S (S (S (S (Z tx')))))) + where + tx' = error "toConsensusGenTx: Alonzo not implemented yet" + -- Consensus needs to expose a function that can make create Alonzo txs + + -- ---------------------------------------------------------------------------- -- Transaction validation errors in the context of eras and consensus modes @@ -147,6 +154,12 @@ instance Show (TxValidationError era) where . showsPrec 11 err ) + showsPrec p (ShelleyTxValidationError ShelleyBasedEraAlonzo err) = + showParen (p >= 11) + ( showString "ShelleyTxValidationError ShelleyBasedEraAlonzo " + . showsPrec 11 err + ) + -- | A 'TxValidationError' in one of the eras supported by a given protocol -- mode. @@ -198,6 +211,11 @@ fromConsensusApplyTxErr CardanoMode (Consensus.ApplyTxErrMary err) = (ShelleyTxValidationError ShelleyBasedEraMary err) MaryEraInCardanoMode +fromConsensusApplyTxErr CardanoMode (Consensus.ApplyTxErrAlonzo err) = + TxValidationErrorInMode + (ShelleyTxValidationError ShelleyBasedEraAlonzo err) + AlonzoEraInCardanoMode + fromConsensusApplyTxErr CardanoMode (Consensus.ApplyTxErrWrongEra err) = TxValidationEraMismatch err diff --git a/cardano-api/test/Test/Cardano/Api/Typed/Gen.hs b/cardano-api/test/Test/Cardano/Api/Typed/Gen.hs index f331fc894ab..9bd4a5b403a 100644 --- a/cardano-api/test/Test/Cardano/Api/Typed/Gen.hs +++ b/cardano-api/test/Test/Cardano/Api/Typed/Gen.hs @@ -353,6 +353,7 @@ genTxOutValue era = ShelleyEra -> TxOutAdaOnly AdaOnlyInShelleyEra <$> genLovelace AllegraEra -> TxOutAdaOnly AdaOnlyInAllegraEra <$> genLovelace MaryEra -> TxOutValue MultiAssetInMaryEra <$> genValueForTxOut + AlonzoEra -> panic "genTxOutValue: Alonzo not implemented yet" genTxOut :: CardanoEra era -> Gen (TxOut era) genTxOut era = @@ -367,6 +368,7 @@ genTxOut era = TxOut <$> (shelleyAddressInEra <$> genAddressShelley) <*> genTxOutValue era + AlonzoEra -> panic "genTxOut: Alonzo not implemented yet" genTtl :: Gen SlotNo genTtl = genSlotNo @@ -379,6 +381,7 @@ genTxValidityLowerBound era = ShelleyEra -> pure TxValidityNoLowerBound AllegraEra -> TxValidityLowerBound ValidityLowerBoundInAllegraEra <$> genTtl MaryEra -> TxValidityLowerBound ValidityLowerBoundInMaryEra <$> genTtl + AlonzoEra -> panic "genTxValidityLowerBound: Alonzo not implemented yet " -- TODO: Accept a range for generating ttl. genTxValidityUpperBound :: CardanoEra era -> Gen (TxValidityUpperBound era) @@ -388,6 +391,7 @@ genTxValidityUpperBound era = ShelleyEra -> TxValidityUpperBound ValidityUpperBoundInShelleyEra <$> genTtl AllegraEra -> TxValidityUpperBound ValidityUpperBoundInAllegraEra <$> genTtl MaryEra -> TxValidityUpperBound ValidityUpperBoundInMaryEra <$> genTtl + AlonzoEra -> panic "genTxValidityUpperBound: Alonzo not implemented yet " genTxValidityRange :: CardanoEra era @@ -416,6 +420,7 @@ genTxMetadataInEra era = [ pure TxMetadataNone , TxMetadataInEra TxMetadataInMaryEra <$> genTxMetadata ] + AlonzoEra -> panic "genTxMetadataInEra: Alonzo not implemented yet" genTxAuxScripts :: CardanoEra era -> Gen (TxAuxScripts era) genTxAuxScripts era = @@ -428,6 +433,7 @@ genTxAuxScripts era = MaryEra -> TxAuxScripts AuxScriptsInMaryEra <$> Gen.list (Range.linear 0 3) (genScriptInEra MaryEra) + AlonzoEra -> panic "genTxAuxScripts: Alonzo not implemented yet" genTxWithdrawals :: CardanoEra era -> Gen (TxWithdrawals BuildTx era) genTxWithdrawals era = @@ -448,6 +454,7 @@ genTxWithdrawals era = [ pure TxWithdrawalsNone , pure (TxWithdrawals WithdrawalsInMaryEra mempty) -- TODO: Generate withdrawals ] + AlonzoEra -> panic "genTxWithdrawals: Alonzo not implemented yet" genTxCertificates :: CardanoEra era -> Gen (TxCertificates BuildTx era) genTxCertificates era = @@ -468,6 +475,7 @@ genTxCertificates era = [ pure TxCertificatesNone , pure (TxCertificates CertificatesInMaryEra mempty $ BuildTxWith mempty) -- TODO: Generate certificates ] + AlonzoEra -> panic "genTxCertificates: Alonzo not implemented yet" genTxUpdateProposal :: CardanoEra era -> Gen (TxUpdateProposal era) genTxUpdateProposal era = @@ -488,6 +496,7 @@ genTxUpdateProposal era = [ pure TxUpdateProposalNone , pure (TxUpdateProposal UpdateProposalInMaryEra emptyUpdateProposal) -- TODO: Generate proposals ] + AlonzoEra -> panic "genTxUpdateProposal: Alonzo not implemented yet" where emptyUpdateProposal :: UpdateProposal emptyUpdateProposal = UpdateProposal Map.empty (EpochNo 0) @@ -503,6 +512,8 @@ genTxMintValue era = [ pure TxMintNone , TxMintValue MultiAssetInMaryEra <$> genValueForMinting <*> return (BuildTxWith mempty) ] + AlonzoEra -> panic "genTxMintValue: Alonzo not implemented yet" + genTxBodyContent :: CardanoEra era -> Gen (TxBodyContent BuildTx era) genTxBodyContent era = do @@ -537,6 +548,7 @@ genTxFee era = ShelleyEra -> TxFeeExplicit TxFeesExplicitInShelleyEra <$> genLovelace AllegraEra -> TxFeeExplicit TxFeesExplicitInAllegraEra <$> genLovelace MaryEra -> TxFeeExplicit TxFeesExplicitInMaryEra <$> genLovelace + AlonzoEra -> panic "genTxFee: Alonzo not implemented yet" genTxBody :: CardanoEra era -> Gen (TxBody era) genTxBody era = @@ -553,6 +565,7 @@ genTxBody era = case res of Left err -> fail (show err) -- TODO: Render function for TxBodyError Right txBody -> pure txBody + AlonzoEra -> panic "genTxBody: Alonzo not implemented yet" genTx :: forall era. CardanoEra era -> Gen (Tx era) genTx era = @@ -567,6 +580,7 @@ genTx era = ShelleyEra -> genShelleyBasedWitnessList AllegraEra -> genShelleyBasedWitnessList MaryEra -> genShelleyBasedWitnessList + AlonzoEra -> panic "genTx: Alonzo not implemented yet" genShelleyBasedWitnessList :: IsShelleyBasedEra era => Gen [KeyWitness era] genShelleyBasedWitnessList = do diff --git a/cardano-cli/cardano-cli.cabal b/cardano-cli/cardano-cli.cabal index 4bf82063e54..b8c61d0093a 100644 --- a/cardano-cli/cardano-cli.cabal +++ b/cardano-cli/cardano-cli.cabal @@ -109,6 +109,7 @@ library , cardano-crypto , cardano-crypto-class , cardano-crypto-wrapper + , cardano-ledger-alonzo , cardano-ledger-byron , cardano-ledger-core , cardano-ledger-shelley-ma @@ -129,6 +130,8 @@ library , ouroboros-consensus-shelley , ouroboros-network , parsec + , plutus-core + , plutus-ledger-api , shelley-spec-ledger , small-steps , split diff --git a/cardano-cli/src/Cardano/CLI/Run/Friendly.hs b/cardano-cli/src/Cardano/CLI/Run/Friendly.hs index a25aa4f0901..05fd2c42188 100644 --- a/cardano-cli/src/Cardano/CLI/Run/Friendly.hs +++ b/cardano-cli/src/Cardano/CLI/Run/Friendly.hs @@ -18,7 +18,7 @@ import Data.Yaml.Pretty (defConfig, encodePretty, setConfCompare) import Cardano.Api as Api (AddressInEra (..), AddressTypeInEra (ByronAddressInAnyEra, ShelleyAddressInEra), CardanoEra, - ShelleyBasedEra (ShelleyBasedEraAllegra, ShelleyBasedEraMary, ShelleyBasedEraShelley), + ShelleyBasedEra (ShelleyBasedEraAllegra, ShelleyBasedEraAlonzo, ShelleyBasedEraMary, ShelleyBasedEraShelley), ShelleyEra, TxBody, serialiseAddress) import Cardano.Api.Byron (TxBody (ByronTxBody)) import Cardano.Api.Shelley (TxBody (ShelleyTxBody), fromShelleyAddr) @@ -50,6 +50,8 @@ friendlyTxBody era txbody = addAuxData aux $ friendlyTxBodyAllegra body ShelleyTxBody ShelleyBasedEraMary body _scripts aux -> addAuxData aux $ friendlyTxBodyMary body + ShelleyTxBody ShelleyBasedEraAlonzo _ _ _ -> + panic "friendlyTxBody: Alonzo not implemented yet" addAuxData :: Show a => Maybe a -> Object -> Object addAuxData = HashMap.insert "auxiliary data" . maybe Null (toJSON . textShow) diff --git a/cardano-cli/src/Cardano/CLI/Shelley/Orphans.hs b/cardano-cli/src/Cardano/CLI/Shelley/Orphans.hs index 9652a5399a9..be86cc27f78 100644 --- a/cardano-cli/src/Cardano/CLI/Shelley/Orphans.hs +++ b/cardano-cli/src/Cardano/CLI/Shelley/Orphans.hs @@ -4,6 +4,7 @@ {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} +{-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE TypeFamilies #-} @@ -15,20 +16,27 @@ module Cardano.CLI.Shelley.Orphans () where import Cardano.Prelude +import Control.Monad import Control.SetAlgebra as SetAlgebra import Data.Aeson +import qualified Data.Aeson as Aeson +import Data.Aeson.Types (toJSONKeyText) import qualified Data.ByteString.Base16 as Base16 +import qualified Data.ByteString.Lazy as LBS import qualified Data.ByteString.Short as SBS +import qualified Data.Map.Strict as Map +import qualified Data.Text as Text import qualified Data.Text.Encoding as Text import Cardano.Api.Orphans () import Cardano.Crypto.Hash.Class as Crypto +import Cardano.Ledger.Alonzo.Language (Language) import Ouroboros.Consensus.Byron.Ledger.Block (ByronHash (..)) import Ouroboros.Consensus.HardFork.Combinator (OneEraHash (..)) -import Ouroboros.Consensus.Shelley.Ledger.Block (ShelleyHash (..)) import Ouroboros.Consensus.Shelley.Eras (StandardCrypto) +import Ouroboros.Consensus.Shelley.Ledger.Block (ShelleyHash (..)) import Ouroboros.Network.Block (BlockNo (..), HeaderHash, Tip (..)) import Cardano.Ledger.AuxiliaryData (AuxiliaryDataHash (..)) @@ -45,6 +53,16 @@ import Shelley.Spec.Ledger.TxBody (TxId (..)) import qualified Cardano.Ledger.Mary.Value as Ledger.Mary +import qualified Cardano.Ledger.Alonzo.Language as Alonzo +import qualified Cardano.Ledger.Alonzo.Scripts as Alonzo +import Cardano.Ledger.Alonzo.Translation (AlonzoGenesis (..)) +import qualified Cardano.Ledger.Alonzo.Translation as Alonzo + +import qualified PlutusCore.Evaluation.Machine.ExBudgeting as Plutus +import qualified PlutusCore.Evaluation.Machine.ExBudgetingDefaults as Plutus + +import Data.MemoBytes (MemoBytes) + instance ToJSON (OneEraHash xs) where toJSON = toJSON . Text.decodeLatin1 @@ -95,3 +113,116 @@ deriving newtype instance ToJSON (Ledger.Mary.PolicyID StandardCrypto) instance (ToJSONKey k, ToJSON v) => ToJSON (SetAlgebra.BiMap v k v) where toJSON = toJSON . SetAlgebra.forwards -- to normal Map + + + + +-- We defer parsing of the cost model so that we can +-- read it as a filepath. This is to reduce further pollution +-- of the genesis file. +instance FromJSON Alonzo.AlonzoGenesis where + parseJSON = + withObject "Alonzo Genesis" $ \o -> do + adaPerUTxOWord <- 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 Plutus.extractModelParams Plutus.defaultCostModel of + Just m -> + return Alonzo.AlonzoGenesis { + adaPerUTxOWord, + costmdls = Map.singleton Alonzo.PlutusV1 (Alonzo.CostModel m), + prices, + maxTxExUnits, + maxBlockExUnits, + maxValSize, + collateralPercentage, + maxCollateralInputs + } + Nothing -> fail "Failed to extract the cost model params from Plutus.defaultCostModel" + Just costmdls -> + return Alonzo.AlonzoGenesis { + adaPerUTxOWord, + costmdls, + prices, + maxTxExUnits, + maxBlockExUnits, + maxValSize, + collateralPercentage, + maxCollateralInputs + } + + +-- We don't render the cost model so that we can +-- render it later in 'AlonzoGenWrapper' as a filepath +-- and keep the cost model (which is chunky) as a separate file. +instance ToJSON AlonzoGenesis where + toJSON v = object + [ "adaPerUTxOWord" .= adaPerUTxOWord v + , "costModels" .= costmdls v + , "executionPrices" .= prices v + , "maxTxExUnits" .= maxTxExUnits v + , "maxBlockExUnits" .= maxBlockExUnits v + , "maxValueSize" .= maxValSize v + , "collateralPercentage" .= collateralPercentage v + , "maxCollateralInputs" .= maxCollateralInputs v + ] + +instance ToJSON Alonzo.ExUnits +deriving instance FromJSON Alonzo.ExUnits + +instance ToJSON Language where + toJSON Alonzo.PlutusV1 = Aeson.String "PlutusV1" + +instance FromJSON Language where + parseJSON v = + case v of + Aeson.String "PlutusV1" -> return Alonzo.PlutusV1 + wrong -> fail $ "Error decoding Language. \ + \Expected a JSON string but got: " <> show wrong + +instance ToJSON Alonzo.CostModel +instance FromJSON Alonzo.CostModel + +instance FromJSON (Data.MemoBytes.MemoBytes (Map Text Integer)) +instance ToJSON (Data.MemoBytes.MemoBytes (Map Text Integer)) + + +instance ToJSONKey Language where + toJSONKey = toJSONKeyText (Text.decodeLatin1 . LBS.toStrict . encode) + +instance FromJSONKey Language where + fromJSONKey = FromJSONKeyText parseLang + where + parseLang :: Text -> Language + parseLang lang = + case eitherDecode $ LBS.fromStrict $ Text.encodeUtf8 lang of + Left err -> panic $ Text.pack err + Right lang' -> lang' + + + +instance ToJSON Alonzo.Prices +deriving instance FromJSON Alonzo.Prices + +instance ToJSON SBS.ShortByteString where + toJSON = Aeson.String + . Text.decodeLatin1 + . Base16.encode + . SBS.fromShort + + +instance FromJSON SBS.ShortByteString where + parseJSON v = case v of + Aeson.String b16 -> + case Base16.decode $ Text.encodeUtf8 b16 of + Right decoded -> return $ SBS.toShort decoded + Left err -> fail err + wrong -> fail $ "Error decoding ShortByteString. \ + \Expected a JSON string but got: " <> show wrong diff --git a/cardano-cli/src/Cardano/CLI/Shelley/Run/Genesis.hs b/cardano-cli/src/Cardano/CLI/Shelley/Run/Genesis.hs index b4f49b0236d..f98d217c70d 100644 --- a/cardano-cli/src/Cardano/CLI/Shelley/Run/Genesis.hs +++ b/cardano-cli/src/Cardano/CLI/Shelley/Run/Genesis.hs @@ -10,6 +10,7 @@ module Cardano.CLI.Shelley.Run.Genesis ( ShelleyGenesisCmdError(..) , readShelleyGenesis + , readAlonzoGenesis , renderShelleyGenesisCmdError , runGenesisCmd ) where @@ -17,6 +18,7 @@ module Cardano.CLI.Shelley.Run.Genesis import Cardano.Prelude import Prelude (id) +import Data.Aeson import qualified Data.Aeson as Aeson import Data.Aeson.Encode.Pretty (encodePretty) import qualified Data.Binary.Get as Bin @@ -59,17 +61,26 @@ import Ouroboros.Consensus.Shelley.Eras (StandardShelley) import Ouroboros.Consensus.Shelley.Node (ShelleyGenesisStaking (..)) import Ouroboros.Consensus.Shelley.Protocol (StandardCrypto) +import qualified Cardano.Ledger.Alonzo.Language as Alonzo +import qualified Cardano.Ledger.Alonzo.Scripts as Alonzo +import Cardano.Ledger.Alonzo.Translation (AlonzoGenesis (..)) +import qualified Cardano.Ledger.Alonzo.Translation as Alonzo +import Cardano.Ledger.Coin (Coin (..)) import qualified Shelley.Spec.Ledger.API as Ledger import qualified Shelley.Spec.Ledger.BaseTypes as Ledger -import Cardano.Ledger.Coin (Coin (..)) import qualified Shelley.Spec.Ledger.Keys as Ledger import qualified Shelley.Spec.Ledger.PParams as Shelley +-- TODO: Remove me, cli should not depend directly on plutus repo. +import qualified PlutusCore.Evaluation.Machine.ExBudgeting as Plutus +import qualified PlutusCore.Evaluation.Machine.ExBudgetingDefaults as Plutus + import Cardano.Ledger.Era () import Cardano.CLI.Helpers (textShow) import Cardano.CLI.Shelley.Commands import Cardano.CLI.Shelley.Key +import Cardano.CLI.Shelley.Orphans () import Cardano.CLI.Shelley.Parsers (renderTxIn) import Cardano.CLI.Shelley.Run.Address import Cardano.CLI.Shelley.Run.Node (ShelleyNodeCmdError (..), renderShelleyNodeCmdError, @@ -95,6 +106,7 @@ data ShelleyGenesisCmdError | ShelleyGenesisCmdNodeCmdError !ShelleyNodeCmdError | ShelleyGenesisCmdPoolCmdError !ShelleyPoolCmdError | ShelleyGenesisCmdStakeAddressCmdError !ShelleyStakeAddressCmdError + | ShelleyGenesisCmdCostModelsError !FilePath deriving Show renderShelleyGenesisCmdError :: ShelleyGenesisCmdError -> Text @@ -129,7 +141,8 @@ renderShelleyGenesisCmdError err = ShelleyGenesisCmdNodeCmdError e -> renderShelleyNodeCmdError e ShelleyGenesisCmdPoolCmdError e -> renderShelleyPoolCmdError e ShelleyGenesisCmdStakeAddressCmdError e -> renderShelleyStakeAddressCmdError e - + ShelleyGenesisCmdCostModelsError fp -> + "Cost model is invalid: " <> Text.pack fp runGenesisCmd :: GenesisCmd -> ExceptT ShelleyGenesisCmdError IO () runGenesisCmd (GenesisKeyGenGenesis vk sk) = runGenesisKeyGenGenesis vk sk @@ -346,7 +359,11 @@ runGenesisCreate (GenesisDir rootdir) utxoAddrs <- readInitialFundAddresses utxodir network start <- maybe (SystemStart <$> getCurrentTimePlus30) pure mStart - let finalGenesis = updateTemplate start genDlgs mAmount utxoAddrs mempty (Lovelace 0) [] [] template + let finalGenesis = updateTemplate + -- Shelley genesis parameters + start genDlgs mAmount utxoAddrs mempty (Lovelace 0) [] [] template + -- Alono genesis parameters TODO: Parameterize + (Lovelace 10) (Lovelace 1, Lovelace 1) (1,1) (1,1) 1 1 1 writeShelleyGenesis (rootdir "genesis.json") finalGenesis where @@ -429,7 +446,11 @@ runGenesisCreateStaked (GenesisDir rootdir) let poolMap :: Map (Ledger.KeyHash Ledger.Staking StandardCrypto) (Ledger.PoolParams StandardCrypto) poolMap = Map.fromList $ mkDelegationMapEntry <$> delegations delegAddrs = dInitialUtxoAddr <$> delegations - finalGenesis = updateTemplate start genDlgs mNonDlgAmount nonDelegAddrs poolMap stDlgAmount delegAddrs stuffedUtxoAddrs template + finalGenesis = updateTemplate + -- Shelley genesis parameters + start genDlgs mNonDlgAmount nonDelegAddrs poolMap stDlgAmount delegAddrs stuffedUtxoAddrs template + -- Alonzo genesis parameters TODO: Parameterize + (Lovelace 10) (Lovelace 1, Lovelace 1) (1,1) (1,1) 1 1 1 writeShelleyGenesis (rootdir "genesis.json") finalGenesis liftIO $ Text.putStrLn $ mconcat $ @@ -712,29 +733,64 @@ updateTemplate -> [AddressInEra ShelleyEra] -> [AddressInEra ShelleyEra] -> ShelleyGenesis StandardShelley - -> ShelleyGenesis StandardShelley + -- Alonzo genesis parameters + -> Lovelace + -- ^ Ada per UTxO word + -> (Lovelace, Lovelace) + -- ^ Execution prices (memory, steps) + -> (Word64, Word64) + -- ^ Max Tx execution units + -> (Word64, Word64) + -- ^ Max block execution units + -> Natural + -- ^ Max value size + -> Natural + -- ^ Collateral percentage + -> Natural + -- ^ Max collateral inputs + -> (ShelleyGenesis StandardShelley, Alonzo.AlonzoGenesis) updateTemplate (SystemStart start) genDelegMap mAmountNonDeleg utxoAddrsNonDeleg poolSpecs (Lovelace amountDeleg) utxoAddrsDeleg stuffedUtxoAddrs - template = - template - { sgSystemStart = start - , sgMaxLovelaceSupply = fromIntegral $ nonDelegCoin + delegCoin - , sgGenDelegs = shelleyDelKeys - , sgInitialFunds = Map.fromList - [ (toShelleyAddr addr, toShelleyLovelace v) - | (addr, v) <- - distribute nonDelegCoin utxoAddrsNonDeleg ++ - distribute delegCoin utxoAddrsDeleg ++ - mkStuffedUtxo stuffedUtxoAddrs ] - , sgStaking = - ShelleyGenesisStaking - { sgsPools = Map.fromList - [ (Ledger._poolId poolParams, poolParams) - | poolParams <- Map.elems poolSpecs ] - , sgsStake = Ledger._poolId <$> poolSpecs + template adaPerUtxoWrd' (exMem,exStep) (maxTxMem, maxTxStep) + (maxBlkMem, maxBlkStep) maxValSize' collPercent maxColInputs = do + + let shelleyGenesis = template + { sgSystemStart = start + , sgMaxLovelaceSupply = fromIntegral $ nonDelegCoin + delegCoin + , sgGenDelegs = shelleyDelKeys + , sgInitialFunds = Map.fromList + [ (toShelleyAddr addr, toShelleyLovelace v) + | (addr, v) <- + distribute nonDelegCoin utxoAddrsNonDeleg ++ + distribute delegCoin utxoAddrsDeleg ++ + mkStuffedUtxo stuffedUtxoAddrs ] + , sgStaking = + ShelleyGenesisStaking + { sgsPools = Map.fromList + [ (Ledger._poolId poolParams, poolParams) + | poolParams <- Map.elems poolSpecs ] + , sgsStake = Ledger._poolId <$> poolSpecs + } } - } + cModel = case Plutus.extractModelParams Plutus.defaultCostModel of + Just m -> + if Alonzo.validateCostModelParams m + then Map.singleton Alonzo.PlutusV1 $ Alonzo.CostModel m + else panic "updateTemplate: Plutus.defaultCostModel is invalid" + + Nothing -> panic "updateTemplate: Could not extract cost model params from Plutus.defaultCostModel" + alonzoGenesis = AlonzoGenesis + { adaPerUTxOWord = toShelleyLovelace adaPerUtxoWrd' + , costmdls = cModel + , prices = Alonzo.Prices (toShelleyLovelace exMem) (toShelleyLovelace exStep) + , maxTxExUnits = Alonzo.ExUnits maxTxMem maxTxStep + , maxBlockExUnits = Alonzo.ExUnits maxBlkMem maxBlkStep + , maxValSize = maxValSize' + , collateralPercentage = collPercent + , maxCollateralInputs = maxColInputs + } + (shelleyGenesis, alonzoGenesis) where nonDelegCoin, delegCoin :: Integer nonDelegCoin = fromIntegral $ fromMaybe (sgMaxLovelaceSupply template) (unLovelace <$> mAmountNonDeleg) @@ -771,11 +827,22 @@ updateTemplate (SystemStart start) unLovelace :: Integral a => Lovelace -> a unLovelace (Lovelace coin) = fromIntegral coin -writeShelleyGenesis :: FilePath -> ShelleyGenesis StandardShelley -> ExceptT ShelleyGenesisCmdError IO () -writeShelleyGenesis fpath sg = - handleIOExceptT (ShelleyGenesisCmdGenesisFileError . FileIOError fpath) $ LBS.writeFile fpath (encodePretty sg) - - +-- We need to include Alonzo genesis parameters +writeShelleyGenesis + :: FilePath + -> (ShelleyGenesis StandardShelley, AlonzoGenesis) + -> ExceptT ShelleyGenesisCmdError IO () +writeShelleyGenesis fpath (sg, ag) = do + let sgValue = toJSON sg + agValue = toJSON ag + genesisCombined <- hoistEither $ combineAndEncode sgValue agValue + handleIOExceptT + (ShelleyGenesisCmdGenesisFileError . FileIOError fpath) + $ LBS.writeFile fpath genesisCombined + where + combineAndEncode :: Aeson.Value -> Aeson.Value -> Either ShelleyGenesisCmdError LBS.ByteString + combineAndEncode (Object sgO) (Object agO) = Right $ encodePretty $ sgO <> agO + combineAndEncode _sgWrong _agWrong = panic "combineAndEncode: Implement ShelleyGenesisCmdError constuctor" -- ------------------------------------------------------------------------------------------------- readGenDelegsMap :: FilePath -> FilePath @@ -919,3 +986,31 @@ runGenesisHashFile (GenesisFile fpath) = do let gh :: Crypto.Hash Crypto.Blake2b_256 ByteString gh = Crypto.hashWith id content liftIO $ Text.putStrLn (Crypto.hashToTextAsHex gh) + +-- +-- Alonzo genesis +-- + +-- | In order to avoid introducing a separate Alonzo genesis file, we +-- have added additional fields to the Shelley genesis that are required +-- when hardforking to Alonzo. Unfortunately the 'ShelleyGenesis' 'FromJSON' +-- instance exists in cardano-ledger-specs so we must duplicate code for now. + +readAlonzoGenesis + :: FilePath + -> ExceptT ShelleyGenesisCmdError IO Alonzo.AlonzoGenesis +readAlonzoGenesis fpath = do + readAndDecode + `catchError` \err -> + case err of + ShelleyGenesisCmdGenesisFileError (FileIOError _ ioe) + | isDoesNotExistError ioe -> panic "Shelley genesis file not found." + _ -> left err + + where + readAndDecode :: ExceptT ShelleyGenesisCmdError IO AlonzoGenesis + readAndDecode = do + lbs <- handleIOExceptT (ShelleyGenesisCmdGenesisFileError . FileIOError fpath) $ LBS.readFile fpath + firstExceptT (ShelleyGenesisCmdAesonDecodeError fpath . Text.pack) + . hoistEither $ Aeson.eitherDecode' lbs + diff --git a/cardano-cli/src/Cardano/CLI/Shelley/Run/Query.hs b/cardano-cli/src/Cardano/CLI/Shelley/Run/Query.hs index 8d05f05aefb..2d499bf6803 100644 --- a/cardano-cli/src/Cardano/CLI/Shelley/Run/Query.hs +++ b/cardano-cli/src/Cardano/CLI/Shelley/Run/Query.hs @@ -47,6 +47,7 @@ import Cardano.CLI.Types import Cardano.Binary (decodeFull) import Cardano.Crypto.Hash (hashToBytesAsHex) +import Cardano.Ledger.Coin import qualified Cardano.Ledger.Crypto as Crypto import qualified Cardano.Ledger.Era as Era import qualified Cardano.Ledger.Shelley.Constraints as Ledger @@ -56,7 +57,6 @@ import Ouroboros.Network.Block (Serialised (..)) import Ouroboros.Network.Protocol.LocalStateQuery.Type as LocalStateQuery (AcquireFailure (..)) import qualified Shelley.Spec.Ledger.API.Protocol as Ledger -import Cardano.Ledger.Coin import Shelley.Spec.Ledger.EpochBoundary import Shelley.Spec.Ledger.Keys (KeyHash (..), KeyRole (..)) import Shelley.Spec.Ledger.LedgerState hiding (_delegations) @@ -566,6 +566,7 @@ writeFilteredUTxOs shelleyBasedEra' mOutFile utxo = ShelleyBasedEraShelley -> writeUTxo fpath utxo ShelleyBasedEraAllegra -> writeUTxo fpath utxo ShelleyBasedEraMary -> writeUTxo fpath utxo + ShelleyBasedEraAlonzo -> writeUTxo fpath utxo where writeUTxo fpath utxo' = handleIOExceptT (ShelleyQueryCmdWriteFileError . FileIOError fpath) @@ -582,6 +583,7 @@ printFilteredUTxOs shelleyBasedEra' (UTxO utxo) = do mapM_ (printUtxo shelleyBasedEra') $ Map.toList utxo ShelleyBasedEraMary -> mapM_ (printUtxo shelleyBasedEra') $ Map.toList utxo + ShelleyBasedEraAlonzo -> panic "printFilteredUTxOs: Alonzo era not implemented yet" where title :: Text title = @@ -618,7 +620,7 @@ printUtxo shelleyBasedEra' txInOutTuple = , textShowN 6 index , " " <> printableValue value ] - + ShelleyBasedEraAlonzo -> panic "printUtxo: Alonzo era not implemented yet" where textShowN :: Show a => Int -> a -> Text textShowN len x = @@ -786,4 +788,6 @@ obtainLedgerEraClassConstraints obtainLedgerEraClassConstraints ShelleyBasedEraShelley f = f obtainLedgerEraClassConstraints ShelleyBasedEraAllegra f = f obtainLedgerEraClassConstraints ShelleyBasedEraMary f = f +obtainLedgerEraClassConstraints ShelleyBasedEraAlonzo _ = + panic "obtainLedgerEraClassConstraints: Alonzo era not implemented yet" diff --git a/cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs b/cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs index 8da0b28d214..aecb408dc7d 100644 --- a/cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs +++ b/cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs @@ -174,6 +174,7 @@ renderEra (AnyCardanoEra ByronEra) = "Byron" renderEra (AnyCardanoEra ShelleyEra) = "Shelley" renderEra (AnyCardanoEra AllegraEra) = "Allegra" renderEra (AnyCardanoEra MaryEra) = "Mary" +renderEra (AnyCardanoEra AlonzoEra) = "Alonzo" renderFeature :: TxFeature -> Text renderFeature TxFeatureShelleyAddresses = "Shelley addresses" diff --git a/cardano-node/app/cardano-node.hs b/cardano-node/app/cardano-node.hs index 759988e5420..264b177b577 100644 --- a/cardano-node/app/cardano-node.hs +++ b/cardano-node/app/cardano-node.hs @@ -18,7 +18,7 @@ import System.Info (arch, compilerName, compilerVersion, os) import Cardano.Node.Configuration.POM (PartialNodeConfiguration) import Cardano.Node.Handlers.TopLevel import Cardano.Node.Parsers (nodeCLIParser, parserHelpHeader, parserHelpOptions, - renderHelpDoc) + renderHelpDoc) import Cardano.Node.Run (runNode) main :: IO () diff --git a/cardano-node/cardano-node.cabal b/cardano-node/cardano-node.cabal index 83b92a69108..9076fdd49b5 100644 --- a/cardano-node/cardano-node.cabal +++ b/cardano-node/cardano-node.cabal @@ -66,11 +66,11 @@ library Cardano.Node.Handlers.TopLevel Cardano.Node.Orphans Cardano.Node.Protocol + Cardano.Node.Protocol.Alonzo Cardano.Node.Protocol.Byron Cardano.Node.Protocol.Cardano Cardano.Node.Protocol.Shelley Cardano.Node.Protocol.Types - Cardano.Node.Query Cardano.Node.Parsers Cardano.Node.Run Cardano.Node.STM @@ -103,6 +103,7 @@ library , cardano-config , cardano-crypto-class , cardano-crypto-wrapper + , cardano-ledger-alonzo , cardano-ledger-byron , cardano-ledger-core , cardano-ledger-shelley-ma @@ -135,10 +136,13 @@ library , ouroboros-consensus-shelley , ouroboros-network , ouroboros-network-framework + , plutus-core + , plutus-ledger-api , process , safe-exceptions , scientific , shelley-spec-ledger + , small-steps , stm , text , time diff --git a/cardano-node/src/Cardano/Node/Configuration/Logging.hs b/cardano-node/src/Cardano/Node/Configuration/Logging.hs index 3f822e4436c..a5d76a8b9ad 100644 --- a/cardano-node/src/Cardano/Node/Configuration/Logging.hs +++ b/cardano-node/src/Cardano/Node/Configuration/Logging.hs @@ -33,10 +33,10 @@ import qualified Data.Map as Map import Data.Text (pack) import Data.Time.Clock (UTCTime, getCurrentTime) import Data.Version (showVersion) -import qualified System.Remote.Monitoring as EKG +import System.Metrics.Counter (Counter) import System.Metrics.Gauge (Gauge) import System.Metrics.Label (Label) -import System.Metrics.Counter (Counter) +import qualified System.Remote.Monitoring as EKG import Cardano.BM.Backend.Aggregation (plugin) import Cardano.BM.Backend.EKGView (plugin) @@ -78,8 +78,8 @@ import qualified Shelley.Spec.Ledger.API as SL import Cardano.Api.Protocol.Types (BlockType (..), protocolInfo) import Cardano.Config.Git.Rev (gitRev) import Cardano.Node.Configuration.POM (NodeConfiguration (..), ncProtocol) -import Cardano.Node.Types import Cardano.Node.Protocol.Types (SomeConsensusProtocol (..)) +import Cardano.Node.Types import Cardano.Tracing.OrphanInstances.Common () import Paths_cardano_node (version) @@ -321,11 +321,12 @@ nodeBasicInfo nc (SomeConsensusProtocol whichP pForInfo) nodeStartTime' = do let DegenLedgerConfig cfgShelley = Consensus.configLedger cfg in getGenesisValues "Shelley" cfgShelley CardanoBlockType -> - let CardanoLedgerConfig cfgByron cfgShelley cfgAllegra cfgMary = Consensus.configLedger cfg + let CardanoLedgerConfig cfgByron cfgShelley cfgAllegra cfgMary cfgAlonzo = Consensus.configLedger cfg in getGenesisValuesByron cfg cfgByron ++ getGenesisValues "Shelley" cfgShelley ++ getGenesisValues "Allegra" cfgAllegra ++ getGenesisValues "Mary" cfgMary + ++ getGenesisValues "Alonzo" cfgAlonzo items = nub $ [ ("protocol", pack . protocolName $ ncProtocol nc) , ("version", pack . showVersion $ version) diff --git a/cardano-node/src/Cardano/Node/Configuration/POM.hs b/cardano-node/src/Cardano/Node/Configuration/POM.hs index 990073049a1..9f7422a9671 100644 --- a/cardano-node/src/Cardano/Node/Configuration/POM.hs +++ b/cardano-node/src/Cardano/Node/Configuration/POM.hs @@ -236,6 +236,9 @@ instance FromJSON PartialNodeConfiguration where npcTestMaryHardForkAtEpoch <- v .:? "TestMaryHardForkAtEpoch" npcTestMaryHardForkAtVersion <- v .:? "TestMaryHardForkAtVersion" + npcTestAlonzoHardForkAtEpoch <- v .:? "TestAlonzoHardForkAtEpoch" + npcTestAlonzoHardForkAtVersion <- v .:? "TestAlonzoHardForkAtVersion" + pure NodeHardForkProtocolConfiguration { npcTestShelleyHardForkAtEpoch, npcTestShelleyHardForkAtVersion, @@ -244,7 +247,10 @@ instance FromJSON PartialNodeConfiguration where npcTestAllegraHardForkAtVersion, npcTestMaryHardForkAtEpoch, - npcTestMaryHardForkAtVersion + npcTestMaryHardForkAtVersion, + + npcTestAlonzoHardForkAtEpoch, + npcTestAlonzoHardForkAtVersion } -- | Default configuration is mainnet diff --git a/cardano-node/src/Cardano/Node/Orphans.hs b/cardano-node/src/Cardano/Node/Orphans.hs index 9f678aba4b7..37461792175 100644 --- a/cardano-node/src/Cardano/Node/Orphans.hs +++ b/cardano-node/src/Cardano/Node/Orphans.hs @@ -1,4 +1,6 @@ - +{-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE StandaloneDeriving #-} {-# OPTIONS_GHC -Wno-orphans #-} @@ -8,11 +10,33 @@ module Cardano.Node.Orphans () where import Cardano.Prelude import Prelude (fail) -import Data.Aeson (FromJSON (..), Value (..)) +import Cardano.Api.Orphans () + +import Data.Aeson (eitherDecode) +import qualified Data.Aeson as Aeson +import Data.Aeson.Types +import qualified Data.ByteString.Base16 as Base16 +import qualified Data.ByteString.Lazy as LBS +import qualified Data.ByteString.Short as SBS +import qualified Data.Map.Strict as Map +import Data.MemoBytes (MemoBytes) import qualified Data.Text as Text +import qualified Data.Text.Encoding as Text import Cardano.BM.Data.Tracer (TracingVerbosity (..)) import qualified Cardano.Chain.Update as Update +import qualified Cardano.Ledger.Alonzo as Alonzo +import Cardano.Ledger.Alonzo.Language +import qualified Cardano.Ledger.Alonzo.Language as Alonzo +import qualified Cardano.Ledger.Alonzo.PParams as Alonzo +import qualified Cardano.Ledger.Alonzo.Scripts as Alonzo +import Cardano.Ledger.Alonzo.Translation as Alonzo +import Ouroboros.Consensus.Shelley.Protocol.Crypto (StandardCrypto) +import qualified Shelley.Spec.Ledger.CompactAddr as Shelley + +-- TODO: Remove me, cli should not depend directly on plutus repo. +import qualified PlutusCore.Evaluation.Machine.ExBudgeting as Plutus +import qualified PlutusCore.Evaluation.Machine.ExBudgetingDefaults as Plutus instance FromJSON TracingVerbosity where parseJSON (String str) = case str of @@ -26,8 +50,96 @@ instance FromJSON TracingVerbosity where deriving instance Show TracingVerbosity +deriving instance ToJSON (Alonzo.PParamsUpdate (Alonzo.AlonzoEra StandardCrypto)) +deriving instance ToJSON Alonzo.ExUnits +deriving instance ToJSON Alonzo.Prices +deriving instance ToJSON Alonzo.Language +deriving instance ToJSONKey Alonzo.Language + +instance ToJSON Alonzo.CostModel where + toJSON (Alonzo.CostModel m) = toJSON m + +deriving instance FromJSON Alonzo.Prices +deriving instance FromJSON Alonzo.ExUnits + +instance ToJSON (Shelley.CompactAddr StandardCrypto) where + toJSON = toJSON . Shelley.decompactAddr + +--Not currently needed, but if we do need it, this is the general instance. +--instance (ToJSON a, Ledger.Compactible a) => ToJSON (Ledger.CompactForm a) where +-- toJSON = toJSON . Ledger.fromCompact + instance FromJSON Update.ApplicationName where parseJSON (String x) = pure $ Update.ApplicationName x parseJSON invalid = fail $ "Parsing of application name failed due to type mismatch. " <> "Encountered: " <> show invalid + +-- We defer parsing of the cost model so that we can +-- read it as a filepath. This is to reduce further pollution +-- of the genesis file. +instance FromJSON Alonzo.AlonzoGenesis where + parseJSON = + withObject "Alonzo Genesis" $ \o -> do + adaPerUTxOWord <- 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 Plutus.extractModelParams Plutus.defaultCostModel of + Just m -> + return Alonzo.AlonzoGenesis { + adaPerUTxOWord, + costmdls = Map.singleton Alonzo.PlutusV1 (Alonzo.CostModel m), + prices, + maxTxExUnits, + maxBlockExUnits, + maxValSize, + collateralPercentage, + maxCollateralInputs + } + Nothing -> fail "Failed to extract the cost model params from Plutus.defaultCostModel" + Just costmdls -> + return Alonzo.AlonzoGenesis { + adaPerUTxOWord, + costmdls, + prices, + maxTxExUnits, + maxBlockExUnits, + maxValSize, + collateralPercentage, + maxCollateralInputs + } + +instance FromJSON Language where + parseJSON v = + case v of + Aeson.String "PlutusV1" -> return Alonzo.PlutusV1 + wrong -> fail $ "Error decoding Language. \ + \Expected a JSON string but got: " <> show wrong + +instance FromJSONKey Language where + fromJSONKey = FromJSONKeyText parseLang + where + parseLang :: Text -> Language + parseLang lang = + case eitherDecode $ LBS.fromStrict $ Text.encodeUtf8 lang of + Left err -> panic $ Text.pack err + Right lang' -> lang' + +instance FromJSON Alonzo.CostModel +instance FromJSON (Data.MemoBytes.MemoBytes (Map Text Integer)) + +instance FromJSON SBS.ShortByteString where + parseJSON v = case v of + Aeson.String b16 -> + case Base16.decode $ Text.encodeUtf8 b16 of + Right decoded -> return $ SBS.toShort decoded + Left err -> fail err + wrong -> fail $ "Error decoding ShortByteString. \ + \Expected a JSON string but got: " <> show wrong diff --git a/cardano-node/src/Cardano/Node/Protocol.hs b/cardano-node/src/Cardano/Node/Protocol.hs index f5454c9627b..e156b9f50eb 100644 --- a/cardano-node/src/Cardano/Node/Protocol.hs +++ b/cardano-node/src/Cardano/Node/Protocol.hs @@ -14,11 +14,11 @@ import Control.Monad.Trans.Except.Extra (firstExceptT) import Cardano.Node.Configuration.POM (NodeConfiguration (..)) import Cardano.Node.Types +import Cardano.Node.Orphans () import Cardano.Node.Protocol.Byron import Cardano.Node.Protocol.Cardano import Cardano.Node.Protocol.Shelley import Cardano.Node.Protocol.Types (SomeConsensusProtocol (..)) - ------------------------------------------------------------------------------ -- Conversions from configuration into specific protocols and their params -- diff --git a/cardano-node/src/Cardano/Node/Protocol/Alonzo.hs b/cardano-node/src/Cardano/Node/Protocol/Alonzo.hs new file mode 100644 index 00000000000..ce889b0bc04 --- /dev/null +++ b/cardano-node/src/Cardano/Node/Protocol/Alonzo.hs @@ -0,0 +1,82 @@ +{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE ScopedTypeVariables #-} + +module Cardano.Node.Protocol.Alonzo + ( AlonzoProtocolInstantiationError(..) + , renderAlonzoProtocolInstantiationError + -- * Reusable parts + , readAlonzoGenesis + ) where + +import Cardano.Prelude + +import Cardano.Api + +import Control.Monad.Trans.Except.Extra (firstExceptT, handleIOExceptT, hoistEither, left) +import qualified Data.Aeson as Aeson +import qualified Data.ByteString.Lazy as LBS +import qualified Data.Text as Text +import System.IO.Error (isDoesNotExistError) + +import qualified Cardano.Ledger.Alonzo.Translation as Alonzo + + +import Cardano.Node.Orphans () + +import Cardano.Tracing.OrphanInstances.HardFork () +import Cardano.Tracing.OrphanInstances.Shelley () + + +-- +-- Alonzo genesis +-- + +-- | In order to avoid introducing a separate Alonzo genesis file, we +-- have added additional fields to the Shelley genesis that are required +-- when hardforking to Alonzo. Unfortunately the 'ShelleyGenesis' 'FromJSON' +-- instance exists in cardano-ledger-specs so we must duplicate code for now. + +readAlonzoGenesis + :: FilePath + -> ExceptT AlonzoProtocolInstantiationError IO Alonzo.AlonzoGenesis +readAlonzoGenesis fpath = do + readAndDecode + `catchError` \err -> + case err of + AlonzoGenesisFileError (FileIOError _ ioe) + | isDoesNotExistError ioe -> left $ GenesisFileNotFound fpath + _ -> left err + where + readAndDecode :: ExceptT AlonzoProtocolInstantiationError IO Alonzo.AlonzoGenesis + readAndDecode = do + lbs <- handleIOExceptT (AlonzoGenesisFileError . FileIOError fpath) $ LBS.readFile fpath + firstExceptT (AlonzoGenesisDecodeError fpath . Text.pack) + . hoistEither $ Aeson.eitherDecode' lbs + + +data AlonzoProtocolInstantiationError + = InvalidCostModelError !FilePath + | CostModelExtractionError !FilePath + | AlonzoCostModelFileError !(FileError ()) + | AlonzoCostModelDecodeError !FilePath !Text + | AlonzoGenesisFileError !(FileError ()) + | AlonzoGenesisDecodeError !FilePath !Text + | GenesisFileNotFound !FilePath + deriving Show + +renderAlonzoProtocolInstantiationError :: AlonzoProtocolInstantiationError -> Text +renderAlonzoProtocolInstantiationError (InvalidCostModelError fp) = + "Invalid cost model: " <> Text.pack (show fp) +renderAlonzoProtocolInstantiationError (CostModelExtractionError fp) = + "Error extracting the cost model at: " <> Text.pack (show fp) +renderAlonzoProtocolInstantiationError (AlonzoCostModelFileError err) = + Text.pack $ displayError err +renderAlonzoProtocolInstantiationError (AlonzoCostModelDecodeError fp err) = + "Error decoding cost model at: " <> Text.pack (show fp) <> " Error: " <> err +renderAlonzoProtocolInstantiationError (AlonzoGenesisFileError err) = + Text.pack $ displayError err +renderAlonzoProtocolInstantiationError (AlonzoGenesisDecodeError fp err) = + "Error decoding genesis at: " <> Text.pack fp <> " Error: " <> err +renderAlonzoProtocolInstantiationError (GenesisFileNotFound fp) = + "Genesis file not found at: " <> Text.pack fp + diff --git a/cardano-node/src/Cardano/Node/Protocol/Byron.hs b/cardano-node/src/Cardano/Node/Protocol/Byron.hs index 7aac5f62694..befa5d33e74 100644 --- a/cardano-node/src/Cardano/Node/Protocol/Byron.hs +++ b/cardano-node/src/Cardano/Node/Protocol/Byron.hs @@ -14,7 +14,7 @@ module Cardano.Node.Protocol.Byron import Cardano.Prelude import Control.Monad.Trans.Except.Extra (bimapExceptT, firstExceptT, hoistEither, - hoistMaybe, left) + hoistMaybe, left) import qualified Data.ByteString.Lazy as LB import qualified Data.Text as Text @@ -26,8 +26,8 @@ import qualified Cardano.Crypto.Hash as Crypto import qualified Cardano.Crypto.Hashing as Byron.Crypto import qualified Cardano.Chain.Genesis as Genesis -import qualified Cardano.Chain.Update as Update import qualified Cardano.Chain.UTxO as UTxO +import qualified Cardano.Chain.Update as Update import Cardano.Crypto.ProtocolMagic (RequiresNetworkMagic) import Ouroboros.Consensus.Cardano @@ -35,10 +35,10 @@ import qualified Ouroboros.Consensus.Cardano as Consensus import Cardano.Node.Types +import Cardano.Node.Protocol.Types import Cardano.Tracing.OrphanInstances.Byron () import Cardano.Tracing.OrphanInstances.HardFork () - -import Cardano.Node.Protocol.Types +import Cardano.Tracing.OrphanInstances.Shelley () ------------------------------------------------------------------------------ diff --git a/cardano-node/src/Cardano/Node/Protocol/Cardano.hs b/cardano-node/src/Cardano/Node/Protocol/Cardano.hs index 57634206598..0e8a60eebc6 100644 --- a/cardano-node/src/Cardano/Node/Protocol/Cardano.hs +++ b/cardano-node/src/Cardano/Node/Protocol/Cardano.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE NamedFieldPuns #-} @@ -35,6 +36,8 @@ import Cardano.Node.Types import Cardano.Tracing.OrphanInstances.Byron () import Cardano.Tracing.OrphanInstances.Shelley () +import Cardano.Node.Protocol.Alonzo (AlonzoProtocolInstantiationError, readAlonzoGenesis, + renderAlonzoProtocolInstantiationError) import qualified Cardano.Node.Protocol.Byron as Byron import qualified Cardano.Node.Protocol.Shelley as Shelley @@ -83,7 +86,9 @@ mkSomeConsensusProtocolCardano NodeByronProtocolConfiguration { npcTestAllegraHardForkAtEpoch, npcTestAllegraHardForkAtVersion, npcTestMaryHardForkAtEpoch, - npcTestMaryHardForkAtVersion + npcTestMaryHardForkAtVersion, + npcTestAlonzoHardForkAtEpoch, + npcTestAlonzoHardForkAtVersion } files = do byronGenesis <- @@ -105,6 +110,12 @@ mkSomeConsensusProtocolCardano NodeByronProtocolConfiguration { firstExceptT CardanoProtocolInstantiationErrorShelley $ Shelley.readLeaderCredentials files + -- We choose to include the Alonzo relevant fields in the Shelley genesis + -- and therefore avoid creating a separate Alonzo genesis file + let GenesisFile shelleyGenFile = npcShelleyGenesisFile + alonzoGenesis <- firstExceptT CardanoProtocolInstantiationErrorAlonzo + $ readAlonzoGenesis shelleyGenFile + --TODO: all these protocol versions below are confusing and unnecessary. -- It could and should all be automated and these config entries eliminated. return $! @@ -138,7 +149,7 @@ mkSomeConsensusProtocolCardano NodeByronProtocolConfiguration { shelleyBasedGenesis = shelleyGenesis, shelleyBasedInitialNonce = Shelley.genesisHashToPraosNonce shelleyGenesisHash, - shelleyBasedLeaderCredentials = shelleyLeaderCredentials + shelleyBasedLeaderCredentials = shelleyLeaderCredentials } Consensus.ProtocolParamsShelley { -- This is /not/ the Shelley protocol version. It is the protocol @@ -164,10 +175,22 @@ mkSomeConsensusProtocolCardano NodeByronProtocolConfiguration { maryProtVer = ProtVer 4 0 } + -- TODO: TestEnableDevelopmentHardForkEras :: Bool. This bool + -- will tell use whether or not to change the 'maryProtVer' field + -- from version 4 to version 5 so that we can fork to version 5 + Consensus.ProtocolParamsAlonzo { + -- This is /not/ the Alonzo protocol version. It is the protocol + -- version that this node will declare that it understands, when it + -- is in the Alonzo era. Since Alonzo is currently the last known + -- protocol version then this is also the Alonzo protocol version. + alonzoProtVer = ProtVer 5 0 + } + -- ProtocolParamsTransition specifies the parameters needed to transition between two eras -- The comments below also apply for the Shelley -> Allegra and Allegra -> Mary hard forks. -- Byron to Shelley hard fork parameters - Consensus.ProtocolParamsTransition { + Consensus.ProtocolTransitionParamsShelleyBased { + transitionTranslationContext = (), transitionTrigger = -- What will trigger the Byron -> Shelley hard fork? case npcTestShelleyHardForkAtEpoch of @@ -180,6 +203,7 @@ mkSomeConsensusProtocolCardano NodeByronProtocolConfiguration { -- Version 2 is Shelley -- Version 3 is Allegra -- Version 4 is Mary + -- Version 5 is Alonzo -- -- But we also provide an override to allow for simpler test setups -- such as triggering at the 0 -> 1 transition . @@ -192,7 +216,8 @@ mkSomeConsensusProtocolCardano NodeByronProtocolConfiguration { Just epochNo -> Consensus.TriggerHardForkAtEpoch epochNo } -- Shelley to Allegra hard fork parameters - Consensus.ProtocolParamsTransition { + Consensus.ProtocolTransitionParamsShelleyBased { + transitionTranslationContext = (), transitionTrigger = case npcTestAllegraHardForkAtEpoch of Nothing -> Consensus.TriggerHardForkAtVersion @@ -200,13 +225,24 @@ mkSomeConsensusProtocolCardano NodeByronProtocolConfiguration { Just epochNo -> Consensus.TriggerHardForkAtEpoch epochNo } -- Allegra to Mary hard fork parameters - Consensus.ProtocolParamsTransition { + Consensus.ProtocolTransitionParamsShelleyBased { + transitionTranslationContext = (), transitionTrigger = case npcTestMaryHardForkAtEpoch of Nothing -> Consensus.TriggerHardForkAtVersion (maybe 4 fromIntegral npcTestMaryHardForkAtVersion) Just epochNo -> Consensus.TriggerHardForkAtEpoch epochNo } + -- Mary to Alonzo hard fork parameters + Consensus.ProtocolTransitionParamsShelleyBased { + transitionTranslationContext = alonzoGenesis, + transitionTrigger = + case npcTestAlonzoHardForkAtEpoch of + Nothing -> Consensus.TriggerHardForkAtVersion + (maybe 5 fromIntegral npcTestAlonzoHardForkAtVersion) + Just epochNo -> Consensus.TriggerHardForkAtEpoch epochNo + } + ------------------------------------------------------------------------------ -- Errors @@ -218,6 +254,8 @@ data CardanoProtocolInstantiationError = | CardanoProtocolInstantiationErrorShelley Shelley.ShelleyProtocolInstantiationError + | CardanoProtocolInstantiationErrorAlonzo + AlonzoProtocolInstantiationError deriving Show renderCardanoProtocolInstantiationError :: CardanoProtocolInstantiationError @@ -229,3 +267,7 @@ renderCardanoProtocolInstantiationError renderCardanoProtocolInstantiationError (CardanoProtocolInstantiationErrorShelley err) = Shelley.renderShelleyProtocolInstantiationError err + +renderCardanoProtocolInstantiationError + (CardanoProtocolInstantiationErrorAlonzo err) = + renderAlonzoProtocolInstantiationError err diff --git a/cardano-node/src/Cardano/Node/Protocol/Shelley.hs b/cardano-node/src/Cardano/Node/Protocol/Shelley.hs index 69331ee32dd..c725046e2ad 100644 --- a/cardano-node/src/Cardano/Node/Protocol/Shelley.hs +++ b/cardano-node/src/Cardano/Node/Protocol/Shelley.hs @@ -52,7 +52,6 @@ import Cardano.Tracing.OrphanInstances.Shelley () import Cardano.Node.Protocol.Types - ------------------------------------------------------------------------------ -- Shelley protocol -- diff --git a/cardano-node/src/Cardano/Node/Protocol/Types.hs b/cardano-node/src/Cardano/Node/Protocol/Types.hs index da2a3d29707..7daac7d5dd8 100644 --- a/cardano-node/src/Cardano/Node/Protocol/Types.hs +++ b/cardano-node/src/Cardano/Node/Protocol/Types.hs @@ -19,8 +19,9 @@ import NoThunks.Class (NoThunks) import qualified Cardano.Api.Protocol.Types as Cardano +import Cardano.Node.Orphans () import Cardano.Tracing.Constraints (TraceConstraints) -import Cardano.Tracing.Metrics (HasKESMetricsData, HasKESInfo) +import Cardano.Tracing.Metrics (HasKESInfo, HasKESMetricsData) data Protocol = ByronProtocol | ShelleyProtocol diff --git a/cardano-node/src/Cardano/Node/Query.hs b/cardano-node/src/Cardano/Node/Query.hs deleted file mode 100644 index da135f64d24..00000000000 --- a/cardano-node/src/Cardano/Node/Query.hs +++ /dev/null @@ -1,190 +0,0 @@ -{-# LANGUAGE FlexibleContexts #-} -{-# LANGUAGE GADTs #-} -{-# LANGUAGE ScopedTypeVariables #-} --- | Answer queries using the ledger state of the running node --- --- This allows queries from within the running node as opposed to submitting --- queries via the LocalStateQuery protocol. -module Cardano.Node.Query - ( answerQuery - , answerQueryWithLedgerState - , InterpreterQuery - , qryEpochStartTimeOfSlot - , getEpochStartTimeOfSlot - ) where - -import Cardano.Prelude - -import Data.Time.Clock (UTCTime) - --- Consensus -import Ouroboros.Consensus.Block (SlotNo) -import qualified Ouroboros.Consensus.BlockchainTime.WallClock.Types as WCT -import Ouroboros.Consensus.Config (TopLevelConfig, configBlock, configLedger) -import Ouroboros.Consensus.Config.SupportsNode (getSystemStart) -import qualified Ouroboros.Consensus.HardFork.Combinator.Compat as HF -import Ouroboros.Consensus.HardFork.Combinator.Degenerate - (HardForkLedgerConfig (DegenLedgerConfig)) -import qualified Ouroboros.Consensus.HardFork.History.Qry as HFI -import Ouroboros.Consensus.Ledger.Extended (ExtLedgerCfg (..), ExtLedgerState) -import qualified Ouroboros.Consensus.Ledger.Query as Consensus (Query, answerQuery) -import Ouroboros.Consensus.Node (RunNode) -import Ouroboros.Consensus.Node.ProtocolInfo (pInfoConfig) -import qualified Ouroboros.Consensus.Storage.ChainDB as ChainDB - -import qualified Cardano.Api.Protocol.Types as Protocol - --- Byron -import qualified Cardano.Chain.Genesis as Byron -import qualified Ouroboros.Consensus.Byron.Ledger.Conversions as Byron - --- Shelley -import Ouroboros.Consensus.Shelley.Ledger (shelleyLedgerGenesis) -import qualified Shelley.Spec.Ledger.API as SL - --- Cardano -import Ouroboros.Consensus.Cardano.ByronHFC (ByronBlockHFC) -import qualified Ouroboros.Consensus.Cardano.CanHardFork as CanHardFork -import Ouroboros.Consensus.Shelley.ShelleyHFC (ShelleyBlockHFC) - -import Cardano.Tracing.Kernel - --- | Answer a general query about the current ledger state of the running node. -answerQuery - :: forall blk result - . ( RunNode blk - , Protocol.Protocol IO blk - ) - => Protocol.BlockType blk - -> Protocol.ProtocolInfoArgs IO blk - -> NodeKernel IO RemoteConnectionId LocalConnectionId blk - -> HF.HardForkCompatQuery blk result - -> IO result -answerQuery blkType protocol nodeKernel query = do - extLedgerState <- atomically $ ChainDB.getCurrentLedger chainDB - return $ answerQueryWithLedgerState blkType protocol extLedgerState query - where - chainDB = getChainDB nodeKernel - --- | Answer a general query about the given ledger state. -answerQueryWithLedgerState - :: forall blk result - . ( RunNode blk - , Protocol.Protocol IO blk - ) - => Protocol.BlockType blk - -> Protocol.ProtocolInfoArgs IO blk - -> ExtLedgerState blk - -> HF.HardForkCompatQuery blk result - -> result -answerQueryWithLedgerState blkType protocol extLedgerState query = runIdentity $ - case blkType of - Protocol.ByronBlockType {} -> - byronQuery - Protocol.ShelleyBlockType {} -> - shelleyBasedQuery - Protocol.CardanoBlockType {} -> - HF.forwardCompatQuery - answerQueryHelper - query - where - cfg :: TopLevelConfig blk - cfg = pInfoConfig $ Protocol.protocolInfo protocol - - answerQueryHelper - :: forall m result'. Monad m - => Consensus.Query blk result' - -> m result' - answerQueryHelper q = pure $ - Consensus.answerQuery (ExtLedgerCfg cfg) q extLedgerState - - byronQuery :: blk ~ ByronBlockHFC => Identity result - byronQuery = - HF.singleEraCompatQuery - epochSize - slotLength - answerQueryHelper - query - where - DegenLedgerConfig ledgerConfig = configLedger cfg - genesis = CanHardFork.byronLedgerConfig ledgerConfig - epochSize = Byron.fromByronEpochSlots $ Byron.configEpochSlots genesis - slotLength = Byron.fromByronSlotLength $ Byron.genesisSlotLength genesis - - shelleyBasedQuery :: blk ~ ShelleyBlockHFC era => Identity result - shelleyBasedQuery = - HF.singleEraCompatQuery - epochSize - slotLength - answerQueryHelper - query - where - DegenLedgerConfig ledgerConfig = configLedger cfg - genesis = shelleyLedgerGenesis $ - CanHardFork.shelleyLedgerConfig ledgerConfig - epochSize = SL.sgEpochLength genesis - slotLength = WCT.mkSlotLength $ SL.sgSlotLength genesis - --- | To avoid confusing 'HFI.Qry' with 'HF.Query' and 'HF.HardForkCompatQuery, --- we introduce a type synonym for the former which we can use in docstrings --- (and type signatures, of course). --- --- * 'HFI.Qry' (and thus 'InterpreterQuery') is a query about slots/epochs/time --- that a 'HF.Interpreter' can answer. --- --- * 'Consensus.Query' and 'HF.HardForkCompatQuery' are more general queries --- that can ask for anything related to the ledger state. -type InterpreterQuery a = HFI.Qry a - --- | Return the start time of the epoch of the given slot. -qryEpochStartTimeOfSlot :: SlotNo -> InterpreterQuery WCT.RelativeTime -qryEpochStartTimeOfSlot slotNo = HFI.qryFromExpr $ - HFI.ELet (HFI.EAbsToRelSlot (HFI.ELit slotNo)) $ \slotInEra -> - HFI.ELet (HFI.ERelSlotToTime (HFI.EVar slotInEra)) $ \timeInEra -> - HFI.ERelToAbsTime (HFI.EVar timeInEra) - --- | Execute the 'qryEpochStartTimeOfSlot' 'InterpreterQuery' against the --- current ledger state. --- --- Will return a 'HF.PastHorizonException' when the current chain doesn't give --- us enough information about the given slot. For example, when syncing from --- scratch, we don't know yet when the transition to Shelley will happen, so we --- can't do conversions for slots from the Shelley era. -getEpochStartTimeOfSlot - :: forall blk - . ( RunNode blk - , Protocol.Protocol IO blk - ) - => Protocol.BlockType blk - -> Protocol.ProtocolInfoArgs IO blk - -> NodeKernel IO RemoteConnectionId LocalConnectionId blk - -> SlotNo - -> IO (Either HFI.PastHorizonException UTCTime) -getEpochStartTimeOfSlot blkType protocol nodeKernel slotNo = do - interpreter <- answerQuery blkType protocol nodeKernel HF.compatGetInterpreter - -- NOTE: ask for an interpreter sparingly, as it is not super cheap. You can - -- use that same interpreter to answer many queries. - -- - -- When the interpreter returns 'HFI.PastHorizonException' for a certain - -- 'InterpreterQuery', try obtaining a new interpreter. The chain might have - -- advanced and the new ledger state might contain more information so that - -- the 'InterpreterQuery' /can/ be answered. - -- - -- For example, when starting up with an empty chain, the interpreter - -- obtained from the empty ledger state won't be able to answer queries - -- about the a slot from the Shelley era, as it doesn't know when the - -- Shelley transition takes place. So while the node is syncing, you can - -- periodically try to obtain a new interpreter whenever it returns - -- 'HFI.PastHorizonException'. Note that doing this after every new block is - -- pointless and wasteful. Doing it when the ledger hasn't changed is even - -- more pointless. - return $ - WCT.fromRelativeTime systemStart <$> - HFI.interpretQuery interpreter (qryEpochStartTimeOfSlot slotNo) - where - systemStart = - getSystemStart - . configBlock - . pInfoConfig - . Protocol.protocolInfo - $ protocol diff --git a/cardano-node/src/Cardano/Node/Run.hs b/cardano-node/src/Cardano/Node/Run.hs index ee4efc0b043..3acc0396231 100644 --- a/cardano-node/src/Cardano/Node/Run.hs +++ b/cardano-node/src/Cardano/Node/Run.hs @@ -54,7 +54,7 @@ import Cardano.Node.Configuration.POM (NodeConfiguration (..), import Cardano.Node.Types import Cardano.Tracing.Config (TraceOptions (..), TraceSelection (..)) import Cardano.Tracing.Constraints (TraceConstraints) -import Cardano.Tracing.Metrics (HasKESMetricsData (..), HasKESInfo (..)) +import Cardano.Tracing.Metrics (HasKESInfo (..), HasKESMetricsData (..)) import qualified Ouroboros.Consensus.Config as Consensus import Ouroboros.Consensus.Config.SupportsNode (getNetworkMagic) diff --git a/cardano-node/src/Cardano/Node/Types.hs b/cardano-node/src/Cardano/Node/Types.hs index 6dcbe67415f..fa745d5759c 100644 --- a/cardano-node/src/Cardano/Node/Types.hs +++ b/cardano-node/src/Cardano/Node/Types.hs @@ -348,13 +348,30 @@ data NodeHardForkProtocolConfiguration = , npcTestMaryHardForkAtEpoch :: Maybe EpochNo -- | For testing purposes we support specifying that the hard fork - -- happens at an exact epoch number (ie the first epoch of the new era). + -- happens at a given major protocol version. -- -- Obviously if this is used, all the nodes in the test cluster must be -- configured the same, or they will disagree. -- + -- , npcTestMaryHardForkAtVersion :: Maybe Word + -- | For testing purposes we support specifying that the hard fork + -- happens at an exact epoch number (ie the first epoch of the new era). + -- + -- Obviously if this is used, all the nodes in the test cluster must be + -- configured the same, or they will disagree. + -- + , npcTestAlonzoHardForkAtEpoch :: Maybe EpochNo + + -- | For testing purposes we support specifying that the hard fork + -- happens at a given major protocol version. + -- + -- Obviously if this is used, all the nodes in the test cluster must be + -- configured the same, or they will disagree. + -- + , npcTestAlonzoHardForkAtVersion :: Maybe Word + -- TODO: npcTestEnableDevelopmentHardForkEras :: Bool } deriving (Eq, Show) diff --git a/cardano-node/src/Cardano/Tracing/Constraints.hs b/cardano-node/src/Cardano/Tracing/Constraints.hs index 017e5a570db..8f544ff8d8c 100644 --- a/cardano-node/src/Cardano/Tracing/Constraints.hs +++ b/cardano-node/src/Cardano/Tracing/Constraints.hs @@ -13,16 +13,21 @@ import Cardano.BM.Tracing (ToObject) import Cardano.Tracing.ConvertTxId (ConvertTxId) import Cardano.Tracing.Queries (LedgerQueries) -import Ouroboros.Consensus.Block (BlockProtocol, CannotForge, - ForgeStateUpdateError, Header) +import Cardano.Ledger.Alonzo (AlonzoEra) +import Cardano.Ledger.Alonzo.PParams (PParamsUpdate) +import Cardano.Ledger.Alonzo.Rules.Bbody (AlonzoBbodyPredFail) +import Cardano.Ledger.Alonzo.Rules.Utxo (UtxoPredicateFailure) +import Cardano.Ledger.Alonzo.Rules.Utxow (AlonzoPredFail) +import Cardano.Ledger.Alonzo.TxBody (TxOut) +import Ouroboros.Consensus.Block (BlockProtocol, CannotForge, ForgeStateUpdateError, + Header) import Ouroboros.Consensus.HeaderValidation (OtherHeaderEnvelopeError) import Ouroboros.Consensus.Ledger.Abstract (LedgerError) import Ouroboros.Consensus.Ledger.Inspect (LedgerEvent) -import Ouroboros.Consensus.Ledger.SupportsMempool (ApplyTxErr, HasTxId, - HasTxs (..)) +import Ouroboros.Consensus.Ledger.SupportsMempool (ApplyTxErr, HasTxId, HasTxs (..)) import Ouroboros.Consensus.Protocol.Abstract (ValidationErr) import Ouroboros.Consensus.Shelley.Ledger.Mempool (GenTx, TxId) - +import Ouroboros.Consensus.Shelley.Protocol.Crypto (StandardCrypto) -- | Tracing-related constraints for monitoring purposes. type TraceConstraints blk = @@ -31,6 +36,8 @@ type TraceConstraints blk = , HasTxId (GenTx blk) , LedgerQueries blk , ToJSON (TxId (GenTx blk)) + , ToJSON (TxOut (AlonzoEra StandardCrypto)) + , ToJSON (PParamsUpdate (AlonzoEra StandardCrypto)) , ToObject (ApplyTxErr blk) , ToObject (GenTx blk) , ToObject (Header blk) @@ -40,6 +47,9 @@ type TraceConstraints blk = , ToObject (ValidationErr (BlockProtocol blk)) , ToObject (CannotForge blk) , ToObject (ForgeStateUpdateError blk) + , ToObject (UtxoPredicateFailure (AlonzoEra StandardCrypto)) + , ToObject (AlonzoBbodyPredFail (AlonzoEra StandardCrypto)) + , ToObject (AlonzoPredFail (AlonzoEra StandardCrypto)) , Show blk , Show (Header blk) ) diff --git a/cardano-node/src/Cardano/Tracing/OrphanInstances/Byron.hs b/cardano-node/src/Cardano/Tracing/OrphanInstances/Byron.hs index fd427136940..4711d6d2d7f 100644 --- a/cardano-node/src/Cardano/Tracing/OrphanInstances/Byron.hs +++ b/cardano-node/src/Cardano/Tracing/OrphanInstances/Byron.hs @@ -12,6 +12,7 @@ module Cardano.Tracing.OrphanInstances.Byron () where import Cardano.Prelude +import Data.Aeson (Value (..)) import qualified Data.Set as Set import qualified Data.Text as Text @@ -22,14 +23,14 @@ import Ouroboros.Consensus.Block (Header) import Ouroboros.Network.Block (blockHash, blockNo, blockSlot) import Ouroboros.Consensus.Byron.Ledger (ByronBlock (..), - ByronOtherHeaderEnvelopeError (..), TxId (..), byronHeaderRaw) + ByronOtherHeaderEnvelopeError (..), TxId (..), byronHeaderRaw) import Ouroboros.Consensus.Byron.Ledger.Inspect (ByronLedgerUpdate (..), - ProtocolUpdate (..), UpdateState (..)) + ProtocolUpdate (..), UpdateState (..)) import Ouroboros.Consensus.Ledger.SupportsMempool (GenTx, txId) import Ouroboros.Consensus.Util.Condense (condense) import Cardano.Chain.Block (ABlockOrBoundaryHdr (..), AHeader (..), - ChainValidationError (..), delegationCertificate) + ChainValidationError (..), delegationCertificate) import Cardano.Chain.Byron.API (ApplyMempoolPayloadErr (..)) import Cardano.Chain.Delegation (delegateVK) import Cardano.Crypto.Signing (VerificationKey) diff --git a/cardano-node/src/Cardano/Tracing/OrphanInstances/Common.hs b/cardano-node/src/Cardano/Tracing/OrphanInstances/Common.hs index 15867c676aa..c4a3f40cede 100644 --- a/cardano-node/src/Cardano/Tracing/OrphanInstances/Common.hs +++ b/cardano-node/src/Cardano/Tracing/OrphanInstances/Common.hs @@ -17,7 +17,6 @@ module Cardano.Tracing.OrphanInstances.Common , mkObject , emptyObject , ToJSON - , Value (..) , toJSON , (.=) @@ -43,7 +42,7 @@ module Cardano.Tracing.OrphanInstances.Common import Cardano.Prelude import Prelude (fail) -import Data.Aeson +import Data.Aeson hiding (Value) import qualified Data.ByteString.Base16 as B16 import qualified Data.ByteString.Short as SBS import Data.Scientific (coefficient) @@ -52,20 +51,18 @@ import qualified Data.Text.Encoding as Text import Network.Socket (PortNumber) import Cardano.BM.Data.LogItem (LOContent (..), LogObject (..), PrivacyAnnotation (..), - mkLOMeta) + mkLOMeta) import Cardano.BM.Data.Tracer (HasTextFormatter (..), emptyObject, mkObject, trStructured, - trStructuredText) + trStructuredText) import Cardano.BM.Stats import Cardano.BM.Tracing (HasPrivacyAnnotation (..), HasSeverityAnnotation (..), - Severity (..), ToObject (..), Tracer (..), TracingVerbosity (..), - Transformable (..)) + Severity (..), ToObject (..), Tracer (..), TracingVerbosity (..), + Transformable (..)) import qualified Cardano.Chain.Update as Update import Cardano.Slotting.Block (BlockNo (..)) import Ouroboros.Consensus.Byron.Ledger.Block (ByronHash (..)) import Ouroboros.Consensus.HardFork.Combinator (OneEraHash (..)) import Ouroboros.Network.Block (HeaderHash, Tip (..)) - - -- | A bit of a weird one, but needed because some of the very general -- consensus interfaces are sometimes instantiated to 'Void', when there are -- no cases needed. @@ -125,3 +122,4 @@ instance ToObject ResourceStats where case toJSON stats of Object x -> x _ -> mempty + diff --git a/cardano-node/src/Cardano/Tracing/OrphanInstances/Consensus.hs b/cardano-node/src/Cardano/Tracing/OrphanInstances/Consensus.hs index 38e5820fbb6..d95ba3f44fe 100644 --- a/cardano-node/src/Cardano/Tracing/OrphanInstances/Consensus.hs +++ b/cardano-node/src/Cardano/Tracing/OrphanInstances/Consensus.hs @@ -16,6 +16,7 @@ module Cardano.Tracing.OrphanInstances.Consensus () where import Cardano.Prelude hiding (show) import Prelude (show) +import Data.Aeson (Value (..)) import Data.Text (pack) import qualified Data.Text as Text import qualified Data.Text.Encoding as Text @@ -256,7 +257,8 @@ instance ( tx ~ GenTx blk , ToObject (OtherHeaderEnvelopeError blk) , ToObject (ValidationErr (BlockProtocol blk)) , ToObject (CannotForge blk) - , ToObject (ForgeStateUpdateError blk)) + , ToObject (ForgeStateUpdateError blk) + , LedgerSupportsMempool blk) => Transformable Text IO (TraceForgeEvent blk) where trTransformer = trStructuredText @@ -265,9 +267,11 @@ instance ( tx ~ GenTx blk , HasTxId tx , LedgerSupportsMempool blk , LedgerSupportsProtocol blk + , LedgerSupportsMempool blk , Show (TxId tx) , Show (ForgeStateUpdateError blk) - , Show (CannotForge blk)) + , Show (CannotForge blk) + , LedgerSupportsMempool blk) => HasTextFormatter (TraceForgeEvent blk) where formatText = \case TraceStartLeadershipCheck slotNo -> const $ diff --git a/cardano-node/src/Cardano/Tracing/OrphanInstances/Network.hs b/cardano-node/src/Cardano/Tracing/OrphanInstances/Network.hs index 9c014c747fe..67590da2c73 100644 --- a/cardano-node/src/Cardano/Tracing/OrphanInstances/Network.hs +++ b/cardano-node/src/Cardano/Tracing/OrphanInstances/Network.hs @@ -16,6 +16,7 @@ import Cardano.Prelude hiding (show) import Prelude (String, show) import Control.Monad.Class.MonadTime (DiffTime, Time (..)) +import Data.Aeson (Value (..)) import qualified Data.IP as IP import Data.Text (pack) diff --git a/cardano-node/src/Cardano/Tracing/OrphanInstances/Shelley.hs b/cardano-node/src/Cardano/Tracing/OrphanInstances/Shelley.hs index ea97eaabe02..b6cba3a94b2 100644 --- a/cardano-node/src/Cardano/Tracing/OrphanInstances/Shelley.hs +++ b/cardano-node/src/Cardano/Tracing/OrphanInstances/Shelley.hs @@ -19,12 +19,16 @@ module Cardano.Tracing.OrphanInstances.Shelley () where import Cardano.Prelude +import Data.Aeson (Value (..), object) import qualified Data.Aeson as Aeson +import qualified Data.Aeson.Types as Aeson import qualified Data.HashMap.Strict as HMS import qualified Data.Set as Set import qualified Data.Text as Text +import qualified Cardano.Api as Api import Cardano.Api.Orphans () +import qualified Cardano.Api.Shelley as Api import Cardano.Slotting.Block (BlockNo (..)) import Cardano.Tracing.OrphanInstances.Common @@ -39,14 +43,25 @@ import Ouroboros.Network.Point (WithOrigin, withOriginToMaybe) import Ouroboros.Consensus.Shelley.Ledger hiding (TxId) import Ouroboros.Consensus.Shelley.Ledger.Inspect import Ouroboros.Consensus.Shelley.Protocol (TPraosCannotForge (..)) +import Ouroboros.Consensus.Shelley.Protocol.Crypto (StandardCrypto) import qualified Ouroboros.Consensus.Shelley.Protocol.HotKey as HotKey +import qualified Cardano.Crypto.Hash.Class as Crypto +import Cardano.Ledger.Alonzo as Alonzo +import Cardano.Ledger.Alonzo.Rules.Bbody (AlonzoBbodyPredFail) +import qualified Cardano.Ledger.Alonzo.Rules.Utxo as Alonzo +import Cardano.Ledger.Alonzo.Rules.Utxow (AlonzoPredFail (..)) +import qualified Cardano.Ledger.Alonzo.Tx as Alonzo +import qualified Cardano.Ledger.Alonzo.TxBody as Alonzo import qualified Cardano.Ledger.AuxiliaryData as Core import qualified Cardano.Ledger.Core as Core +import qualified Cardano.Ledger.Core as Ledger import qualified Cardano.Ledger.Crypto as Core -import qualified Cardano.Ledger.Shelley.Constraints as Shelley +import qualified Cardano.Ledger.Era as Ledger +import qualified Cardano.Ledger.SafeHash as SafeHash import qualified Cardano.Ledger.ShelleyMA.Rules.Utxo as MA import qualified Cardano.Ledger.ShelleyMA.Timelocks as MA +import Shelley.Spec.Ledger.BaseTypes (strictMaybeToMaybe) -- TODO: this should be exposed via Cardano.Api import Shelley.Spec.Ledger.API hiding (ShelleyBasedEra) @@ -159,21 +174,21 @@ instance ( ShelleyBasedEra era ] instance ( ShelleyBasedEra era - , ToJSON (Shelley.PParamsDelta era) + , ToJSON (Ledger.PParamsDelta era) ) => ToObject (ShelleyLedgerUpdate era) where toObject verb (ShelleyUpdatedProtocolUpdates updates) = mkObject [ "kind" .= String "ShelleyUpdatedProtocolUpdates" , "updates" .= map (toObject verb) updates ] -instance ToJSON (Shelley.PParamsDelta era) +instance ToJSON (Ledger.PParamsDelta era) => ToObject (ProtocolUpdate era) where toObject verb ProtocolUpdate{protocolUpdateProposal, protocolUpdateState} = mkObject [ "proposal" .= toObject verb protocolUpdateProposal , "state" .= toObject verb protocolUpdateState ] -instance ToJSON (Shelley.PParamsDelta era) +instance ToJSON (Ledger.PParamsDelta era) => ToObject (UpdateProposal era) where toObject _verb UpdateProposal{proposalParams, proposalVersion, proposalEpoch} = mkObject [ "params" .= proposalParams @@ -279,6 +294,51 @@ instance ( ShelleyBasedEra era toObject verb (UtxowFailure f) = toObject verb f toObject verb (DelegsFailure f) = toObject verb f +instance ToObject (AlonzoPredFail (Alonzo.AlonzoEra StandardCrypto)) where + toObject v (WrappedShelleyEraFailure utxoPredFail) = + toObject v utxoPredFail + toObject _ (UnRedeemableScripts scripts) = + mkObject [ "kind" .= String "UnRedeemableScripts" + , "scripts" .= renderUnredeemableScripts scripts + ] + toObject _ (DataHashSetsDontAgree fromTx fromUtxo) = + mkObject [ "kind" .= String "DataHashSetsDontAgree" + , "fromTx" .= map (Crypto.hashToTextAsHex . SafeHash.extractHash) (Set.toList fromTx) + , "fromUtxo" .= map (Crypto.hashToTextAsHex . SafeHash.extractHash) (Set.toList fromUtxo) + ] + toObject _ (PPViewHashesDontMatch ppHashInTxBody ppHashFromPParams) = + mkObject [ "kind" .= String "PPViewHashesDontMatch" + , "fromTxBody" .= renderWitnessPPDataHash (strictMaybeToMaybe ppHashInTxBody) + , "fromPParams" .= renderWitnessPPDataHash (strictMaybeToMaybe ppHashFromPParams) + ] + toObject _ (MissingRequiredSigners missingKeyWitnesses) = + mkObject [ "kind" .= String "MissingRequiredSigners" + , "witnesses" .= Set.toList missingKeyWitnesses + ] + +renderWitnessPPDataHash :: Maybe (Alonzo.WitnessPPDataHash StandardCrypto) -> Aeson.Value +renderWitnessPPDataHash (Just witPPDataHash) = + Aeson.String . Crypto.hashToTextAsHex $ SafeHash.extractHash witPPDataHash +renderWitnessPPDataHash Nothing = Aeson.Null + +renderScriptHash :: ScriptHash StandardCrypto -> Text +renderScriptHash = Api.serialiseToRawBytesHexText . Api.fromShelleyScriptHash + +renderUnredeemableScripts :: [(Alonzo.ScriptPurpose StandardCrypto, ScriptHash StandardCrypto)] -> Aeson.Value +renderUnredeemableScripts scripts = Aeson.object $ map renderTuple scripts + where + renderTuple :: (Alonzo.ScriptPurpose StandardCrypto, ScriptHash StandardCrypto) -> Aeson.Pair + renderTuple (scriptPurpose, sHash) = renderScriptHash sHash .= renderScriptPurpose scriptPurpose + + renderScriptPurpose :: Alonzo.ScriptPurpose StandardCrypto -> Aeson.Value + renderScriptPurpose (Alonzo.Minting pid) = + Aeson.object [ "minting" .= toJSON pid] + renderScriptPurpose (Alonzo.Spending txin) = + Aeson.object [ "spending" .= Api.fromShelleyTxIn txin] + renderScriptPurpose (Alonzo.Rewarding rwdAcct) = + Aeson.object [ "rewarding" .= Aeson.String (Api.serialiseAddress $ Api.fromShelleyStakeAddr rwdAcct)] + renderScriptPurpose (Alonzo.Certifying cert) = + Aeson.object [ "certifying" .= toJSON (Api.textEnvelopeDefaultDescr $ Api.fromShelleyCertificate cert)] instance ( ShelleyBasedEra era , ToObject (PredicateFailure (UTXO era)) @@ -448,12 +508,12 @@ instance ( ShelleyBasedEra era , "error" .= String "Too many asset ids in the tx output" ] -renderBadInputsUTxOErr :: Set (TxIn era) -> Value +renderBadInputsUTxOErr :: Set (TxIn era) -> Aeson.Value renderBadInputsUTxOErr txIns | Set.null txIns = String "The transaction contains no inputs." | otherwise = String "The transaction contains inputs that do not exist in the UTxO set." -renderValueNotConservedErr :: Show val => val -> val -> Value +renderValueNotConservedErr :: Show val => val -> val -> Aeson.Value renderValueNotConservedErr consumed produced = String $ "This transaction consumed " <> show consumed <> " but produced " <> show produced @@ -771,6 +831,31 @@ instance ToObject (UpecPredicateFailure era) where , "depositPot" .= String (textShow depositPot) ] + +-------------------------------------------------------------------------------- +-- Alonzo related +-------------------------------------------------------------------------------- + + +instance ToObject (Alonzo.UtxoPredicateFailure (Alonzo.AlonzoEra StandardCrypto)) where + toObject _ _ = panic "ToJSON: UtxoPredicateFailure not implemented yet" + +instance ToObject (AlonzoBbodyPredFail (Alonzo.AlonzoEra StandardCrypto)) where + toObject _ _ = panic "ToJSON: AlonzoBbodyPredFail not implemented yet" + +instance (Ledger.Era era, Show (Ledger.Value era), ToJSON (Ledger.Value era)) + => ToJSON (Alonzo.TxOut era) where + toJSON (Alonzo.TxOut addr v dataHash) = + object [ "address" .= toJSON addr + , "value" .= toJSON v + , "datahash" .= case strictMaybeToMaybe dataHash of + Nothing -> Aeson.Null + Just dHash -> + Aeson.String . Crypto.hashToTextAsHex + $ SafeHash.extractHash dHash + ] + + -------------------------------------------------------------------------------- -- Helper functions -------------------------------------------------------------------------------- diff --git a/cardano-node/src/Cardano/Tracing/Queries.hs b/cardano-node/src/Cardano/Tracing/Queries.hs index 8c731d9b9f0..917b8c9235d 100644 --- a/cardano-node/src/Cardano/Tracing/Queries.hs +++ b/cardano-node/src/Cardano/Tracing/Queries.hs @@ -62,8 +62,10 @@ instance LedgerQueries (Cardano.CardanoBlock c) where Cardano.LedgerStateShelley ledgerShelley -> ledgerUtxoSize ledgerShelley Cardano.LedgerStateAllegra ledgerAllegra -> ledgerUtxoSize ledgerAllegra Cardano.LedgerStateMary ledgerMary -> ledgerUtxoSize ledgerMary + Cardano.LedgerStateAlonzo ledgerAlonzo -> ledgerUtxoSize ledgerAlonzo ledgerDelegMapSize = \case Cardano.LedgerStateByron ledgerByron -> ledgerDelegMapSize ledgerByron Cardano.LedgerStateShelley ledgerShelley -> ledgerDelegMapSize ledgerShelley Cardano.LedgerStateAllegra ledgerAllegra -> ledgerDelegMapSize ledgerAllegra Cardano.LedgerStateMary ledgerMary -> ledgerDelegMapSize ledgerMary + Cardano.LedgerStateAlonzo ledgerAlonzo -> ledgerDelegMapSize ledgerAlonzo diff --git a/configuration/cardano/alonzo/shelley_qa_cost-model.json b/configuration/cardano/alonzo/shelley_qa_cost-model.json new file mode 100644 index 00000000000..6a279c81d2c --- /dev/null +++ b/configuration/cardano/alonzo/shelley_qa_cost-model.json @@ -0,0 +1,306 @@ +{ + "less_than_integer": { + "memory": { + "arguments": 1, + "type": "constant_cost" + }, + "cpu": { + "arguments": { + "slope": 4.3328524294545e-4, + "intercept": 2.10575839518836 + }, + "type": "min_size" + } + }, + "verify_signature": { + "memory": { + "arguments": 1, + "type": "constant_cost" + }, + "cpu": { + "arguments": 2.71491123389651, + "type": "constant_cost" + } + }, + "take_byte_string": { + "memory": { + "arguments": 2, + "type": "constant_cost" + }, + "cpu": { + "arguments": 2.0365567048005, + "type": "constant_cost" + } + }, + "less_than_eq_integer": { + "memory": { + "arguments": 1, + "type": "constant_cost" + }, + "cpu": { + "arguments": { + "slope": 3.37112224357207e-4, + "intercept": 2.09702447231695 + }, + "type": "min_size" + } + }, + "lt_byte_string": { + "memory": { + "arguments": 1, + "type": "constant_cost" + }, + "cpu": { + "arguments": { + "slope": 2.46159434917543e-4, + "intercept": 2.07414622772793 + }, + "type": "min_size" + } + }, + "if_then_else": { + "memory": { + "arguments": 1, + "type": "constant_cost" + }, + "cpu": { + "arguments": 1, + "type": "constant_cost" + } + }, + "greater_than_integer": { + "memory": { + "arguments": 1, + "type": "constant_cost" + }, + "cpu": { + "arguments": { + "slope": 4.3328524294545e-4, + "intercept": 2.10575839518836 + }, + "type": "min_size" + } + }, + "multiply_integer": { + "memory": { + "arguments": { + "slope": 1, + "intercept": 0 + }, + "type": "added_sizes" + }, + "cpu": { + "arguments": { + "slope": 1.17628612553361e-2, + "intercept": 1.9243156681313 + }, + "type": "added_sizes" + } + }, + "eq_integer": { + "memory": { + "arguments": 1, + "type": "constant_cost" + }, + "cpu": { + "arguments": { + "slope": 5.73299088778534e-4, + "intercept": 2.08823964398551 + }, + "type": "min_size" + } + }, + "quotient_integer": { + "memory": { + "arguments": { + "slope": 1, + "intercept": 0, + "orientation": "y" + }, + "type": "linear_size" + }, + "cpu": { + "arguments": { + "model_split_const_intercept": 2.19257116593296, + "model_split_const_slope": 5.12624141673763e-4 + }, + "type": "split_const_multi" + } + }, + "add_integer": { + "memory": { + "arguments": { + "slope": 1, + "intercept": 1 + }, + "type": "max_size" + }, + "cpu": { + "arguments": { + "slope": 1.10910717654586e-3, + "intercept": 2.11737234677083 + }, + "type": "max_size" + } + }, + "drop_byte_string": { + "memory": { + "arguments": 2, + "type": "constant_cost" + }, + "cpu": { + "arguments": 2.0324988684539, + "type": "constant_cost" + } + }, + "greater_than_eq_integer": { + "memory": { + "arguments": 1, + "type": "constant_cost" + }, + "cpu": { + "arguments": { + "slope": 3.37112224357207e-4, + "intercept": 2.09702447231695 + }, + "type": "min_size" + } + }, + "gt_byte_string": { + "memory": { + "arguments": 1, + "type": "constant_cost" + }, + "cpu": { + "arguments": { + "slope": 2.46159434917543e-4, + "intercept": 2.07414622772793 + }, + "type": "min_size" + } + }, + "mod_integer": { + "memory": { + "arguments": { + "minimum": 1, + "slope": 1, + "intercept": 0 + }, + "type": "subtracted_sizes" + }, + "cpu": { + "arguments": { + "model_split_const_intercept": 2.19257116593296, + "model_split_const_slope": 5.12624141673763e-4 + }, + "type": "split_const_multi" + } + }, + "concatenate": { + "memory": { + "arguments": { + "slope": 1, + "intercept": 0 + }, + "type": "added_sizes" + }, + "cpu": { + "arguments": { + "slope": 4.99167767731152e-4, + "intercept": 2.67153236270497 + }, + "type": "added_sizes" + } + }, + "divide_integer": { + "memory": { + "arguments": { + "minimum": 1, + "slope": 1, + "intercept": 0 + }, + "type": "subtracted_sizes" + }, + "cpu": { + "arguments": { + "model_split_const_intercept": 2.19257116593296, + "model_split_const_slope": 5.12624141673763e-4 + }, + "type": "split_const_multi" + } + }, + "subtract_integer": { + "memory": { + "arguments": { + "slope": 1, + "intercept": 1 + }, + "type": "max_size" + }, + "cpu": { + "arguments": { + "slope": 1.24644768853139e-3, + "intercept": 2.11084612123977 + }, + "type": "max_size" + } + }, + "sha2": { + "memory": { + "arguments": 4, + "type": "constant_cost" + }, + "cpu": { + "arguments": { + "slope": 2.96456821195969e-2, + "intercept": 3.86834707882836, + "orientation": "x" + }, + "type": "linear_cost" + } + }, + "eq_byte_string": { + "memory": { + "arguments": 1, + "type": "constant_cost" + }, + "cpu": { + "arguments": { + "slope": 2.4746426691108e-4, + "intercept": 2.09360627536428 + }, + "type": "min_size" + } + }, + "remainder_integer": { + "memory": { + "arguments": { + "slope": 1, + "intercept": 0, + "orientation": "y" + }, + "type": "linear_size" + }, + "cpu": { + "arguments": { + "model_split_const_intercept": 2.19257116593296, + "model_split_const_slope": 5.12624141673763e-4 + }, + "type": "split_const_multi" + } + }, + "sha3": { + "memory": { + "arguments": 4, + "type": "constant_cost" + }, + "cpu": { + "arguments": { + "slope": 8.19185039380989e-2, + "intercept": 1.18696087943684, + "orientation": "x" + }, + "type": "linear_cost" + } + } +} \ No newline at end of file diff --git a/configuration/cardano/shelley_qa-shelley-genesis.json b/configuration/cardano/shelley_qa-shelley-genesis.json index d50a4e04291..b82c0c166cc 100644 --- a/configuration/cardano/shelley_qa-shelley-genesis.json +++ b/configuration/cardano/shelley_qa-shelley-genesis.json @@ -1,52 +1,60 @@ { - "activeSlotsCoeff": 5.0e-2, - "protocolParams": { - "protocolVersion": { - "minor": 0, - "major": 2 + "activeSlotsCoeff": 5.0e-2, + "protocolParams": { + "protocolVersion": { + "minor": 0, + "major": 2 + }, + "decentralisationParam": 1, + "eMax": 18, + "extraEntropy": { + "tag": "NeutralNonce" + }, + "maxTxSize": 16384, + "maxBlockBodySize": 65536, + "maxBlockHeaderSize": 1100, + "minFeeA": 44, + "minFeeB": 155381, + "minUTxOValue": 1000000, + "poolDeposit": 500000000, + "minPoolCost": 340000000, + "keyDeposit": 2000000, + "nOpt": 150, + "rho": 0.003, + "tau": 0.20, + "a0": 0.3 }, - "decentralisationParam": 1, - "eMax": 18, - "extraEntropy": { - "tag": "NeutralNonce" + "genDelegs": { + "489c900ca42a9e690678f777552f70cabcb49e28ad4126a902e1fbfa": { + "delegate": "a38dcd095ad126eac1f64d99ec64c3de63b14e90009f5e4b4e451b86", + "vrf": "df85ffa44aed49ef1e9dda28dab48592143668ac0fb1f1df1a8ec6b771223b53" + }, + "fe4a70e2858afa3487ac582eb7f8a9fb2538d186e71263beb497d017": { + "delegate": "399752c39cdc628950ec4a62c09482b6ba8d65f79bcd41d7ff620273", + "vrf": "64f241c7929da8e8fb5af2b4f7779fbb18e06e6240276fb54efdddda5b7d427b" + }, + "a5f87e4f6eac5fcfcaf18beadf14f4142e7bd26bac9e4951b2918811": { + "delegate": "ea6a83bfaba85ebf3dcf4fe9a701c991fabc2e229217734fea6ec5e2", + "vrf": "524fb631fd92ae561f09f7631a1c6239dc40f242b5f7bcc3a7840aac6b403643" + } }, - "maxTxSize": 16384, - "maxBlockBodySize": 65536, - "maxBlockHeaderSize": 1100, - "minFeeA": 44, - "minFeeB": 155381, - "minUTxOValue": 1000000, - "poolDeposit": 500000000, - "minPoolCost": 340000000, - "keyDeposit": 2000000, - "nOpt": 150, - "rho": 0.003, - "tau": 0.20, - "a0": 0.3 - }, - "genDelegs": { - "489c900ca42a9e690678f777552f70cabcb49e28ad4126a902e1fbfa": { - "delegate": "a38dcd095ad126eac1f64d99ec64c3de63b14e90009f5e4b4e451b86", - "vrf": "df85ffa44aed49ef1e9dda28dab48592143668ac0fb1f1df1a8ec6b771223b53" - }, - "fe4a70e2858afa3487ac582eb7f8a9fb2538d186e71263beb497d017": { - "delegate": "399752c39cdc628950ec4a62c09482b6ba8d65f79bcd41d7ff620273", - "vrf": "64f241c7929da8e8fb5af2b4f7779fbb18e06e6240276fb54efdddda5b7d427b" - }, - "a5f87e4f6eac5fcfcaf18beadf14f4142e7bd26bac9e4951b2918811": { - "delegate": "ea6a83bfaba85ebf3dcf4fe9a701c991fabc2e229217734fea6ec5e2", - "vrf": "524fb631fd92ae561f09f7631a1c6239dc40f242b5f7bcc3a7840aac6b403643" - } - }, - "updateQuorum": 3, - "networkId": "Testnet", - "initialFunds": {}, - "maxLovelaceSupply": 45000000000000000, - "networkMagic": 3, - "epochLength": 7200, - "systemStart": "2020-08-17T13:00:00Z", - "slotsPerKESPeriod": 129600, - "slotLength": 1, - "maxKESEvolutions": 62, - "securityParam": 36 -} + "updateQuorum": 3, + "networkId": "Testnet", + "initialFunds": {}, + "maxLovelaceSupply": 45000000000000000, + "networkMagic": 3, + "epochLength": 7200, + "systemStart": "2020-08-17T13:00:00Z", + "slotsPerKESPeriod": 129600, + "slotLength": 1, + "maxKESEvolutions": 62, + "securityParam": 36, + + "adaPerUTxOWord": 42, + "executionPrices": 42, + "maxTxExUnits": 42, + "maxBlockExUnits": 42, + "maxValueSize": 42, + "costModels": "configuration/cardano/alonzo/shelley_qa_cost-model.json" + +} \ No newline at end of file diff --git a/flake.lock b/flake.lock index c57c421510c..59d8ae28e1d 100644 --- a/flake.lock +++ b/flake.lock @@ -39,11 +39,11 @@ ] }, "locked": { - "lastModified": 1620314199, - "narHash": "sha256-JCu5wnt3ja8UBQv5G3aRhQ+ZcAKB6+ivodv3yA6UnK8=", + "lastModified": 1621507969, + "narHash": "sha256-wLXAv8acJ162tVLxW2hCxDrtVmYVwHELKD9aq2CVgY0=", "owner": "input-output-hk", "repo": "iohk-nix", - "rev": "0ce3abcfed803ed77472488f30b299fda9d941b1", + "rev": "42d272e3f731ba4a8b90079d85a5ccbd985a8a9b", "type": "github" }, "original": { diff --git a/release.nix b/release.nix index b7606c1bbc1..42d2ca7f273 100644 --- a/release.nix +++ b/release.nix @@ -27,11 +27,11 @@ # Build for linux , linuxBuild ? builtins.elem "x86_64-linux" supportedSystems -# Build for macos -, macosBuild ? builtins.elem "x86_64-darwin" supportedSystems +# PR #2657 Temporarily disable macos build +, macosBuild ? false -# Cross compilation to Windows is currently only supported on linux. -, windowsBuild ? builtins.elem "x86_64-linux" supportedCrossSystems +# PR #2657 Temporarily disable mingw32 cross build +, windowsBuild ? false # A Hydra option , scrubJobs ? true @@ -49,7 +49,7 @@ let linuxRelease = (import pkgs.iohkNix.release-lib) { inherit pkgs; supportedSystems = [ "x86_64-linux" ]; - supportedCrossSystems = filter (s: s == "x86_64-linux" && windowsBuild) supportedCrossSystems; + supportedCrossSystems = filter (s: s == "x86_64-linux") supportedCrossSystems; inherit scrubJobs projectArgs; packageSet = import cardano-node; gitrev = cardano-node.rev; @@ -57,7 +57,7 @@ let macosRelease = (import pkgs.iohkNix.release-lib) { inherit pkgs; supportedSystems = [ "x86_64-darwin" ]; - supportedCrossSystems = filter (s: s == "x86_64-darwin" && windowsBuild) supportedCrossSystems; + supportedCrossSystems = filter (s: s == "x86_64-darwin") supportedCrossSystems; inherit scrubJobs projectArgs; packageSet = import cardano-node; gitrev = cardano-node.rev; @@ -194,6 +194,7 @@ let [ jobs.cardano-node-linux ] ])) # macOS builds: + # NB. you can replace macosBuild with false to remove these jobs from "required" (optionals macosBuild (concatLists [ (collectJobs jobs.macos.checks) (collectJobs jobs.macos.nixosTests) @@ -202,6 +203,7 @@ let [ jobs.cardano-node-macos ] ])) # Windows builds: + # NB. you can replace windowsBuild with false to remove these jobs from "required" (optional windowsBuild jobs.cardano-node-win64) (optionals windowsBuild (collectJobs jobs.windows.checks)) # Default system builds (linux on hydra): diff --git a/scripts/byron-to-mary/burn.sh b/scripts/byron-to-alonzo/burn.sh similarity index 100% rename from scripts/byron-to-mary/burn.sh rename to scripts/byron-to-alonzo/burn.sh diff --git a/scripts/byron-to-mary/mint.sh b/scripts/byron-to-alonzo/mint.sh similarity index 100% rename from scripts/byron-to-mary/mint.sh rename to scripts/byron-to-alonzo/mint.sh diff --git a/scripts/byron-to-mary/mkfiles.sh b/scripts/byron-to-alonzo/mkfiles.sh similarity index 90% rename from scripts/byron-to-mary/mkfiles.sh rename to scripts/byron-to-alonzo/mkfiles.sh index a9c11f4c028..81725e28250 100755 --- a/scripts/byron-to-mary/mkfiles.sh +++ b/scripts/byron-to-alonzo/mkfiles.sh @@ -1,7 +1,11 @@ #!/usr/bin/env bash set -e -#set -x +# Unoffiical bash strict mode. +# See: http://redsymbol.net/articles/unofficial-bash-strict-mode/ +set -u +set -o pipefail + # This script sets up a cluster that starts out in Byron, and can transition to Mary. # @@ -97,7 +101,7 @@ pushd ${ROOT} # create the node directories for NODE in ${ALL_NODES}; do - mkdir ${NODE} ${NODE}/byron ${NODE}/shelley + mkdir "${NODE}" "${NODE}/byron" "${NODE}/shelley" done @@ -186,7 +190,7 @@ EOF cardano-cli byron genesis genesis \ --protocol-magic ${NETWORK_MAGIC} \ - --start-time ${START_TIME} \ + --start-time "${START_TIME}" \ --k ${SECURITY_PARAM} \ --n-poor-addresses 0 \ --n-delegate-addresses ${NUM_BFT_NODES} \ @@ -202,8 +206,8 @@ mv byron.genesis.spec.json byron/genesis.spec.json # Symlink the BFT operator keys from the genesis delegates, for uniformity for N in ${BFT_NODES_N}; do - ln -s ../../byron/delegate-keys.00$((${N} - 1)).key node-bft${N}/byron/delegate.key - ln -s ../../byron/delegation-cert.00$((${N} - 1)).json node-bft${N}/byron/delegate.cert + ln -s ../../byron/delegate-keys.00$((${N} - 1)).key "node-bft${N}/byron/delegate.key" + ln -s ../../byron/delegation-cert.00$((${N} - 1)).json "node-bft${N}/byron/delegate.cert" done @@ -227,7 +231,7 @@ for N in ${BFT_NODES_N}; do --testnet-magic 42 \ --tx tx$((${N} - 1)).tx \ --wallet-key byron/delegate-keys.00$((${N} - 1)).key \ - --rich-addr-from $(head -n 1 byron/genesis-address-00$((${N} - 1))) \ + --rich-addr-from "$(head -n 1 byron/genesis-address-00$((${N} - 1)))" \ --txout "(\"$(head -n 1 byron/address-00$((${N} - 1)))\", $FUNDS_PER_BYRON_ADDRESS)" done @@ -502,21 +506,21 @@ echo echo "In order to do the protocol updates, proceed as follows:" echo echo " 0. wait for the nodes to start producing blocks" -echo " 1. invoke ./scripts/byron-to-mary/update-1.sh" +echo " 1. invoke ./scripts/byron-to-alonzo/update-1.sh" echo " wait for the next epoch for the update to take effect" echo -echo " 2. invoke ./scripts/byron-to-mary/update-2.sh" +echo " 2. invoke ./scripts/byron-to-alonzo/update-2.sh" echo " 3. restart the nodes" echo " wait for the next epoch for the update to take effect" echo -echo " 4. invoke ./scripts/byron-to-mary/update-3.sh " +echo " 4. invoke ./scripts/byron-to-alonzo/update-3.sh " echo " Here, the current epoch (2 if you're quick)." echo " If you provide the wrong epoch, you will see an error" echo " that will tell you the current epoch, and can run" echo " the script again." echo " 5. restart the nodes" echo " wait for the next epoch for the update to take effect" -echo " 6. invoke ./scripts/byron-to-mary/update-4.sh " +echo " 6. invoke ./scripts/byron-to-alonzo/update-4.sh " echo " 7. restart the nodes" echo echo "You can observe the status of the updates by grepping the logs, via" @@ -545,7 +549,27 @@ popd # For an automatic transition at epoch 0, specifying mary, allegra or shelley # will start the node in the appropriate era. echo "" -if [ "$1" = "mary" ]; then +if [ "$1" = "alonzo" ]; then + echo "TestShelleyHardForkAtEpoch: 0" >> ${ROOT}/configuration.yaml + echo "TestAllegraHardForkAtEpoch: 0" >> ${ROOT}/configuration.yaml + echo "TestMaryHardForkAtEpoch: 0" >> ${ROOT}/configuration.yaml + echo "TestAlonzoHardForkAtEpoch: 0" >> ${ROOT}/configuration.yaml + echo "TestEnableDevelopmentHardForkEras: True" >> ${ROOT}/configuration.yaml + echo "TestEnableDevelopmentNetworkProtocols: True" >> ${ROOT}/configuration.yaml + + sed -i ${ROOT}/configuration.yaml \ + -e 's/LastKnownBlockVersion-Major: 1/LastKnownBlockVersion-Major: 5/' + + # Update shelley genesis with required Alonzo fields. + alonzogenesisparams='.+ {adaPerUTxOWord: 0, executionPrices: {prMem: 1, prSteps: 1}, maxTxExUnits: {exUnitsMem: 1, exUnitsSteps: 1}, maxBlockExUnits: {exUnitsMem: 1, exUnitsSteps: 1}, maxValueSize: 1000, costModels: "example/shelley/alonzo/costmodel.json", collateralPercentage: 100, maxCollateralInputs: 1}' + alonzogenesis=$(jq "${alonzogenesisparams}" < ${ROOT}/shelley/genesis.json) + echo "${alonzogenesis}" > ${ROOT}/shelley/genesis.json + # Copy the cost model + mkdir ${ROOT}/shelley/alonzo + cp configuration/cardano/alonzo/shelley_qa_cost-model.json ${ROOT}/shelley/alonzo/costmodel.json + echo "Nodes will start in Alonzo era from epoch 0" + +elif [ "$1" = "mary" ]; then echo "TestShelleyHardForkAtEpoch: 0" >> ${ROOT}/configuration.yaml echo "TestAllegraHardForkAtEpoch: 0" >> ${ROOT}/configuration.yaml echo "TestMaryHardForkAtEpoch: 0" >> ${ROOT}/configuration.yaml diff --git a/scripts/byron-to-mary/update-1.sh b/scripts/byron-to-alonzo/update-1.sh similarity index 100% rename from scripts/byron-to-mary/update-1.sh rename to scripts/byron-to-alonzo/update-1.sh diff --git a/scripts/byron-to-mary/update-2.sh b/scripts/byron-to-alonzo/update-2.sh similarity index 100% rename from scripts/byron-to-mary/update-2.sh rename to scripts/byron-to-alonzo/update-2.sh diff --git a/scripts/byron-to-mary/update-3.sh b/scripts/byron-to-alonzo/update-3.sh similarity index 100% rename from scripts/byron-to-mary/update-3.sh rename to scripts/byron-to-alonzo/update-3.sh diff --git a/scripts/byron-to-mary/update-4.sh b/scripts/byron-to-alonzo/update-4.sh similarity index 100% rename from scripts/byron-to-mary/update-4.sh rename to scripts/byron-to-alonzo/update-4.sh