Skip to content

Commit aaab28c

Browse files
Jimbo4350carbolymer
authored andcommitted
Add gRPC to cardano-node
1 parent 6a9b76f commit aaab28c

File tree

23 files changed

+570
-48
lines changed

23 files changed

+570
-48
lines changed

.github/workflows/haskell.yml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
# If you edit these versions, make sure the version in the lonely macos-latest job below is updated accordingly
3939
# TODO add 9.8 again to the versions list when GHC-9.8 gets released with stm > 2.5.2,
4040
# see https://github.com/haskell/stm/issues/76
41-
ghc: ["9.6", "9.12"]
41+
ghc: ["9.6", "9.10"]
4242
cabal: ["3.12"]
4343
sys:
4444
- { os: windows-latest, shell: 'C:/msys64/usr/bin/bash.exe -e {0}' }
@@ -97,6 +97,18 @@ jobs:
9797
with:
9898
use-sodium-vrf: true # default is true
9999

100+
- name: "[Linux] Install grpc dependencies"
101+
if: runner.os == 'Linux'
102+
run: sudo apt install libsnappy-dev protobuf-compiler
103+
104+
- name: "[Windows] Install grpc dependencies"
105+
if: runner.os == 'Windows'
106+
run: /usr/bin/pacman --noconfirm -S mingw-w64-x86_64-snappy mingw-w64-x86_64-protobuf
107+
108+
- name: "[macOS] Install grpc dependencies"
109+
if: runner.os == 'macOS'
110+
run: brew install snappy protobuf
111+
100112
- uses: actions/checkout@v4
101113

102114
- name: Cabal update
@@ -230,9 +242,9 @@ jobs:
230242
# and will silently fail if msys2 is not in path. See the "Run tests" step.
231243
#
232244
# - name: Setup tmate session
233-
# if: ${{ failure() }}
234-
# uses: mxschmitt/action-tmate@v3
235-
# with:
245+
# if: ${{ failure() }}
246+
# uses: mxschmitt/action-tmate@v3
247+
# with:
236248
# limit-access-to-actor: true
237249

238250
build-complete:

bench/tx-generator/src/Cardano/TxGenerator/Setup/Plutus.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import Cardano.Benchmarking.PlutusScripts (findPlutusScript)
4040
#endif
4141
import Control.Exception (SomeException (..), try)
4242
import System.FilePath ((<.>), (</>))
43+
import RIO (runRIO)
4344

4445
import Paths_tx_generator
4546

@@ -71,7 +72,7 @@ readPlutusScript (Left s)
7172
doLoad fp = second (second (const $ ResolvedToFallback asFileName)) <$> readPlutusScript (Right fp)
7273
readPlutusScript (Right fp)
7374
= runExceptT $ do
74-
script <- firstExceptT ApiError $
75+
script <- runRIO () $
7576
readFileScriptInAnyLang fp
7677
case script of
7778
ScriptInAnyLang (PlutusScriptLanguage _) _ -> pure (script, ResolvedToFileName fp)

bench/tx-generator/tx-generator.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ library
142142
, network
143143
, network-mux
144144
, optparse-applicative-fork
145+
, rio
145146
, ouroboros-consensus >= 0.6
146147
, ouroboros-consensus-cardano >= 0.5
147148
, ouroboros-consensus-diffusion >= 0.7.0

cabal.project

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ package plutus-scripts-bench
6161
allow-newer:
6262
, katip:Win32
6363

64+
65+
if impl (ghc >= 9.10)
66+
allow-newer:
67+
-- TODO: remove - this is for protolens
68+
, *:base
69+
, *:ghc-prim
70+
6471
if impl (ghc >= 9.12)
6572
allow-newer:
6673
-- https://github.com/kapralVV/Unique/issues/11
@@ -72,3 +79,22 @@ if impl (ghc >= 9.12)
7279
-- IMPORTANT
7380
-- Do NOT add more source-repository-package stanzas here unless they are strictly
7481
-- temporary! Please read the section in CONTRIBUTING about updating dependencies.
82+
83+
84+
source-repository-package
85+
type: git
86+
location: https://github.com/intersectmbo/cardano-api
87+
-- mgalazyn/feature/add-utxorpc-protocol-parameters-query
88+
tag: 87b2afaaa037b78d1bed92257413fa9fdf2f156c
89+
--sha256: sha256-VZv++ErHQZoG/OokIoQKGfqpKAcdm7dXPD8BzXKAkxU=
90+
subdir: cardano-api
91+
cardano-api-gen
92+
cardano-rpc
93+
94+
source-repository-package
95+
type: git
96+
location: https://github.com/intersectmbo/cardano-cli
97+
-- mgalazyn/chore/remove-upstreamed-instances
98+
tag: 386b22edd41820584857537203ca39caca61d158
99+
--sha256: sha256-wsP5leh9EIgmG0wVLuaPizHFylvS8LGt7D2erLZbs5s=
100+
subdir: cardano-cli

