Skip to content

Commit 5625233

Browse files
committed
wip: cardano-api with kes-agent support
1 parent ee5af3f commit 5625233

File tree

23 files changed

+155
-57
lines changed

23 files changed

+155
-57
lines changed

cabal.project

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ repository cardano-haskell-packages
1414
-- you need to run if you change them
1515
index-state:
1616
, hackage.haskell.org 2025-06-22T20:18:27Z
17-
, cardano-haskell-packages 2025-06-20T09:11:51Z
17+
, cardano-haskell-packages 2025-07-22T10:42:20Z
1818

1919
packages:
2020
cardano-api
@@ -61,6 +61,7 @@ if impl (ghc >= 9.12)
6161
-- https://github.com/kapralVV/Unique/issues/11
6262
, Unique:hashable
6363

64+
6465
-- WASM compilation specific
6566

6667
if arch(wasm32)
@@ -156,3 +157,76 @@ if arch(wasm32)
156157
-- Do NOT add more source-repository-package stanzas here unless they are strictly
157158
-- temporary! Please read the section in CONTRIBUTING about updating dependencies.
158159

160+
allow-newer:
161+
, cardano-ledger-core
162+
, cardano-ledger-byron
163+
, serdoc-core:tasty-quickcheck
164+
165+
, kes-agent:containers
166+
-- , hedgehog-quickcheck:QuickCheck
167+
, *:QuickCheck
168+
169+
source-repository-package
170+
type: git
171+
location: https://github.com/input-output-hk/kes-agent
172+
tag: 60acf5d1c949695dc7822945b18fc916e7ef4391
173+
--sha256: sha256-oTsxaFAs1c/H0oYLhiivO5mr48oHNsPi5k2XyXxwCJg=
174+
subdir:
175+
kes-agent
176+
177+
source-repository-package
178+
type: git
179+
location: https://github.com/IntersectMBO/ouroboros-network
180+
tag: 253316ae1c5ec0eaf79f306eac1986969b7842a4
181+
--sha256: sha256-0HZ49kIgCrv/H9I/aUb+wFfRiVuZMrUofJFdgWPG17o=
182+
subdir: ouroboros-network-api
183+
ouroboros-network
184+
ouroboros-network-framework
185+
ouroboros-network-protocols
186+
187+
source-repository-package
188+
type: git
189+
location: https://github.com/IntersectMBO/cardano-ledger
190+
tag: ca8d451bbce11dde3b68e99782c79f9b4c1dfca5
191+
--sha256: sha256-YHIscWnp9GrFn0EYGM7xd8Ds8x0O00FWBAIZX22bWpA=
192+
subdir:
193+
eras/allegra/impl
194+
eras/alonzo/impl
195+
eras/alonzo/test-suite
196+
eras/babbage/impl
197+
eras/babbage/test-suite
198+
eras/byron/chain/executable-spec
199+
eras/byron/crypto
200+
eras/byron/ledger/executable-spec
201+
eras/byron/ledger/impl
202+
eras/conway/impl
203+
eras/conway/test-suite
204+
eras/dijkstra/
205+
eras/mary/impl
206+
eras/shelley/impl
207+
eras/shelley-ma/test-suite
208+
eras/shelley/test-suite
209+
libs/cardano-data
210+
libs/cardano-ledger-api
211+
libs/cardano-ledger-binary
212+
libs/cardano-ledger-core
213+
libs/cardano-ledger-test
214+
libs/cardano-protocol-tpraos
215+
libs/constrained-generators
216+
libs/non-integral
217+
libs/set-algebra
218+
libs/small-steps
219+
libs/vector-map
220+
221+
source-repository-package
222+
type: git
223+
location: https://github.com/IntersectMBO/ouroboros-consensus
224+
tag: 26c831eb40bd15750ef8243285466fe9bd582cf7
225+
--sha256: sha256-oTsxaFAs1c/H0oYLhiivO5mr48oHNsPi5k2XyXxwCJg=
226+
subdir:
227+
ouroboros-consensus
228+
ouroboros-consensus-cardano
229+
ouroboros-consensus-diffusion
230+
ouroboros-consensus-protocol
231+
sop-extras
232+
strict-sop-core

