From f6703357b36b176265c8642dcfdebea134b7f86f Mon Sep 17 00:00:00 2001 From: Armando Santos Date: Mon, 12 Jun 2023 18:44:31 +0100 Subject: [PATCH] Accommodate ouroboros-consensus API changes --- cabal.project | 22 ++++++++++++++++++- .../internal/Cardano/Api/LedgerState.hs | 10 +++++---- cardano-api/internal/Cardano/Api/Protocol.hs | 11 +++++++--- flake.lock | 6 ++--- 4 files changed, 38 insertions(+), 11 deletions(-) diff --git a/cabal.project b/cabal.project index dd0acbaa61..ef5f6ca741 100644 --- a/cabal.project +++ b/cabal.project @@ -14,7 +14,7 @@ repository cardano-haskell-packages -- you need to run if you change them index-state: , hackage.haskell.org 2023-05-10T10:34:57Z - , cardano-haskell-packages 2023-05-24T10:41:02Z + , cardano-haskell-packages 2023-06-20T22:19:21Z packages: cardano-api @@ -41,3 +41,23 @@ write-ghc-environment-files: always -- IMPORTANT -- Do NOT add more source-repository-package stanzas here unless they are strictly -- temporary! Please read the section in CONTRIBUTING about updating dependencies. + +source-repository-package + type: git + location: https://github.com/input-output-hk/ouroboros-consensus + tag: e0d484a6f6f90b8b3268366bb4478c469a18922c + --sha256: sha256-dYObo/zzwPxyWuRNpuiqL33oiRj7Jlqoz5O3WviOF6g= + subdir: + ouroboros-consensus + ouroboros-consensus-diffusion + ouroboros-consensus-cardano + ouroboros-consensus-protocol + +-- Needed because consensus uses it +source-repository-package + type: git + location: https://github.com/input-output-hk/io-sim + tag: ec202298c420378ef90b3fc0126c39e0f52290a3 + --sha256: 1p6pn83kwp66x2m0cw9a27blfcpmw0lrra72qd0pi5bj3v1bcrl9 + subdir: + strict-mvar diff --git a/cardano-api/internal/Cardano/Api/LedgerState.hs b/cardano-api/internal/Cardano/Api/LedgerState.hs index 5a7c67805f..69b36dc08e 100644 --- a/cardano-api/internal/Cardano/Api/LedgerState.hs +++ b/cardano-api/internal/Cardano/Api/LedgerState.hs @@ -134,6 +134,7 @@ import qualified Cardano.Slotting.EpochInfo.API as Slot import Cardano.Slotting.Slot (WithOrigin (At, Origin)) import qualified Cardano.Slotting.Slot as Slot import qualified Ouroboros.Consensus.Block.Abstract as Consensus +import Ouroboros.Consensus.Block.Forging (BlockForging) import qualified Ouroboros.Consensus.Byron.Ledger.Block as Byron import qualified Ouroboros.Consensus.Byron.Ledger.Ledger as Byron import qualified Ouroboros.Consensus.Cardano as Consensus @@ -772,7 +773,7 @@ genesisConfigToEnv ] | otherwise -> let - topLevelConfig = Consensus.pInfoConfig (mkProtocolInfoCardano genCfg) + topLevelConfig = Consensus.pInfoConfig $ fst $ mkProtocolInfoCardano genCfg in Right $ Env { envLedgerConfig = Consensus.topLevelConfigLedger topLevelConfig @@ -912,7 +913,7 @@ readByteString fp cfgType = ExceptT $ initLedgerStateVar :: GenesisConfig -> LedgerState initLedgerStateVar genesisConfig = LedgerState - { clsState = Ledger.ledgerState $ Consensus.pInfoInitLedger protocolInfo + { clsState = Ledger.ledgerState $ Consensus.pInfoInitLedger $ fst protocolInfo } where protocolInfo = mkProtocolInfoCardano genesisConfig @@ -989,10 +990,11 @@ type NodeConfigFile = File NodeConfig mkProtocolInfoCardano :: GenesisConfig -> - Consensus.ProtocolInfo - IO + (Consensus.ProtocolInfo (HFC.HardForkBlock (Consensus.CardanoEras Consensus.StandardCrypto)) + , IO [BlockForging IO (HFC.HardForkBlock + (Consensus.CardanoEras Consensus.StandardCrypto))]) mkProtocolInfoCardano (GenesisCardano dnc byronGenesis shelleyGenesis alonzoGenesis conwayGenesis) = Consensus.protocolInfoCardano Consensus.ProtocolParamsByron diff --git a/cardano-api/internal/Cardano/Api/Protocol.hs b/cardano-api/internal/Cardano/Api/Protocol.hs index 51426d78b6..66f1346555 100644 --- a/cardano-api/internal/Cardano/Api/Protocol.hs +++ b/cardano-api/internal/Cardano/Api/Protocol.hs @@ -17,6 +17,9 @@ module Cardano.Api.Protocol import Cardano.Api.Modes +import Data.Bifunctor (bimap) + +import Ouroboros.Consensus.Block.Forging (BlockForging) import Ouroboros.Consensus.Cardano import Ouroboros.Consensus.Cardano.Block import Ouroboros.Consensus.Cardano.ByronHFC (ByronBlockHFC) @@ -35,7 +38,7 @@ import Ouroboros.Consensus.Util.IOLike (IOLike) class (RunNode blk, IOLike m) => Protocol m blk where data ProtocolInfoArgs m blk - protocolInfo :: ProtocolInfoArgs m blk -> ProtocolInfo m blk + protocolInfo :: ProtocolInfoArgs m blk -> (ProtocolInfo blk, m [BlockForging m blk]) -- | Node client support for each consensus protocol. -- @@ -50,7 +53,9 @@ class RunNode blk => ProtocolClient blk where -- | Run PBFT against the Byron ledger instance IOLike m => Protocol m ByronBlockHFC where data ProtocolInfoArgs m ByronBlockHFC = ProtocolInfoArgsByron ProtocolParamsByron - protocolInfo (ProtocolInfoArgsByron params) = inject $ protocolInfoByron params + protocolInfo (ProtocolInfoArgsByron params) = ( inject $ protocolInfoByron params + , pure . map inject $ blockForgingByron params + ) instance (CardanoHardForkConstraints StandardCrypto, IOLike m) => Protocol m (CardanoBlock StandardCrypto) where data ProtocolInfoArgs m (CardanoBlock StandardCrypto) = @@ -123,7 +128,7 @@ instance ( IOLike m (ProtocolParamsShelleyBased StandardShelley) (ProtocolParamsShelley StandardCrypto) protocolInfo (ProtocolInfoArgsShelley paramsShelleyBased paramsShelley) = - inject $ protocolInfoShelley paramsShelleyBased paramsShelley + bimap inject (fmap $ map inject) $ protocolInfoShelley paramsShelleyBased paramsShelley instance Consensus.LedgerSupportsProtocol (Consensus.ShelleyBlock diff --git a/flake.lock b/flake.lock index 9e9ff71d06..a20909738d 100644 --- a/flake.lock +++ b/flake.lock @@ -3,11 +3,11 @@ "CHaP": { "flake": false, "locked": { - "lastModified": 1685707241, - "narHash": "sha256-3vwY0mo8lf+0n+H6g3giXtVLQeXt/l9+FlsOpfi7CwM=", + "lastModified": 1687312611, + "narHash": "sha256-Tvq04QEK/Kkj977GM3p7KxGtOrl15ef2y6OagSS5gtM=", "owner": "input-output-hk", "repo": "cardano-haskell-packages", - "rev": "2baceb51b8f3175e05e94fdd4780cc717aeb2a6f", + "rev": "42e80e6600314053b7e0db2cb71725b9a1c8cdcf", "type": "github" }, "original": {