@@ -4,13 +4,12 @@ module CardanoNode where
4
4
5
5
import Hydra.Prelude
6
6
7
- import Cardano.Ledger.Core ( PParams )
7
+ import CardanoClient ( NodeLog ( .. ), RunningNode ( .. ), waitForFullySynchronized )
8
8
import Control.Lens ((?~) , (^?!) )
9
9
import Control.Tracer (Tracer , traceWith )
10
10
import Data.Aeson (Value (String ), (.=) )
11
11
import Data.Aeson qualified as Aeson
12
12
import Data.Aeson.Lens (atKey , key , _Number )
13
- import Data.Fixed (Centi )
14
13
import Data.Text qualified as Text
15
14
import Data.Time.Clock.POSIX (posixSecondsToUTCTime , utcTimeToPOSIXSeconds )
16
15
import Hydra.Cardano.Api (AsType (AsPaymentKey ), File (.. ), NetworkId , PaymentKey , SigningKey , SocketPath , VerificationKey , generateSigningKey , getVerificationKey )
@@ -40,12 +39,6 @@ type Port = Int
40
39
newtype NodeId = NodeId Int
41
40
deriving newtype (Eq , Show , Num , ToJSON , FromJSON )
42
41
43
- data RunningNode = RunningNode
44
- { nodeSocket :: SocketPath
45
- , networkId :: NetworkId
46
- , pparams :: PParams Api. LedgerEra
47
- }
48
-
49
42
-- | Configuration parameters for a single node devnet
50
43
data DevnetConfig = DevnetConfig
51
44
{ stateDirectory :: FilePath
@@ -121,7 +114,7 @@ withCardanoNodeDevnet ::
121
114
IO a
122
115
withCardanoNodeDevnet tracer stateDirectory action = do
123
116
args <- setupCardanoDevnet stateDirectory
124
- withCardanoNode tracer stateDirectory args $ \ nodeSocket -> do
117
+ withCardanoNode tracer stateDirectory args networkId $ \ nodeSocket -> do
125
118
traceWith tracer MsgNodeIsReady
126
119
pparams <- queryProtocolParameters networkId nodeSocket QueryTip
127
120
let rn =
@@ -147,7 +140,7 @@ withCardanoNodeOnKnownNetwork ::
147
140
withCardanoNodeOnKnownNetwork tracer workDir knownNetwork action = do
148
141
copyKnownNetworkFiles
149
142
networkId <- readNetworkId
150
- withCardanoNode tracer workDir args $ \ nodeSocket -> do
143
+ withCardanoNode tracer workDir args networkId $ \ nodeSocket -> do
151
144
traceWith tracer MsgNodeIsReady
152
145
pparams <- queryProtocolParameters networkId nodeSocket QueryTip
153
146
let rn =
@@ -279,9 +272,10 @@ withCardanoNode ::
279
272
Tracer IO NodeLog ->
280
273
FilePath ->
281
274
CardanoNodeArgs ->
275
+ NetworkId ->
282
276
(SocketPath -> IO a ) ->
283
277
IO a
284
- withCardanoNode tr stateDirectory args@ CardanoNodeArgs {nodeSocket} action = do
278
+ withCardanoNode tr stateDirectory args@ CardanoNodeArgs {nodeSocket} networkId action = do
285
279
traceWith tr $ MsgNodeCmdSpec (show $ cmdspec process)
286
280
traceWith tr $ MsgNodeStarting {stateDirectory}
287
281
withLogFile logFilePath $ \ out -> do
@@ -306,6 +300,10 @@ withCardanoNode tr stateDirectory args@CardanoNodeArgs{nodeSocket} action = do
306
300
waitForNode = do
307
301
let nodeSocketPath = File socketPath
308
302
waitForSocket nodeSocketPath
303
+ -- we wait for synchronization since otherwise we will receive a query
304
+ -- exception when trying to obtain pparams and the era is not the one we
305
+ -- expect.
306
+ _ <- waitForFullySynchronized tr networkId nodeSocketPath
309
307
traceWith tr $ MsgSocketIsReady $ unFile nodeSocketPath
310
308
action nodeSocketPath
311
309
@@ -416,21 +414,6 @@ data ProcessHasExited = ProcessHasExited Text ExitCode
416
414
417
415
instance Exception ProcessHasExited
418
416
419
- -- Logging
420
-
421
- data NodeLog
422
- = MsgNodeCmdSpec Text
423
- | MsgCLI [Text ]
424
- | MsgCLIStatus Text Text
425
- | MsgCLIRetry Text
426
- | MsgCLIRetryResult Text Int
427
- | MsgNodeStarting { stateDirectory :: FilePath }
428
- | MsgSocketIsReady FilePath
429
- | MsgSynchronizing { percentDone :: Centi }
430
- | MsgNodeIsReady
431
- deriving stock (Eq , Show , Generic )
432
- deriving anyclass (ToJSON , FromJSON )
433
-
434
417
--
435
418
-- Helpers
436
419
--
0 commit comments