cardano-node/cardano-node.cabal

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ library
158158
, cardano-prelude
159159
, cardano-protocol-tpraos >= 1.4
160160
, cardano-slotting >= 0.2
161+
, cardano-rpc ^>= 10.0
161162
, cborg ^>= 0.2.4
162163
, containers
163164
, contra-tracer
@@ -221,6 +222,7 @@ library
221222
, typed-protocols-stateful >= 0.3
222223
, yaml
223224

225+
224226
executable cardano-node
225227
import: project-config
226228
hs-source-dirs: app
@@ -256,6 +258,7 @@ test-suite cardano-node-test
256258
, cardano-crypto-class
257259
, cardano-crypto-wrapper
258260
, cardano-api
261+
, cardano-rpc
259262
, cardano-protocol-tpraos
260263
, cardano-node
261264
, cardano-slotting

cardano-node/src/Cardano/Node/Configuration/POM.hs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
{-# OPTIONS_GHC -Wno-noncanonical-monoid-instances #-}
1212

13+
{- HLINT ignore "Functor law" -}
14+
1315
module Cardano.Node.Configuration.POM
1416
( NodeConfiguration (..)
1517
, ResponderCoreAffinityPolicy (..)
@@ -36,6 +38,8 @@ import Cardano.Node.Configuration.Socket (SocketConfig (..))
3638
import Cardano.Node.Handlers.Shutdown
3739
import Cardano.Node.Protocol.Types (Protocol (..))
3840
import Cardano.Node.Types
41+
import Cardano.Rpc.Server.Config (PartialRpcConfig, RpcConfig, RpcConfigF (..),
42+
makeRpcConfig)
3943
import Cardano.Tracing.Config
4044
import Cardano.Tracing.OrphanInstances.Network ()
4145
import qualified Ouroboros.Cardano.Network.Diffusion.Configuration as Cardano
@@ -203,6 +207,9 @@ data NodeConfiguration
203207
, ncGenesisConfig :: GenesisConfig
204208

205209
, ncResponderCoreAffinityPolicy :: ResponderCoreAffinityPolicy
210+
211+
-- gRPC
212+
, ncRpcConfig :: RpcConfig
206213
} deriving (Eq, Show)
207214

208215
-- | We expose the `Ouroboros.Network.Mux.ForkPolicy` as a `NodeConfiguration` field.
@@ -283,13 +290,13 @@ data PartialNodeConfiguration
283290
, pncSyncTargetOfKnownBigLedgerPeers :: !(Last Int)
284291
, pncSyncTargetOfEstablishedBigLedgerPeers :: !(Last Int)
285292
, pncSyncTargetOfActiveBigLedgerPeers :: !(Last Int)
293+
-- Consensus mode for diffusion layer
294+
, pncConsensusMode :: !(Last ConsensusMode)
295+
286296
-- Minimum number of active big ledger peers we must be connected to
287297
-- in Genesis mode
288298
, pncMinBigLedgerPeersForTrustedState :: !(Last NumberOfBigLedgerPeers)
289299

290-
-- Consensus mode for diffusion layer
291-
, pncConsensusMode :: !(Last ConsensusMode)
292-
293300
-- Network P2P mode
294301
, pncEnableP2P :: !(Last NetworkP2PMode)
295302

@@ -300,6 +307,9 @@ data PartialNodeConfiguration
300307
, pncGenesisConfigFlags :: !(Last GenesisConfigFlags)
301308

302309
, pncResponderCoreAffinityPolicy :: !(Last ResponderCoreAffinityPolicy)
310+
311+
-- gRPC
312+
, pncRpcConfig :: !PartialRpcConfig
303313
} deriving (Eq, Generic, Show)
304314

305315
instance AdjustFilePaths PartialNodeConfiguration where
@@ -417,6 +427,12 @@ instance FromJSON PartialNodeConfiguration where
417427
<$> v .:? "ResponderCoreAffinityPolicy"
418428
<*> v .:? "ForkPolicy" -- deprecated
419429

430+
pncRpcConfig <-
431+
RpcConfig
432+
<$> (Last <$> v .:? "EnableRpc")
433+
<*> (Last <$> v .:? "RpcSocketPath")
434+
<*> pure mempty
435+
420436
pure PartialNodeConfiguration {
421437
pncProtocolConfig
422438
, pncSocketConfig = Last . Just $ SocketConfig mempty mempty mempty pncSocketPath
@@ -462,6 +478,7 @@ instance FromJSON PartialNodeConfiguration where
462478
, pncPeerSharing
463479
, pncGenesisConfigFlags
464480
, pncResponderCoreAffinityPolicy
481+
, pncRpcConfig
465482
}
466483
where
467484
parseMempoolCapacityBytesOverride v = parseNoOverride <|> parseOverride
@@ -709,6 +726,7 @@ defaultPartialNodeConfiguration =
709726
, pncGenesisConfigFlags = Last (Just defaultGenesisConfigFlags)
710727
-- https://ouroboros-consensus.cardano.intersectmbo.org/haddocks/ouroboros-consensus-diffusion/Ouroboros-Consensus-Node-Genesis.html#v:defaultGenesisConfigFlags
711728
, pncResponderCoreAffinityPolicy = Last $ Just NoResponderCoreAffinity
729+
, pncRpcConfig = mempty
712730
}
713731

