Skip to content

Commit eab2ed1

Browse files
Jimbo4350carbolymer
authored andcommitted
Add gRPC to cardano-node
1 parent f11e0f3 commit eab2ed1

File tree

23 files changed

+571
-53
lines changed

23 files changed

+571
-53
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 (..)
@@ -35,6 +37,8 @@ import Cardano.Node.Configuration.Socket (SocketConfig (..))
3537
import Cardano.Node.Handlers.Shutdown
3638
import Cardano.Node.Protocol.Types (Protocol (..))
3739
import Cardano.Node.Types
40+
import Cardano.Rpc.Server.Config (PartialRpcConfig, RpcConfig, RpcConfigF (..),
41+
makeRpcConfig)
3842
import Cardano.Tracing.Config
3943
import Cardano.Tracing.OrphanInstances.Network ()
4044
import qualified Ouroboros.Cardano.Network.Diffusion.Configuration as Cardano
@@ -202,6 +206,9 @@ data NodeConfiguration
202206
, ncGenesisConfig :: GenesisConfig
203207

204208
, ncResponderCoreAffinityPolicy :: ResponderCoreAffinityPolicy
209+
210+
-- gRPC
211+
, ncRpcConfig :: RpcConfig
205212
} deriving (Eq, Show)
206213

207214
-- | 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
@@ -418,6 +428,12 @@ instance FromJSON PartialNodeConfiguration where
418428
<$> v .:? "ResponderCoreAffinityPolicy"
419429
<*> v .:? "ForkPolicy" -- deprecated
420430

431+
pncRpcConfig <-
432+
RpcConfig
433+
<$> (Last <$> v .:? "EnableRpc")
434+
<*> (Last <$> v .:? "RpcSocketPath")
435+
<*> pure mempty
436+
421437
pure PartialNodeConfiguration {
422438
pncProtocolConfig
423439
, pncSocketConfig = Last . Just $ SocketConfig mempty mempty mempty pncSocketPath
@@ -463,6 +479,7 @@ instance FromJSON PartialNodeConfiguration where
463479
, pncPeerSharing
464480
, pncGenesisConfigFlags
465481
, pncResponderCoreAffinityPolicy
482+
, pncRpcConfig
466483
}
467484
where
468485
parseMempoolCapacityBytesOverride v = parseNoOverride <|> parseOverride
@@ -710,6 +727,7 @@ defaultPartialNodeConfiguration =
710727
, pncGenesisConfigFlags = Last (Just defaultGenesisConfigFlags)
711728
-- https://ouroboros-consensus.cardano.intersectmbo.org/haddocks/ouroboros-consensus-diffusion/Ouroboros-Consensus-Node-Genesis.html#v:defaultGenesisConfigFlags
712729
, pncResponderCoreAffinityPolicy = Last $ Just NoResponderCoreAffinity
730+
, pncRpcConfig = mempty
713731
}
714732

