@@ -23,6 +23,7 @@ module Cardano.Node.Run
23
23
) where
24
24
25
25
import Cardano.Api (File (.. ), FileDirection (.. ))
26
+ import Cardano.Api.Internal.Error (displayError )
26
27
import qualified Cardano.Api as Api
27
28
import System.Random (randomIO )
28
29
@@ -58,7 +59,7 @@ import Cardano.Node.Tracing.StateRep (NodeState (NodeKernelOnline))
58
59
import Cardano.Node.Tracing.Tracers.NodeVersion (getNodeVersion )
59
60
import Cardano.Node.Tracing.Tracers.Startup (getStartupInfo )
60
61
import Cardano.Node.Types
61
- import Cardano.Prelude (FatalError (.. ), bool , (:~:) (.. ))
62
+ import Cardano.Prelude (FatalError (.. ), bool , (:~:) (.. ), stderr , )
62
63
import Cardano.Tracing.Config (TraceOptions (.. ), TraceSelection (.. ))
63
64
import Cardano.Tracing.Tracers
64
65
@@ -123,7 +124,7 @@ import Ouroboros.Network.Subscription (DnsSubscriptionTarget (..),
123
124
124
125
import Control.Concurrent (killThread , mkWeakThreadId , myThreadId , getNumCapabilities )
125
126
import Control.Concurrent.Class.MonadSTM.Strict
126
- import Control.Exception (try , IOException )
127
+ import Control.Exception (try , Exception , IOException )
127
128
import qualified Control.Exception as Exception
128
129
import Control.Monad (forM , forM_ , unless , void , when )
129
130
import Control.Monad.Class.MonadThrow (MonadThrow (.. ))
@@ -153,6 +154,7 @@ import Network.HostName (getHostName)
153
154
import Network.Socket (Socket )
154
155
import System.Directory (canonicalizePath , createDirectoryIfMissing , makeAbsolute )
155
156
import System.Environment (lookupEnv )
157
+ import System.IO (hPutStrLn )
156
158
#ifdef UNIX
157
159
import GHC.Weak (deRefWeak )
158
160
import System.Posix.Files
@@ -185,34 +187,24 @@ runNode cmdPc = do
185
187
186
188
putStrLn $ " Node configuration: " <> show nc
187
189
188
- case shelleyVRFFile $ ncProtocolFiles nc of
189
- Just vrfFp -> do vrf <- runExceptT $ checkVRFFilePermissions (File vrfFp)
190
- case vrf of
191
- Left err -> Exception. throwIO err
192
- Right () ->
193
- pure ()
194
- Nothing -> pure ()
195
-
196
- eitherSomeProtocol <- runExceptT $ mkConsensusProtocol
197
- (ncProtocolConfig nc)
198
- -- TODO: Convert ncProtocolFiles to Maybe as relay nodes
199
- -- don't need these.
200
- (Just $ ncProtocolFiles nc)
201
-
202
- p :: SomeConsensusProtocol <-
203
- case eitherSomeProtocol of
204
- Left err -> Exception. throwIO err
205
- Right p -> pure p
206
-
207
- let networkMagic :: Api. NetworkMagic =
208
- case p of
209
- SomeConsensusProtocol _ runP ->
210
- let ProtocolInfo { pInfoConfig } = fst $ Api. protocolInfo @ IO runP
211
- in getNetworkMagic $ Consensus. configBlock pInfoConfig
212
-
213
- case p of
214
- SomeConsensusProtocol blockType runP ->
215
- handleNodeWithTracers cmdPc nc p networkMagic blockType runP
190
+ case ncProtocolFiles nc of
191
+ ProtocolFilepaths {shelleyVRFFile= Just vrfFp} ->
192
+ runThrowExceptT $
193
+ checkVRFFilePermissions stdoutTracer (File vrfFp)
194
+ _ -> pure ()
195
+
196
+ consensusProtocol <-
197
+ runThrowExceptT $
198
+ mkConsensusProtocol
199
+ (ncProtocolConfig nc)
200
+ -- TODO: Convert ncProtocolFiles to Maybe as relay nodes
201
+ -- don't need these.
202
+ (Just $ ncProtocolFiles nc)
203
+
204
+ handleNodeWithTracers cmdPc nc consensusProtocol
205
+
206
+ runThrowExceptT :: Exception e => ExceptT e IO a -> IO a
207
+ runThrowExceptT act = runExceptT act >>= either Exception. throwIO pure
216
208
217
209
-- | Workaround to ensure that the main thread throws an async exception on
218
210
-- receiving a SIGTERM signal.
@@ -233,17 +225,13 @@ installSigTermHandler = do
233
225
return ()
234
226
235
227
handleNodeWithTracers
236
- :: ( TraceConstraints blk
237
- , Api. Protocol IO blk
238
- )
239
- => PartialNodeConfiguration
228
+ :: PartialNodeConfiguration
240
229
-> NodeConfiguration
241
230
-> SomeConsensusProtocol
242
- -> Api. NetworkMagic
243
- -> Api. BlockType blk
244
- -> Api. ProtocolInfoArgs blk
245
231
-> IO ()
246
- handleNodeWithTracers cmdPc nc0 p networkMagic blockType runP = do
232
+ handleNodeWithTracers cmdPc nc0 p@ (SomeConsensusProtocol blockType runP) = do
233
+ let ProtocolInfo {pInfoConfig} = fst $ Api. protocolInfo @ IO runP
234
+ networkMagic :: Api. NetworkMagic = getNetworkMagic $ Consensus. configBlock pInfoConfig
247
235
-- This IORef contains node kernel structure which holds node kernel.
248
236
-- Used for ledger queries and peer connection status.
249
237
nodeKernelData <- mkNodeKernelData
@@ -913,17 +901,17 @@ canonDbPath NodeConfiguration{ncDatabaseFile = nodeDatabaseFps} =
913
901
914
902
-- | Make sure the VRF private key file is readable only
915
903
-- by the current process owner the node is running under.
916
- checkVRFFilePermissions :: File content direction -> ExceptT VRFPrivateKeyFilePermissionError IO ()
904
+ checkVRFFilePermissions :: Tracer IO String -> File content direction -> ExceptT VRFPrivateKeyFilePermissionError IO ()
917
905
#ifdef UNIX
918
- checkVRFFilePermissions (File vrfPrivKey) = do
906
+ checkVRFFilePermissions tracer (File vrfPrivKey) = do
919
907
fs <- liftIO $ getFileStatus vrfPrivKey
920
908
let fm = fileMode fs
921
909
-- Check the the VRF private key file does not give read/write/exec permissions to others.
922
- when (hasOtherPermissions fm)
923
- ( left $ OtherPermissionsExist vrfPrivKey)
910
+ when (hasOtherPermissions fm) $
911
+ left $ OtherPermissionsExist vrfPrivKey
924
912
-- Check the the VRF private key file does not give read/write/exec permissions to any group.
925
- when (hasGroupPermissions fm)
926
- (left $ GroupPermissionsExist vrfPrivKey)
913
+ when (hasGroupPermissions fm) $
914
+ liftIO $ traceWith tracer $ ( " WARNING: " <> ) . displayError $ GroupPermissionsExist vrfPrivKey
927
915
where
928
916
hasPermission :: FileMode -> FileMode -> Bool
929
917
hasPermission fModeA fModeB = fModeA `intersectFileModes` fModeB /= nullFileMode
@@ -934,7 +922,7 @@ checkVRFFilePermissions (File vrfPrivKey) = do
934
922
hasGroupPermissions :: FileMode -> Bool
935
923
hasGroupPermissions fm' = fm' `hasPermission` groupModes
936
924
#else
937
- checkVRFFilePermissions (File vrfPrivKey) = do
925
+ checkVRFFilePermissions _ (File vrfPrivKey) = do
938
926
attribs <- liftIO $ getFileAttributes vrfPrivKey
939
927
-- https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea
940
928
-- https://docs.microsoft.com/en-us/windows/win32/fileio/file-access-rights-constants
0 commit comments