Skip to content

Commit

Permalink
Bump cardano-node to v10.1.4; Fix and refactor cardano-testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
errfrom committed Jan 27, 2025
1 parent d7b5de6 commit 270d275
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 229 deletions.
52 changes: 26 additions & 26 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
flake = false;
};

cardano-node.url = "github:input-output-hk/cardano-node/10.1.3";
cardano-node.url = "github:input-output-hk/cardano-node/10.1.4";

# Repository with network parameters
# NOTE(bladyjoker): Cardano configurations (yaml/json) often change format and break, that's why we pin to a specific known version.
cardano-configurations = {
url = "github:input-output-hk/cardano-configurations?rev=3c5f35bda1b8fd29ab310ad222403a9167f512de";
url = "github:input-output-hk/cardano-configurations?rev=a913d87246dc2484562a00c86e5f9c74a20e82ce";
flake = false;
};

Expand Down
4 changes: 2 additions & 2 deletions src/Internal/Testnet/Contract.purs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ import Ctl.Internal.Testnet.Server
import Ctl.Internal.Testnet.Types (TestnetConfig)
import Ctl.Internal.Testnet.Utils
( cleanupOnExit
, read872GenesisKey
, readGenesisKey
, runCleanup
, whenError
)
Expand Down Expand Up @@ -274,7 +274,7 @@ startTestnetContractEnv cfg distr cleanupRef = do
readGenesisWallets =
traverse
( \location -> do
paymentKey <- read872GenesisKey location
paymentKey <- readGenesisKey location
pure $ mkKeyWalletFromPrivateKeys paymentKey Nothing Nothing
)
(unwrap cluster).paths.genesisKeys
Expand Down
46 changes: 27 additions & 19 deletions src/Internal/Testnet/Server.purs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import Ctl.Internal.Testnet.Types
( TestnetClusterConfig
, TestnetConfig
, TestnetPaths
, TestnetRuntime
)
import Ctl.Internal.Testnet.Utils
( EventSource
Expand Down Expand Up @@ -214,19 +215,10 @@ startTestnetCluster
-> Logger
-> Aff StartedTestnetCluster
startTestnetCluster cfg cleanupRef logger = do
{ testnet, channels, workdirAbsolute } <-
{ testnet, channels, workdirAbsolute, runtime: { paths } } <-
annotateError "Could not start cardano-testnet" $
startCardanoTestnet cfg.clusterConfig cleanupRef logger

{ paths } <- waitUntil (Milliseconds 4000.0)
$ map hush
$ tryAndLogErrors "Waiting for ready state"
$ liftEffect do

paths <- liftEither =<< findTestnetPaths { workdir: workdirAbsolute }
runtime <- getRuntime paths
pure { runtime, paths }

ogmios <- annotateError "Could not start ogmios"
$ startOgmios' { paths, workdir: workdirAbsolute }
kupo <- annotateError "Could not start kupo"
Expand Down Expand Up @@ -324,6 +316,7 @@ startCardanoTestnet
, stdout :: EventSource String
}
, workdirAbsolute :: FilePath
, runtime :: TestnetRuntime
}
startCardanoTestnet params cleanupRef logger =
annotateError "startCardanoTestnet" do
Expand Down Expand Up @@ -363,7 +356,13 @@ startCardanoTestnet params cleanupRef logger =

channels <- liftEffect $ getChannels testnet
attachStdoutMonitors testnet
pure { testnet, workdirAbsolute: workspace, channels }
runtime <- getTestnetRuntime workspace
pure
{ testnet
, workdirAbsolute: workspace
, channels
, runtime
}
where
findWorkspaceDir :: forall m. MonadEffect m => FilePath -> m (Maybe FilePath)
findWorkspaceDir workdir =
Expand Down Expand Up @@ -395,6 +394,14 @@ startCardanoTestnet params cleanupRef logger =
logger Trace $ "Cleaning up cardano-testnet workspace: " <> workspace
_rmdirSync workspace

getTestnetRuntime :: FilePath -> Aff TestnetRuntime
getTestnetRuntime workdir =
waitUntil (Milliseconds 4000.0) do
map hush $ tryAndLogErrors (Just logger) "getTestnetRuntime" $
liftEffect do
paths <- findTestnetPaths workdir
getRuntime paths

