Skip to content

Commit

Permalink
Accommodate ouroboros-consensus API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bolt12 committed Jun 23, 2023
1 parent 0059ec4 commit f670335
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 11 deletions.
22 changes: 21 additions & 1 deletion cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
10 changes: 6 additions & 4 deletions cardano-api/internal/Cardano/Api/LedgerState.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions cardano-api/internal/Cardano/Api/Protocol.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
--
Expand All @@ -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) =
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f670335

Please sign in to comment.