Skip to content

Commit 997dceb

Browse files
Jimbo4350carbolymer
authored andcommitted
Add gRPC to cardano-node
1 parent 8db5cb3 commit 997dceb

File tree

22 files changed

+572
-43
lines changed

22 files changed

+572
-43
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import qualified PlutusTx.AssocMap as AssocMap (empty)
3636
import Cardano.TxGenerator.ProtocolParameters (ProtocolParameters(..))
3737
import Cardano.TxGenerator.Types (TxGenError (..), TxGenPlutusResolvedTo (..))
3838
import Control.Exception (SomeException (..), try, displayException)
39+
import RIO (runRIO)
3940
import System.FilePath ((<.>), (</>))
4041
#ifdef WITH_LIBRARY
4142
import Cardano.Benchmarking.PlutusScripts (findPlutusScript)

bench/tx-generator/tx-generator.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ library
140140
, network
141141
, network-mux
142142
, optparse-applicative-fork
143+
, rio
143144
, ouroboros-consensus >= 0.6
144145
, ouroboros-consensus-cardano >= 0.5
145146
, 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
@@ -220,6 +221,7 @@ library
220221
, typed-protocols:{typed-protocols, stateful} >= 1.0
221222
, yaml
222223

224+
223225
executable cardano-node
224226
import: project-config
225227
hs-source-dirs: app
@@ -255,6 +257,7 @@ test-suite cardano-node-test
255257
, cardano-crypto-class
256258
, cardano-crypto-wrapper
257259
, cardano-api
260+
, cardano-rpc
258261
, cardano-protocol-tpraos
259262
, cardano-node
260263
, cardano-slotting

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

Lines changed: 23 additions & 0 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 (..)
@@ -34,6 +36,8 @@ import Cardano.Node.Configuration.Socket (SocketConfig (..))
3436
import Cardano.Node.Handlers.Shutdown
3537
import Cardano.Node.Protocol.Types (Protocol (..))
3638
import Cardano.Node.Types
39+
import Cardano.Rpc.Server.Config (PartialRpcConfig, RpcConfig, RpcConfigF (..),
40+
makeRpcConfig)
3741
import Cardano.Tracing.Config
3842
import Cardano.Tracing.OrphanInstances.Network ()
3943
import Ouroboros.Consensus.Ledger.SupportsMempool
@@ -174,6 +178,9 @@ data NodeConfiguration
174178
, ncGenesisConfig :: GenesisConfig
175179

176180
, ncResponderCoreAffinityPolicy :: ResponderCoreAffinityPolicy
181+
182+
-- gRPC
183+
, ncRpcConfig :: RpcConfig
177184
} deriving (Eq, Show)
178185

179186
-- | We expose the `Ouroboros.Network.Mux.ForkPolicy` as a `NodeConfiguration` field.
@@ -255,6 +262,7 @@ data PartialNodeConfiguration
255262
, pncSyncTargetOfKnownBigLedgerPeers :: !(Last Int)
256263
, pncSyncTargetOfEstablishedBigLedgerPeers :: !(Last Int)
257264
, pncSyncTargetOfActiveBigLedgerPeers :: !(Last Int)
265+
258266
-- Minimum number of active big ledger peers we must be connected to
259267
-- in Genesis mode
260268
, pncMinBigLedgerPeersForTrustedState :: !(Last NumberOfBigLedgerPeers)
@@ -269,6 +277,9 @@ data PartialNodeConfiguration
269277
, pncGenesisConfigFlags :: !(Last GenesisConfigFlags)
270278

271279
, pncResponderCoreAffinityPolicy :: !(Last ResponderCoreAffinityPolicy)
280+
281+
-- gRPC
282+
, pncRpcConfig :: !PartialRpcConfig
272283
} deriving (Eq, Generic, Show)
273284

274285
instance AdjustFilePaths PartialNodeConfiguration where
@@ -381,6 +392,12 @@ instance FromJSON PartialNodeConfiguration where
381392
<$> v .:? "ResponderCoreAffinityPolicy"
382393
<*> v .:? "ForkPolicy" -- deprecated
383394

395+
pncRpcConfig <-
396+
RpcConfig
397+
<$> (Last <$> v .:? "EnableRpc")
398+
<*> (Last <$> v .:? "RpcSocketPath")
399+
<*> pure mempty
400+
384401
pure PartialNodeConfiguration {
385402
pncProtocolConfig
386403
, pncSocketConfig = Last . Just $ SocketConfig mempty mempty mempty pncSocketPath
@@ -425,6 +442,7 @@ instance FromJSON PartialNodeConfiguration where
425442
, pncPeerSharing
426443
, pncGenesisConfigFlags
427444
, pncResponderCoreAffinityPolicy
445+
, pncRpcConfig
428446
}
429447
where
430448
parseMempoolCapacityBytesOverride v = parseNoOverride <|> parseOverride
@@ -687,6 +705,7 @@ defaultPartialNodeConfiguration =
687705
, pncGenesisConfigFlags = Last (Just defaultGenesisConfigFlags)
688706
-- https://ouroboros-consensus.cardano.intersectmbo.org/haddocks/ouroboros-consensus-diffusion/Ouroboros-Consensus-Node-Genesis.html#v:defaultGenesisConfigFlags
689707
, pncResponderCoreAffinityPolicy = Last $ Just NoResponderCoreAffinity
708+
, pncRpcConfig = mempty
690709
}
691710

692711
lastOption :: Parser a -> Parser (Last a)
@@ -827,6 +846,9 @@ makeNodeConfiguration pnc = do
827846
experimentalProtocols <-
828847
lastToEither "Missing ExperimentalProtocolsEnabled" $
829848
pncExperimentalProtocolsEnabled pnc
849+
850+
ncRpcConfig <- makeRpcConfig $ (pncRpcConfig pnc){nodeSocketPath=ncSocketPath socketConfig}
851+
830852
return $ NodeConfiguration
831853
{ ncConfigFile = configFile
832854
, ncTopologyFile = topologyFile
@@ -872,6 +894,7 @@ makeNodeConfiguration pnc = do
872894
, ncConsensusMode
873895
, ncGenesisConfig
874896
, ncResponderCoreAffinityPolicy
897+
, ncRpcConfig
875898
}
876899

877900
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
@@ -140,12 +142,15 @@ nodeRunParser = do
140142
, pncPeerSharing = mempty
141143
, pncGenesisConfigFlags = mempty
142144
, pncResponderCoreAffinityPolicy = mempty
145+
, pncRpcConfig
143146
}
144147

145-
parseSocketPath :: Text -> Parser SocketPath
146-
parseSocketPath helpMessage =
148+
parseSocketPath :: Text -- ^ option name
149+
-> Text -- ^ help text
150+
-> Parser SocketPath
151+
parseSocketPath optionName helpMessage =
147152
fmap File $ strOption $ mconcat
148-
[ long "socket-path"
153+
[ long (toS optionName)
149154
, help (toS helpMessage)
150155
, completer (bashCompleter "file")
151156
, metavar "FILEPATH"
@@ -419,6 +424,23 @@ parseStartAsNonProducingNode =
419424
]
420425
]
421426

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

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

0 commit comments

Comments
 (0)