Skip to content

Commit 5e32849

Browse files
committed
wip: cardano-api with kes-agent support
1 parent f9dba57 commit 5e32849

File tree

10 files changed

+118
-44
lines changed

10 files changed

+118
-44
lines changed

cabal.project

Lines changed: 72 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,75 @@ if impl (ghc >= 9.12)
6565
-- https://github.com/kapralVV/Unique/issues/11
6666
, Unique:hashable
6767

68-
, network-mux:base
69-
, ouroboros-network:base
70-
, ouroboros-network-api:base
71-
, ouroboros-network-framework:base
72-
, ouroboros-network-protocols:base
73-
68+
, network-mux:base
69+
, ouroboros-network:base
70+
, ouroboros-network-api:base
71+
, ouroboros-network-framework:base
72+
, ouroboros-network-protocols:base
73+
74+
allow-newer:
75+
cardano-ledger-core,
76+
cardano-ledger-byron,
77+
serdoc-core:tasty-quickcheck,
78+
79+
source-repository-package
80+
type: git
81+
location: https://github.com/input-output-hk/kes-agent
82+
tag: 07437ed49022b13759c87c4e314f08fcff64b81a
83+
--sha256: sha256-oTsxaFAs1c/H0oYLhiivO5mr48oHNsPi5k2XyXxwCJg=
84+
subdir:
85+
kes-agent
86+
87+
source-repository-package
88+
type: git
89+
location: https://github.com/IntersectMBO/ouroboros-network
90+
tag: 3e8d3b4b8c87ead794876c62d7fe25f32efb5142
91+
--sha256: 08fpkx3iagj83nn413h9a865zjcj3lrf7017a756qd2wg2jg3amq
92+
subdir:
93+
ouroboros-network-api
94+
95+
source-repository-package
96+
type: git
97+
location: https://github.com/IntersectMBO/cardano-ledger
98+
tag: b44ce911475794a15f908ad27a6f497d6a27e8ba
99+
--sha256: sha256-MXaVKKH9siUsmOnJmYyL6if48dx11zugux7AWGPABfA=
100+
subdir:
101+
eras/allegra/impl
102+
eras/alonzo/impl
103+
eras/alonzo/test-suite
104+
eras/babbage/impl
105+
eras/babbage/test-suite
106+
eras/byron/chain/executable-spec
107+
eras/byron/crypto
108+
eras/byron/ledger/executable-spec
109+
eras/byron/ledger/impl
110+
eras/conway/impl
111+
eras/conway/test-suite
112+
eras/mary/impl
113+
eras/shelley/impl
114+
eras/shelley-ma/test-suite
115+
eras/shelley/test-suite
116+
libs/cardano-data
117+
libs/cardano-ledger-api
118+
libs/cardano-ledger-binary
119+
libs/cardano-ledger-core
120+
libs/cardano-ledger-test
121+
libs/cardano-protocol-tpraos
122+
libs/constrained-generators
123+
libs/non-integral
124+
libs/set-algebra
125+
libs/small-steps
126+
libs/vector-map
127+
128+
source-repository-package
129+
type: git
130+
location: https://github.com/IntersectMBO/ouroboros-consensus
131+
tag: 9fdeacc0ba74009bd3078f08cd6b443a3f296515
132+
--sha256: sha256-oTsxaFAs1c/H0oYLhiivO5mr48oHNsPi5k2XyXxwCJg=
133+
subdir:
134+
ouroboros-consensus
135+
ouroboros-consensus-cardano
136+
ouroboros-consensus-diffusion
137+
ouroboros-consensus-protocol
138+
sop-extras
139+
strict-sop-core

cardano-api/cardano-api.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ library
129129
cardano-ledger-binary >=1.6,
130130
cardano-ledger-byron >=1.1,
131131
cardano-ledger-conway >=1.19,
132-
cardano-ledger-core:{cardano-ledger-core, testlib} >=1.17,
132+
cardano-ledger-core:{cardano-ledger-core, testlib} >=1.17 && <1.19,
133133
cardano-ledger-mary >=1.8,
134134
cardano-ledger-shelley >=1.16,
135135
cardano-protocol-tpraos >=1.4,

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

