Skip to content

Commit 9e77279

Browse files
committed
move out rpc cabal package out of cardano-node
1 parent 814c8cd commit 9e77279

File tree

27 files changed

+247
-143
lines changed

27 files changed

+247
-143
lines changed

.github/workflows/haskell.yml

Lines changed: 1 addition & 1 deletion
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}' }

cabal.project

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ packages:
2020
cardano-node
2121
cardano-node-capi
2222
cardano-node-chairman
23+
cardano-rpc
2324
cardano-submit-api
2425
cardano-testnet
2526
cardano-tracer

cardano-node/cardano-node.cabal

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,8 @@ maintainer: [email protected]
1212
license: Apache-2.0
1313
license-files: LICENSE
1414
NOTICE
15-
build-type: Custom
15+
build-type: Simple
1616
extra-doc-files: ChangeLog.md
17-
extra-source-files: proto/**/*.proto
18-
19-
custom-setup
20-
setup-depends:
21-
base
22-
, Cabal
23-
, proto-lens-setup
2417

2518
Flag unexpected_thunks
2619
Description: Turn on unexpected thunks checks
@@ -74,8 +67,6 @@ library
7467

7568
hs-source-dirs: src
7669

77-
build-tool-depends: proto-lens-protoc:proto-lens-protoc
78-
7970
exposed-modules: Cardano.Node.Configuration.Logging
8071
Cardano.Node.Configuration.NodeAddress
8172
Cardano.Node.Configuration.POM
@@ -97,15 +88,6 @@ library
9788
Cardano.Node.Protocol.Shelley
9889
Cardano.Node.Protocol.Types
9990
Cardano.Node.Queries
100-
Cardano.Node.Rpc.Client
101-
Cardano.Node.Rpc.Proto.Api.Node
102-
Cardano.Node.Rpc.Proto.Api.UtxoRpc.Query
103-
Cardano.Node.Rpc.Server
104-
Cardano.Node.Rpc.Server.Config
105-
Cardano.Node.Rpc.Server.Internal.Env
106-
Cardano.Node.Rpc.Server.Internal.Error
107-
Cardano.Node.Rpc.Server.Internal.Monad
108-
Cardano.Node.Rpc.Server.Internal.UtxoRpc.Query
10991
Cardano.Node.Run
11092
Cardano.Node.Startup
11193
Cardano.Node.STM
@@ -158,24 +140,9 @@ library
158140
Cardano.Tracing.Shutdown
159141
Cardano.Tracing.Startup
160142
Cardano.Tracing.Tracers
161-
Proto.Cardano.Node.Rpc.Node
162-
Proto.Utxorpc.V1alpha.Bitcoin.Bitcoin
163-
Proto.Utxorpc.V1alpha.Cardano.Cardano
164-
Proto.Utxorpc.V1alpha.Query.Query
165-
Proto.Utxorpc.V1alpha.Submit.Submit
166-
Proto.Utxorpc.V1alpha.Sync.Sync
167-
Proto.Utxorpc.V1alpha.Watch.Watch
168143

169144
other-modules: Paths_cardano_node
170145
autogen-modules: Paths_cardano_node
171-
Proto.Cardano.Node.Rpc.Node
172-
Proto.Utxorpc.V1alpha.Bitcoin.Bitcoin
173-
Proto.Utxorpc.V1alpha.Cardano.Cardano
174-
Proto.Utxorpc.V1alpha.Query.Query
175-
Proto.Utxorpc.V1alpha.Submit.Submit
176-
Proto.Utxorpc.V1alpha.Sync.Sync
177-
Proto.Utxorpc.V1alpha.Watch.Watch
178-
179146

180147
build-depends: base
181148
, aeson >= 2.1.0.0
@@ -198,6 +165,7 @@ library
198165
, cardano-prelude
199166
, cardano-protocol-tpraos >= 1.4
200167
, cardano-slotting >= 0.2
168+
, cardano-rpc ^>= 10.0
201169
, cborg ^>= 0.2.4
202170
, containers
203171
, contra-tracer
@@ -209,8 +177,6 @@ library
209177
, ekg-core
210178
, filepath
211179
, formatting
212-
, grapesy
213-
, grpc-spec
214180
, generic-data
215181
, hashable
216182
, hostname
@@ -237,13 +203,9 @@ library
237203
, ouroboros-network-protocols ^>= 0.14
238204
, prettyprinter
239205
, prettyprinter-ansi-terminal
240-
, proto-lens-protobuf-types
241-
, proto-lens-runtime
242-
, proto-lens
243206
, psqueues
244207
, random
245208
, resource-registry
246-
, rio
247209
, safe-exceptions
248210
, scientific
249211
, si-timers

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ data PartialNodeConfiguration
294294
, pncGenesisConfigFlags :: !(Last GenesisConfigFlags)
295295