715733
lastOption :: Parser a -> Parser (Last a)
@@ -850,6 +868,9 @@ makeNodeConfiguration pnc = do
850868
experimentalProtocols <-
851869
lastToEither "Missing ExperimentalProtocolsEnabled" $
852870
pncExperimentalProtocolsEnabled pnc
871+
872+
ncRpcConfig <- makeRpcConfig $ (pncRpcConfig pnc){nodeSocketPath=ncSocketPath socketConfig}
873+
853874
return $ NodeConfiguration
854875
{ ncConfigFile = configFile
855876
, 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: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,26 @@ module Cardano.Node.Parsers
1515

1616
import Cardano.Logging.Types
1717
import qualified Cardano.Logging.Types as Net
18-
import Cardano.Node.Configuration.NodeAddress (
19-
NodeHostIPv4Address (NodeHostIPv4Address), File (..),
18+
import Cardano.Node.Configuration.NodeAddress (File (..),
19+
NodeHostIPv4Address (NodeHostIPv4Address),
2020
NodeHostIPv6Address (NodeHostIPv6Address), PortNumber, SocketPath)
2121
import Cardano.Node.Configuration.POM (PartialNodeConfiguration (..), lastOption)
2222
import Cardano.Node.Configuration.Socket
2323
import Cardano.Node.Handlers.Shutdown
2424
import Cardano.Node.Types
2525
import Cardano.Prelude (ConvertText (..))
26+
import Cardano.Rpc.Server.Config (PartialRpcConfig, RpcConfigF (..))
2627
import Ouroboros.Consensus.Ledger.SupportsMempool
2728
import Ouroboros.Consensus.Node
2829

29-
import Data.Foldable
3030
import Data.Char (isDigit)
31+
import Data.Foldable
3132
import Data.Maybe (fromMaybe)
3233
import Data.Monoid (Last (..))
3334
import Data.Text (Text)
3435
import qualified Data.Text as Text
3536
import Data.Word (Word16, Word32)
3637
import Options.Applicative hiding (str, switch)
37-
-- Don't use switch. It will not allow to set an option in a configuration
38-
-- file. See `parseStartAsNonProducingNode` and `parseValidateDB`.
3938
import qualified Options.Applicative as Opt
4039
import qualified Options.Applicative.Help as OptI
4140
import System.Posix.Types (Fd (..))
@@ -56,7 +55,7 @@ nodeRunParser = do
5655
topFp <- lastOption parseTopologyFile
5756
dbFp <- lastOption parseNodeDatabasePaths
5857
validate <- lastOption parseValidateDB
59-
socketFp <- lastOption $ parseSocketPath "Path to a cardano-node socket"
58+
socketFp <- lastOption $ parseSocketPath "socket-path" "Path to a cardano-node socket"
6059
traceForwardSocket <- lastOption parseTracerSocketMode
6160
nodeConfigFp <- lastOption parseConfigFile
6261

@@ -83,6 +82,9 @@ nodeRunParser = do
8382
-- Hidden options (to be removed eventually)
8483
maybeMempoolCapacityOverride <- lastOption parseMempoolCapacityOverride
8584

85+
-- gRPC
86+
pncRpcConfig <- parseRpcConfig
87+
8688
pure $ PartialNodeConfiguration
8789
{ pncSocketConfig =
8890
Last . Just $ SocketConfig
@@ -141,12 +143,15 @@ nodeRunParser = do
141143
, pncPeerSharing = mempty
142144
, pncGenesisConfigFlags = mempty
143145
, pncResponderCoreAffinityPolicy = mempty
146+
, pncRpcConfig
144147
}
145148

146-
parseSocketPath :: Text -> Parser SocketPath
147-
parseSocketPath helpMessage =
149+
parseSocketPath :: Text -- ^ option name
150+
-> Text -- ^ help text
151+
-> Parser SocketPath
152+
parseSocketPath optionName helpMessage =
148153
fmap File $ strOption $ mconcat
149-
[ long "socket-path"
154+
[ long (toS optionName)
150155
, help (toS helpMessage)
151156
, completer (bashCompleter "file")
152157
, metavar "FILEPATH"
@@ -420,6 +425,23 @@ parseStartAsNonProducingNode =
420425
]
421426
]
422427

428+
parseRpcConfig :: Parser PartialRpcConfig
429+
parseRpcConfig = do
430+
isEnabled <- lastOption parseRpcToggle
431+
socketPath <- lastOption parseRpcSocketPath
432+
pure $ RpcConfig isEnabled socketPath mempty
433+
where
434+
parseRpcToggle :: Parser Bool
435+
parseRpcToggle =
436+
Opt.switch (
437+
long "grpc-enable"
438+
<> help "[EXPERIMENTAL] Enable node gRPC endpoint."
439+
)
440+
parseRpcSocketPath :: Parser SocketPath
441+
parseRpcSocketPath =
442+
parseSocketPath
443+
"gprc-socket-path"
444+
"[EXPERIMENTAL] gRPC socket path. Defaults to rpc.sock in the same directory as node socket."
423445

424446
-- | Produce just the brief help header for a given CLI option parser,
425447
-- without the options.

0 commit comments

Comments
 (0)