Lines changed: 0 additions & 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]

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/Ledger/Internal/Reexport.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ module Cardano.Api.Ledger.Internal.Reexport
112112
, toPlainDecoder
113113
-- Shelley
114114
, secondsToNominalDiffTimeMicro
115-
, AccountState (..)
115+
, ChainAccountState (..)
116116
, NewEpochState (..)
117117
, ShelleyGenesisStaking (..)
118118
-- Babbage
@@ -266,7 +266,7 @@ import Cardano.Ledger.Binary
266266
, toPlainDecoder
267267
)
268268
import Cardano.Ledger.Binary.Plain (Decoder, serializeAsHexText)
269-
import Cardano.Ledger.CertState (DRepState (..), csCommitteeCredsL)
269+
import Cardano.Ledger.Conway.State (DRepState (..), csCommitteeCredsL)
270270
import Cardano.Ledger.Coin (Coin (..), addDeltaCoin, toDeltaCoin)
271271
import Cardano.Ledger.Conway.Core
272272
( DRepVotingThresholds (..)
@@ -336,7 +336,7 @@ import Cardano.Ledger.Plutus.Data (Data (..), unData)
336336
import Cardano.Ledger.Plutus.Language (Language, Plutus, languageToText, plutusBinary)
337337
import Cardano.Ledger.PoolParams (PoolMetadata (..), PoolParams (..), StakePoolRelay (..))
338338
import Cardano.Ledger.Shelley.API
339-
( AccountState (..)
339+
( ChainAccountState (..)
340340
, GenDelegPair (..)
341341
, NewEpochState (..)
342342
, StakeReference (..)

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ import Ouroboros.Consensus.Ledger.Tables.Utils qualified as Ledger
193193
import Ouroboros.Consensus.Node.ProtocolInfo qualified as Consensus
194194
import Ouroboros.Consensus.Protocol.Abstract (ChainDepState, ConsensusProtocol (..))
195195
import Ouroboros.Consensus.Protocol.Praos qualified as Praos
196+
import Ouroboros.Consensus.Protocol.Praos.AgentClient
196197
import Ouroboros.Consensus.Protocol.Praos.Common qualified as Consensus
197198
import Ouroboros.Consensus.Protocol.Praos.VRF (mkInputVRF, vrfLeaderValue)
198199
import Ouroboros.Consensus.Protocol.TPraos qualified as TPraos
@@ -214,6 +215,7 @@ import Control.Error.Util (note)
214215
import Control.Exception.Safe
215216
import Control.Monad
216217
import Control.Monad.State.Strict
218+
import qualified Control.Tracer as Tracer
217219
import Data.Aeson as Aeson
218220
( FromJSON (parseJSON)
219221
, Object
@@ -1434,7 +1436,7 @@ mkProtocolInfoCardano
14341436
:: GenesisConfig
14351437
-> ( Consensus.ProtocolInfo
14361438
(Consensus.CardanoBlock Consensus.StandardCrypto)
1437-
, IO [BlockForging IO (Consensus.CardanoBlock Consensus.StandardCrypto)]
1439+
, Tracer.Tracer IO KESAgentClientTrace -> IO [BlockForging IO (Consensus.CardanoBlock Consensus.StandardCrypto)]
14381440
)
14391441
mkProtocolInfoCardano (GenesisCardano dnc byronGenesis shelleyGenesisHash transCfg) =
14401442
Consensus.protocolInfoCardano

cardano-api/src/Cardano/Api/Query/Internal/Convenience.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ import Cardano.Api.Query.Internal.Type.QueryInMode
3535
import Cardano.Api.Tx.Internal.Body
3636
import Cardano.Api.UTxO (UTxO (..))
3737

38-
import Cardano.Ledger.CertState (DRepState (..))
38+
import Cardano.Ledger.State (DRepState (..))
3939
import Cardano.Ledger.Coin qualified as L
4040
import Cardano.Ledger.Credential qualified as L
4141
import Cardano.Ledger.Keys qualified as L
42-
import Cardano.Ledger.Shelley.LedgerState qualified as L
42+
import Cardano.Ledger.State (ChainAccountState(..))
4343
import Ouroboros.Consensus.HardFork.Combinator.AcrossEras (EraMismatch (..))
4444
import Ouroboros.Network.Protocol.LocalStateQuery.Type (Target (..))
4545

@@ -164,11 +164,11 @@ queryStateForBalancedTx era allTxIns certs = runExceptT $ do
164164
caseShelleyToBabbageOrConwayEraOnwards
165165
(const $ pure Nothing)
166166
( \cOnwards -> do
167-
L.AccountState{L.asTreasury} <-
167+
ChainAccountState{casTreasury} <-
168168
lift (queryAccountState cOnwards)
169169
& onLeft (left . QceUnsupportedNtcVersion)
170170
& onLeft (left . QueryEraMismatch)
171-
let txCurrentTreasuryValue = TxCurrentTreasuryValue asTreasury
171+
let txCurrentTreasuryValue = TxCurrentTreasuryValue casTreasury
172172
return $ Just $ Featured cOnwards txCurrentTreasuryValue
173173
)
174174
sbe

cardano-api/src/Cardano/Api/Query/Internal/Expr.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,11 @@ import Cardano.Api.UTxO
5959

6060
import Cardano.Ledger.Api qualified as L
6161
import Cardano.Ledger.Api.State.Query qualified as L
62-
import Cardano.Ledger.CertState qualified as L
62+
import Cardano.Ledger.State qualified as L
6363
import Cardano.Ledger.Coin qualified as L
6464
import Cardano.Ledger.Credential qualified as L
6565
import Cardano.Ledger.Hashes hiding (Hash)
6666
import Cardano.Ledger.Keys qualified as L
67-
import Cardano.Ledger.Shelley.LedgerState qualified as L
6867
import Cardano.Slotting.Slot
6968
import Ouroboros.Consensus.Cardano.Block qualified as Consensus
7069
import Ouroboros.Consensus.HardFork.Combinator.AcrossEras as Consensus
@@ -484,7 +483,7 @@ queryAccountState
484483
QueryInMode
485484
r
486485
IO
487-
(Either UnsupportedNtcVersionError (Either EraMismatch L.AccountState))
486+
(Either UnsupportedNtcVersionError (Either EraMismatch L.ChainAccountState))
488487
queryAccountState eon = querySbe eon QueryAccountState
489488

490489
queryProposals

0 commit comments

Comments
 (0)