296296
, pncResponderCoreAffinityPolicy :: !(Last ResponderCoreAffinityPolicy)
297+
297298
} deriving (Eq, Generic, Show)
298299

299300
instance AdjustFilePaths PartialNodeConfiguration where

cardano-node/src/Cardano/Node/Rpc/Server/Config.hs

Lines changed: 0 additions & 4 deletions
This file was deleted.

cardano-node/src/Cardano/Node/Rpc/Server/Internal/Env.hs

Lines changed: 0 additions & 11 deletions
This file was deleted.

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

Lines changed: 57 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module Cardano.Node.Run
2222
, checkVRFFilePermissions
2323
) where
2424

25-
import Cardano.Api (File (..), FileDirection (..))
25+
import Cardano.Api (File (..), FileDirection (..), NetworkMagic, fromNetworkMagic)
2626
import Cardano.Api.Internal.Error (displayError)
2727
import qualified Cardano.Api as Api
2828
import System.Random (randomIO)
@@ -40,7 +40,7 @@ import Cardano.Node.Configuration.POM (NodeConfiguration (..),
4040
PartialNodeConfiguration (..), SomeNetworkP2PMode (..), TimeoutOverride (..),
4141
defaultPartialNodeConfiguration, makeNodeConfiguration, parseNodeConfigurationFP, getForkPolicy)
4242
import Cardano.Node.Configuration.Socket (SocketOrSocketInfo' (..),
43-
gatherConfiguredSockets, getSocketOrSocketInfoAddr)
43+
gatherConfiguredSockets, getSocketOrSocketInfoAddr, SocketConfig (..))
4444
import qualified Cardano.Node.Configuration.Topology as TopologyNonP2P
4545
import Cardano.Node.Configuration.TopologyP2P
4646
import qualified Cardano.Node.Configuration.TopologyP2P as TopologyP2P
@@ -52,7 +52,8 @@ import Cardano.Node.Protocol.Shelley (PraosLeaderCredentialsError (..)
5252
ShelleyProtocolInstantiationError (PraosLeaderCredentialsError))
5353
import Cardano.Node.Protocol.Types
5454
import Cardano.Node.Queries
55-
import Cardano.Node.Rpc.Server
55+
import Cardano.Rpc.Server
56+
import Cardano.Rpc.Server.Config
5657
import Cardano.Node.Startup
5758
import Cardano.Node.TraceConstraints (TraceConstraints)
5859
import Cardano.Node.Tracing.API
@@ -156,6 +157,7 @@ import Network.HostName (getHostName)
156157
import Network.Socket (Socket)
157158
import System.Directory (canonicalizePath, createDirectoryIfMissing, makeAbsolute)
158159
import System.Environment (lookupEnv)
160+
import System.FilePath (takeDirectory, (</>))
159161
import System.IO (hPutStrLn)
160162
#ifdef UNIX
161163
import GHC.Weak (deRefWeak)
@@ -177,45 +179,72 @@ runNode
177179
:: PartialNodeConfiguration
178180
-> IO ()
179181
runNode cmdPc = do
180-
installSigTermHandler
182+
installSigTermHandler
181183

182-
Crypto.cryptoInit
184+
Crypto.cryptoInit
183185

184-
configYamlPc <- parseNodeConfigurationFP . getLast $ pncConfigFile cmdPc
186+
let earlyTracer = stdoutTracer
187+
nc@NodeConfiguration
188+
{ ncProtocolConfig
189+
, ncProtocolFiles=ncProtocolFiles@ProtocolFilepaths{shelleyVRFFile=mShelleyVrfFile}
190+
} <- buildNodeConfiguration earlyTracer cmdPc
185191

186-
nc <- case makeNodeConfiguration $ defaultPartialNodeConfiguration <> configYamlPc <> cmdPc of
187-
Left err -> error $ "Error in creating the NodeConfiguration: " <> err
188-
Right nc' -> return nc'
192+
forM_ mShelleyVrfFile $
193+
runThrowExceptT . checkVRFFilePermissions earlyTracer . File
189194