cardano-api/cardano-api.cabal

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ library
130130
cardano-ledger-binary >=1.6,
131131
cardano-ledger-byron >=1.1,
132132
cardano-ledger-conway >=1.19,
133-
cardano-ledger-core:{cardano-ledger-core, testlib} >=1.17,
133+
cardano-ledger-core:{cardano-ledger-core, testlib} >=1.17 && <1.19,
134134
cardano-ledger-mary >=1.8,
135135
cardano-ledger-shelley >=1.16,
136136
cardano-protocol-tpraos >=1.4,
@@ -164,11 +164,11 @@ library
164164
ouroboros-consensus-diffusion ^>=0.23,
165165
ouroboros-consensus-protocol ^>=0.12,
166166
ouroboros-network,
167-
ouroboros-network-api >=0.14,
167+
ouroboros-network-api >=0.15,
168168
ouroboros-network-framework,
169-
ouroboros-network-protocols >=0.14,
169+
ouroboros-network-protocols >=0.15,
170170
parsec,
171-
plutus-ledger-api:{plutus-ledger-api, plutus-ledger-api-testlib} ^>=1.45,
171+
plutus-ledger-api:{plutus-ledger-api, plutus-ledger-api-testlib} ^>=1.50,
172172
pretty-simple,
173173
prettyprinter,
174174
prettyprinter-ansi-terminal,
@@ -186,7 +186,7 @@ library
186186
time,
187187
transformers,
188188
transformers-except ^>=0.1.3,
189-
typed-protocols ^>=0.3,
189+
typed-protocols ^>=1.0,
190190
vector,
191191
yaml,
192192

@@ -312,7 +312,7 @@ library gen
312312
cardano-crypto-class ^>=2.2.1,
313313
cardano-crypto-test ^>=1.6,
314314
cardano-ledger-alonzo:{cardano-ledger-alonzo, testlib} >=1.8.1,
315-
cardano-ledger-byron-test >=1.5,
315+
cardano-ledger-byron:{testlib} >=1.1,
316316
cardano-ledger-conway:testlib,
317317
cardano-ledger-core:{cardano-ledger-core, testlib} >=1.14,
318318
cardano-ledger-shelley >=1.13,
@@ -428,7 +428,7 @@ test-suite cardano-api-golden
428428
hedgehog >=1.1,
429429
hedgehog-extras ^>=0.8,
430430
microlens,
431-
plutus-core ^>=1.45,
431+
plutus-core ^>=1.50,
432432
plutus-ledger-api,
433433
tasty,
434434
tasty-discover,

cardano-api/src/Cardano/Api/Block.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ import Ouroboros.Consensus.Byron.Ledger qualified as Consensus
7272
import Ouroboros.Consensus.Cardano.Block qualified as Consensus
7373
import Ouroboros.Consensus.HardFork.Combinator qualified as Consensus
7474
import Ouroboros.Consensus.Shelley.Ledger qualified as Consensus
75-
import Ouroboros.Consensus.Shelley.Protocol.Abstract qualified as Consensus
7675
import Ouroboros.Network.Block qualified as Consensus
7776

7877
import Data.Aeson (FromJSON (..), ToJSON (..), Value (..), object, withObject, (.:), (.=))
@@ -167,7 +166,6 @@ getShelleyBlockTxs
167166
:: forall era ledgerera blockheader
168167
. ShelleyLedgerEra era ~ ledgerera
169168
=> Consensus.ShelleyCompatible (ConsensusProtocol era) ledgerera
170-
=> Consensus.ShelleyProtocolHeader (ConsensusProtocol era) ~ blockheader
171169
=> ShelleyBasedEra era
172170
-> Ledger.Block blockheader ledgerera
173171
-> [Tx era]
@@ -203,6 +201,7 @@ fromConsensusBlock = \case
203201
Consensus.BlockAlonzo b' -> BlockInMode cardanoEra $ ShelleyBlock ShelleyBasedEraAlonzo b'
204202
Consensus.BlockBabbage b' -> BlockInMode cardanoEra $ ShelleyBlock ShelleyBasedEraBabbage b'
205203
Consensus.BlockConway b' -> BlockInMode cardanoEra $ ShelleyBlock ShelleyBasedEraConway b'
204+
_ -> undefined
206205

207206
toConsensusBlock
208207
:: ()

cardano-api/src/Cardano/Api/Certificate/Internal.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ filterUnRegCreds =
576576
Ledger.RetirePoolTxCert _ _ -> Nothing
577577
Ledger.MirTxCert _ -> Nothing
578578
Ledger.GenesisDelegTxCert{} -> Nothing
579+
_ -> undefined
579580
ConwayCertificate cEra conwayCert -> conwayEraOnwardsConstraints cEra $
580581
case conwayCert of
581582
Ledger.RegPoolTxCert _ -> Nothing
@@ -593,6 +594,7 @@ filterUnRegCreds =
593594
Ledger.RegTxCert _ -> Nothing
594595
-- stake cred deregistration w/o deposit
595596
Ledger.UnRegTxCert cred -> Just cred
597+
_ -> undefined
596598