714732
lastOption :: Parser a -> Parser (Last a)
@@ -844,6 +862,9 @@ makeNodeConfiguration pnc = do
844862
experimentalProtocols <-
845863
lastToEither "Missing ExperimentalProtocolsEnabled" $
846864
pncExperimentalProtocolsEnabled pnc
865+
866+
ncRpcConfig <- makeRpcConfig $ (pncRpcConfig pnc){nodeSocketPath=ncSocketPath socketConfig}
867+
847868
return $ NodeConfiguration
848869
{ ncConfigFile = configFile
849870
, ncTopologyFile = topologyFile
@@ -898,6 +919,7 @@ makeNodeConfiguration pnc = do
898919
, ncConsensusMode
899920
, ncGenesisConfig
900921
, ncResponderCoreAffinityPolicy
922+
, ncRpcConfig
901923
}
902924

903925
ncProtocol :: NodeConfiguration -> Protocol

cardano-node/src/Cardano/Node/Parsers.hs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import Cardano.Node.Configuration.Socket
2020
import Cardano.Node.Handlers.Shutdown
2121
import Cardano.Node.Types
2222
import Cardano.Prelude (ConvertText (..))
23+
import Cardano.Rpc.Server.Config (PartialRpcConfig, RpcConfigF (..))
2324
import Ouroboros.Consensus.Ledger.SupportsMempool
2425
import Ouroboros.Consensus.Node
2526

@@ -49,7 +50,7 @@ nodeRunParser = do
4950
topFp <- lastOption parseTopologyFile
5051
dbFp <- lastOption parseNodeDatabasePaths
5152
validate <- lastOption parseValidateDB
52-
socketFp <- lastOption $ parseSocketPath "Path to a cardano-node socket"
53+
socketFp <- lastOption $ parseSocketPath "socket-path" "Path to a cardano-node socket"
5354
traceForwardSocket <- lastOption parseTracerSocketMode
5455
nodeConfigFp <- lastOption parseConfigFile
5556

@@ -74,6 +75,9 @@ nodeRunParser = do
7475
-- Hidden options (to be removed eventually)
7576
maybeMempoolCapacityOverride <- lastOption parseMempoolCapacityOverride
7677

78+
-- gRPC
79+
pncRpcConfig <- parseRpcConfig
80+
7781
pure $ PartialNodeConfiguration
7882
{ pncSocketConfig =
7983
Last . Just $ SocketConfig
@@ -132,12 +136,15 @@ nodeRunParser = do
132136
, pncPeerSharing = mempty
133137
, pncGenesisConfigFlags = mempty
134138
, pncResponderCoreAffinityPolicy = mempty
139+
, pncRpcConfig
135140
}
136141

137-
parseSocketPath :: Text -> Parser SocketPath
138-
parseSocketPath helpMessage =
142+
parseSocketPath :: Text -- ^ option name
143+
-> Text -- ^ help text
144+
-> Parser SocketPath
145+
parseSocketPath optionName helpMessage =
139146
fmap File $ strOption $ mconcat
140-
[ long "socket-path"
147+
[ long (toS optionName)
141148
, help (toS helpMessage)
142149
, completer (bashCompleter "file")
143150
, metavar "FILEPATH"
@@ -363,6 +370,24 @@ parseStartAsNonProducingNode =
363370
]
364371
]
365372

373+
parseRpcConfig :: Parser PartialRpcConfig
374+
parseRpcConfig = do
375+
isEnabled <- lastOption parseRpcToggle
376+
socketPath <- lastOption parseRpcSocketPath
377+
pure $ RpcConfig isEnabled socketPath mempty
378+
where
379+
parseRpcToggle :: Parser Bool
380+
parseRpcToggle =
381+
switch (
382+
long "grpc-enable"
383+
<> help "[EXPERIMENTAL] Enable node gRPC endpoint."
384+
)
385+
parseRpcSocketPath :: Parser SocketPath
386+
parseRpcSocketPath =
387+
parseSocketPath
388+
"gprc-socket-path"
389+
"[EXPERIMENTAL] gRPC socket path. Defaults to rpc.sock in the same directory as node socket."
390+
366391
-- | Produce just the brief help header for a given CLI option parser,
367392
-- without the options.
368393
parserHelpHeader :: String -> Opt.Parser a -> OptI.Doc

0 commit comments

Comments
 (0)