190-
putStrLn $ "Node configuration: " <> show nc
195+
consensusProtocol@(SomeConsensusProtocol _ runP) <-
196+
runThrowExceptT $
197+
mkConsensusProtocol
198+
ncProtocolConfig
199+
-- TODO: Convert ncProtocolFiles to Maybe as relay nodes
200+
-- don't need these.
201+
(Just ncProtocolFiles)
191202

192-
case ncProtocolFiles nc of
193-
ProtocolFilepaths{shelleyVRFFile=Just vrfFp} ->
194-
runThrowExceptT $
195-
checkVRFFilePermissions stdoutTracer (File vrfFp)
196-
_ -> pure ()
197-
198-
consensusProtocol@(SomeConsensusProtocol _ runP) <-
199-
runThrowExceptT $
200-
mkConsensusProtocol
201-
(ncProtocolConfig nc)
202-
-- TODO: Convert ncProtocolFiles to Maybe as relay nodes
203-
-- don't need these.
204-
(Just $ ncProtocolFiles nc)
203+
let ProtocolInfo{pInfoConfig} = fst $ Api.protocolInfo @IO runP
204+
networkMagic :: Api.NetworkMagic = getNetworkMagic $ Consensus.configBlock pInfoConfig
205+
withAsync (runRpcServer $ buildRpcConfiguration earlyTracer networkMagic cmdPc) $ \_ ->
206+
handleNodeWithTracers cmdPc nc consensusProtocol
205207

206-
let ProtocolInfo{pInfoConfig} = fst $ Api.protocolInfo @IO runP
207-
networkMagic :: Api.NetworkMagic = getNetworkMagic $ Consensus.configBlock pInfoConfig
208-
race_
209-
(handleNodeWithTracers cmdPc nc consensusProtocol)
210-
(runRpcServer cmdPc networkMagic)
211208

212209
runThrowExceptT :: Exception e => ExceptT e IO a -> IO a
213210
runThrowExceptT act = runExceptT act >>= either Exception.throwIO pure
214211

212+
-- | Read node configuration from a file specified in 'PartialNodeConfiguration'
213+
buildNodeConfiguration :: Tracer IO String
214+
-> PartialNodeConfiguration -- ^ defaults
215+
-> IO NodeConfiguration
216+
buildNodeConfiguration tracer partialConf = do
217+
configYamlPc <- parseNodeConfigurationFP . getLast $ pncConfigFile partialConf
218+
nc <- case makeNodeConfiguration $ defaultPartialNodeConfiguration <> configYamlPc <> partialConf of
219+
Left err -> error $ "Error in creating the NodeConfiguration: " <> err
220+
Right nc' -> return nc'
221+
222+
traceWith tracer $ "Node configuration: " <> show nc
223+
pure nc
224+
225+
-- | Build RPC configuration. Reads the configuration file again. Allows RPC server to dynamically reload configuration from disk again.
226+
buildRpcConfiguration :: Tracer IO String
227+
-> NetworkMagic
228+
-> PartialNodeConfiguration
229+
-> IO RpcConfig
230+
buildRpcConfiguration tracer networkMagic partialConf = do
231+
nc <- buildNodeConfiguration tracer partialConf
232+
SocketConfig{ncSocketPath = Last mN2cSocket} <- pure $ ncSocketConfig nc
233+
let nodeSocketPath = fromMaybe "rpc.sock" mN2cSocket
234+
socketDir = takeDirectory $ unFile nodeSocketPath
235+
pure $
236+
RpcConfig
237+
{ isEnabled = True -- TODO take from PNC
238+
, rpcSocketPath = File $ socketDir </> "rpc.sock" -- TODO take from PNC
239+
, nodeSocketPath
240+
, networkMagic
241+
}
242+
215243
-- | Workaround to ensure that the main thread throws an async exception on
216244
-- receiving a SIGTERM signal.
217245
installSigTermHandler :: IO ()
218246
installSigTermHandler = do
247+
-- TODO add SigHUP handler for RPC configuration reloading
219248
#ifdef UNIX
220249
-- Similar implementation to the RTS's handling of SIGINT (see GHC's
221250
-- https://gitlab.haskell.org/ghc/ghc/-/blob/master/libraries/base/GHC/TopHandler.hs).
File renamed without changes.