597599
filterUnRegDRepCreds
598600
:: Certificate era -> Maybe (Ledger.Credential Ledger.DRepRole)
@@ -615,6 +617,7 @@ filterUnRegDRepCreds = \case
615617
Ledger.RegTxCert _ -> Nothing
616618
-- stake cred deregistration w/o deposit
617619
Ledger.UnRegTxCert _ -> Nothing
620+
_ -> undefined
618621

619622
-- ----------------------------------------------------------------------------
620623
-- Internal conversion functions
@@ -803,6 +806,7 @@ getAnchorDataFromCertificate c =
803806
Ledger.RetirePoolTxCert _ _ -> return Nothing
804807
Ledger.GenesisDelegTxCert{} -> return Nothing
805808
Ledger.MirTxCert _ -> return Nothing
809+
_ -> undefined
806810
ConwayCertificate ceo ccert ->
807811
conwayEraOnwardsConstraints ceo $
808812
case ccert of
@@ -819,6 +823,7 @@ getAnchorDataFromCertificate c =
819823
Ledger.UpdateDRepTxCert _ mAnchor -> return $ Ledger.strictMaybeToMaybe mAnchor
820824
Ledger.AuthCommitteeHotKeyTxCert _ _ -> return Nothing
821825
Ledger.ResignCommitteeColdTxCert _ mAnchor -> return $ Ledger.strictMaybeToMaybe mAnchor
826+
_ -> undefined
822827
where
823828
anchorDataFromPoolMetadata
824829
:: MonadError AnchorDataFromCertificateError m