type StdStreams =
{ stderr :: EventSource String
, stdout :: EventSource String
Expand Down Expand Up @@ -449,14 +456,15 @@ redirectLogging
}
-> Aff (Aff.Fiber (Either Error Unit))
redirectLogging events { handleLine, storeLogs } =
Aff.forkAff $ tryAndLogErrors "redirectLogging" $ flip tailRecM unit \_ -> do
line <- waitForEvent events
liftEffect $ suppressAndLogErrors "redirectLogging: callback error" $ void
do
handleLine line
for storeLogs \{ logFile, toString } ->
Node.FS.appendTextFile UTF8 logFile $ toString line <> "\n"
pure $ Loop unit
Aff.forkAff $ tryAndLogErrors Nothing "redirectLogging" $ flip tailRecM unit
\_ -> do
line <- waitForEvent events
liftEffect $ suppressAndLogErrors "redirectLogging: callback error" $ void
do
handleLine line
for storeLogs \{ logFile, toString } ->
Node.FS.appendTextFile UTF8 logFile $ toString line <> "\n"
pure $ Loop unit

type ClusterConfig r =
( ogmiosConfig :: ServerConfig
Expand Down
74 changes: 17 additions & 57 deletions src/Internal/Testnet/Types.purs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ module Ctl.Internal.Testnet.Types
, Era(Byron, Shelley, Allegra, Mary, Alonzo, Babbage, Conway)
, LoggingFormat(LogAsJson, LogAsText)
, TestnetPaths
, Event(Ready872, Finished, Failed, StartupFailed)
, StartupFailure(SpawnFailed, InitializationFailed)
, NodeLocation
, Node
, GenesisUtxoKeyLocation
Expand Down Expand Up @@ -57,26 +55,6 @@ data Era
| Babbage
| Conway

data StartupFailure
= SpawnFailed
| InitializationFailed

derive instance Eq StartupFailure
derive instance Generic StartupFailure _
instance Show StartupFailure where
show = genericShow

data Event
= Ready872 -- when cardano-testnet 8.7.2 is ready to go
| Finished
| Failed
| StartupFailed StartupFailure

derive instance Eq Event
derive instance Generic Event _
instance Show Event where
show = genericShow

instance Show Era where
show = case _ of
Byron -> "byron-era"
Expand Down Expand Up @@ -127,56 +105,38 @@ defaultOptionalStartupParams =
, nodeLoggingFormat: Nothing
}

type TestnetRuntime =
{ nodes :: Array Node
, paths :: TestnetPaths
}

type TestnetPaths =
{ testnetDirectory :: FilePath
, genesisKeys :: Array { | GenesisUtxoKeyLocation () }
, genesisKeys :: Array GenesisUtxoKeyLocation
, nodeConfigPath :: FilePath
, nodeSocketPath :: FilePath
, nodeDirs :: Array { | NodeLocation () }
, nodeDirs :: Array NodeLocation
}

type Node r =
( socket :: FilePath
type Node =
{ socket :: FilePath
, port :: UInt
| NodeLocation r
)
, location :: NodeLocation
}

type NodeLocation r =
( idx :: Int
, name :: String
type NodeLocation =
{ idx :: Int
, workdir :: FilePath
| r
)
}

type GenesisUtxoKeyLocation r =
( path :: FilePath
type GenesisUtxoKeyLocation =
{ path :: FilePath
, idx :: Int
| r
)

{-
type TestnetClusterConfig r =
( hooks :: Config.Hooks
| KupmiosConfig (LogParams r)
)
-}
}

type LogParams r =
( logLevel :: LogLevel
, customLogger :: Maybe (LogLevel -> Config.Message -> Aff Unit)
, suppressLogs :: Boolean
| r
)

{-
type KupmiosConfig r =
( kupoConfig :: Config.ServerConfig
, ogmiosConfig :: Config.ServerConfig
| r
)
-}

type TestnetRuntime r =
( nodes :: Array { | Node () }
| r
)
Loading

0 comments on commit 270d275

Please sign in to comment.