cardano-rpc/cardano-rpc.cabal

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
cabal-version: 3.8
2+
3+
name: cardano-rpc
4+
version: 10.0.0
5+
synopsis: The cardano RPC interface
6+
description: The cardano RPC interface
7+
category: Cardano,
8+
Validator,
9+
copyright: 2019-2023 Input Output Global Inc (IOG), 2023-2025 Intersect.
10+
author: IOHK
11+
maintainer: [email protected]
12+
license: Apache-2.0
13+
license-files: LICENSE
14+
NOTICE
15+
build-type: Custom
16+
extra-doc-files: ChangeLog.md
17+
extra-source-files: proto/**/*.proto
18+
19+
custom-setup
20+
setup-depends:
21+
base
22+
, Cabal
23+
, proto-lens-setup
24+
25+
common project-config
26+
default-language: Haskell2010
27+
28+
default-extensions: OverloadedStrings
29+
build-depends: base >= 4.14 && < 5
30+
31+
ghc-options: -Wall
32+
-Wcompat
33+
-Wincomplete-record-updates
34+
-Wincomplete-uni-patterns
35+
-Wno-unticked-promoted-constructors
36+
-Wpartial-fields
37+
-Wredundant-constraints
38+
-Wunused-packages
39+
40+
library
41+
import: project-config
42+
43+
hs-source-dirs: src
44+
45+
build-tool-depends: proto-lens-protoc:proto-lens-protoc
46+
47+
exposed-modules:
48+
Cardano.Rpc.Client
49+
Cardano.Rpc.Proto.Api.Node
50+
Cardano.Rpc.Proto.Api.UtxoRpc.Query
51+
Cardano.Rpc.Server
52+
Cardano.Rpc.Server.Config
53+
Cardano.Rpc.Server.Internal.Env
54+
Cardano.Rpc.Server.Internal.Error
55+
Cardano.Rpc.Server.Internal.Monad
56+
Cardano.Rpc.Server.Internal.UtxoRpc.Query
57+
Proto.Cardano.Rpc.Node
58+
Proto.Cardano.Rpc.Node_Fields
59+
Proto.Utxorpc.V1alpha.Cardano.Cardano
60+
Proto.Utxorpc.V1alpha.Cardano.Cardano_Fields
61+
Proto.Utxorpc.V1alpha.Query.Query
62+
Proto.Utxorpc.V1alpha.Query.Query_Fields
63+
Proto.Utxorpc.V1alpha.Submit.Submit
64+
Proto.Utxorpc.V1alpha.Submit.Submit_Fields
65+
Proto.Utxorpc.V1alpha.Sync.Sync
66+
Proto.Utxorpc.V1alpha.Sync.Sync_Fields
67+
Proto.Utxorpc.V1alpha.Watch.Watch
68+
Proto.Utxorpc.V1alpha.Watch.Watch_Fields
69+
70+
other-modules: Paths_cardano_rpc
71+
autogen-modules: Paths_cardano_rpc
72+
Proto.Cardano.Rpc.Node
73+
Proto.Cardano.Rpc.Node_Fields
74+
Proto.Utxorpc.V1alpha.Cardano.Cardano
75+
Proto.Utxorpc.V1alpha.Cardano.Cardano_Fields
76+
Proto.Utxorpc.V1alpha.Query.Query
77+
Proto.Utxorpc.V1alpha.Query.Query_Fields
78+
Proto.Utxorpc.V1alpha.Submit.Submit
79+
Proto.Utxorpc.V1alpha.Submit.Submit_Fields
80+
Proto.Utxorpc.V1alpha.Sync.Sync
81+
Proto.Utxorpc.V1alpha.Sync.Sync_Fields
82+
Proto.Utxorpc.V1alpha.Watch.Watch
83+
Proto.Utxorpc.V1alpha.Watch.Watch_Fields
84+
85+
86+
build-depends: base
87+
, bytestring
88+
, cardano-api ^>= 10.16
89+
, cardano-ledger-api
90+
, cardano-ledger-binary
91+
, cardano-ledger-conway
92+
, cardano-ledger-core
93+
, containers
94+
, grapesy
95+
, grpc-spec
96+
, microlens
97+
, ouroboros-network-protocols ^>= 0.14
98+
, proto-lens-protobuf-types
99+
, proto-lens-runtime
100+
, proto-lens
101+
, rio
102+

cardano-node/src/Cardano/Node/Rpc/Client.hs renamed to cardano-rpc/src/Cardano/Rpc/Client.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{-# LANGUAGE DataKinds #-}
22
{-# LANGUAGE TypeApplications #-}
33

4-
module Cardano.Node.Rpc.Client
4+
module Cardano.Rpc.Client
55
( module Network.GRPC.Client
66
, module Network.GRPC.Client.StreamType.IO
77
, module Network.GRPC.Common.Protobuf

0 commit comments

Comments
 (0)