cardano-api/src/Cardano/Api/Consensus/Internal/InMode.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ fromConsensusGenTx = \case
100100
Consensus.HardForkGenTx (Consensus.OneEraGenTx (S (S (S (S (S (S (Z tx')))))))) ->
101101
let Consensus.ShelleyTx _txid shelleyEraTx = tx'
102102
in TxInMode ShelleyBasedEraConway (ShelleyTx ShelleyBasedEraConway shelleyEraTx)
103+
_ -> undefined
103104

104105
toConsensusGenTx
105106
:: ()
@@ -302,3 +303,4 @@ fromConsensusApplyTxErr = \case
302303
TxValidationErrorInCardanoMode $ ShelleyTxValidationError ShelleyBasedEraConway err
303304
Consensus.ApplyTxErrWrongEra err ->
304305
TxValidationEraMismatch err
306+
_ -> undefined

cardano-api/src/Cardano/Api/Consensus/Internal/Mode.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,5 @@ fromConsensusEraIndex = \case
161161
AnyCardanoEra BabbageEra
162162
Consensus.EraIndex (S (S (S (S (S (S (Z (K ())))))))) ->
163163
AnyCardanoEra ConwayEra
164+
Consensus.EraIndex (S (S (S (S (S (S (S (Z (K ()))))))))) ->
165+
AnyCardanoEra ConwayEra

cardano-api/src/Cardano/Api/Consensus/Internal/Protocol.hs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ where
2222

2323
import Cardano.Api.Consensus.Internal.Mode
2424

25+
import qualified Control.Tracer as Tracer
2526
import Ouroboros.Consensus.Block.Forging (BlockForging)
2627
import Ouroboros.Consensus.Byron.ByronHFC (ByronBlockHFC)
2728
import Ouroboros.Consensus.Cardano
@@ -31,6 +32,7 @@ import Ouroboros.Consensus.HardFork.Combinator.Embed.Unary
3132
import Ouroboros.Consensus.Ledger.SupportsProtocol qualified as Consensus (LedgerSupportsProtocol)
3233
import Ouroboros.Consensus.Node.ProtocolInfo (ProtocolClientInfo (..), ProtocolInfo (..))
3334
import Ouroboros.Consensus.Node.Run (RunNode)
35+
import Ouroboros.Consensus.Protocol.Praos.AgentClient
3436
import Ouroboros.Consensus.Protocol.TPraos qualified as Consensus
3537
import Ouroboros.Consensus.Shelley.Eras qualified as Consensus (ShelleyEra)
3638
import Ouroboros.Consensus.Shelley.Ledger.Block qualified as Consensus (ShelleyBlock)
@@ -44,7 +46,11 @@ import Type.Reflection ((:~:) (..))
4446

4547
class (RunNode blk, IOLike m) => Protocol m blk where
4648
data ProtocolInfoArgs blk
47-
protocolInfo :: ProtocolInfoArgs blk -> (ProtocolInfo blk, m [BlockForging m blk])
49+
protocolInfo
50+
:: ProtocolInfoArgs blk
51+
-> ( ProtocolInfo blk
52+
, Tracer.Tracer m KESAgentClientTrace -> m [BlockForging m blk]
53+
)
4854

4955
-- | Node client support for each consensus protocol.
5056
--
@@ -59,10 +65,10 @@ instance IOLike m => Protocol m ByronBlockHFC where
5965
data ProtocolInfoArgs ByronBlockHFC = ProtocolInfoArgsByron ProtocolParamsByron
6066
protocolInfo (ProtocolInfoArgsByron params) =
6167
( inject $ protocolInfoByron params
62-
, pure . map inject $ blockForgingByron params
68+
, \_ -> pure . map inject $ blockForgingByron params
6369
)
6470

65-
instance (CardanoHardForkConstraints StandardCrypto, IOLike m) => Protocol m (CardanoBlock StandardCrypto) where
71+
instance (CardanoHardForkConstraints StandardCrypto, IOLike m, MonadKESAgent m) => Protocol m (CardanoBlock StandardCrypto) where
6672
data ProtocolInfoArgs (CardanoBlock StandardCrypto)
6773
= ProtocolInfoArgsCardano
6874
(CardanoProtocolParams StandardCrypto)
@@ -89,6 +95,7 @@ instance
8995
(Consensus.TPraos StandardCrypto)
9096
ShelleyEra
9197
)
98+
, MonadKESAgent m
9299
)
93100
=> Protocol m (ShelleyBlockHFC (Consensus.TPraos StandardCrypto) ShelleyEra)
94101
where
@@ -98,7 +105,7 @@ instance
98105
(ProtocolParamsShelleyBased StandardCrypto)
99106
ProtVer
100107
protocolInfo (ProtocolInfoArgsShelley genesis paramsShelleyBased_ paramsShelley_) =
101-
bimap inject (fmap $ map inject) $
108+
bimap inject (fmap $ fmap $ map inject) $
102109
protocolInfoShelley genesis paramsShelleyBased_ paramsShelley_
103110

104111
instance

cardano-api/src/Cardano/Api/Experimental/Plutus/Internal/ScriptWitness.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ getPlutusScriptWitnessLanguage (PlutusScriptWitness l _ _ _ _) =
7474
L.SPlutusV1 -> L.plutusLanguage l
7575
L.SPlutusV2 -> L.plutusLanguage l
7676
L.SPlutusV3 -> L.plutusLanguage l
77+
_ -> undefined
7778

7879
-- | Every Plutus script has a purpose that indicates
7980
-- what that script is witnessing.

cardano-api/src/Cardano/Api/Experimental/Tx.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ import Cardano.Crypto.Hash qualified as Hash
167167
import Cardano.Ledger.Alonzo.TxBody qualified as L
168168
import Cardano.Ledger.Api qualified as L
169169
import Cardano.Ledger.Binary qualified as Ledger
170-
import Cardano.Ledger.Conway.TxBody qualified as L
171170
import Cardano.Ledger.Core qualified as Ledger
172171
import Cardano.Ledger.Hashes qualified as L hiding (Hash)
173172

cardano-api/src/Cardano/Api/Experimental/Tx/Internal/AnyWitness.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ fromPlutusRunnable L.SPlutusV3 eon runnable =
143143
AlonzoEraOnwardsConway ->
144144
let plutusScript = L.plutusFromRunnable runnable
145145
in Just $ L.ConwayPlutusV3 plutusScript
146+
fromPlutusRunnable _ _ _ = undefined
146147

147148
toAlonzoDatum
148149
:: AlonzoEraOnwards era
@@ -162,3 +163,5 @@ getPlutusDatum L.SPlutusV2 (SpendingScriptDatum d) = Just d
162163
getPlutusDatum L.SPlutusV3 (SpendingScriptDatum d) = d
163164
getPlutusDatum _ InlineDatum = Nothing
164165
getPlutusDatum _ NoScriptDatum = Nothing
166+
getPlutusDatum _ _ = undefined
167+

0 commit comments

Comments
 (0)