Skip to content

Commit

Permalink
Merge pull request #1252 from input-output-hk/smoke-test-with-mithril
Browse files Browse the repository at this point in the history
Smoke test with mithril
  • Loading branch information
ch1bo committed Jan 17, 2024
2 parents 7a19916 + 40d948c commit 2a68a74
Show file tree
Hide file tree
Showing 13 changed files with 303 additions and 30 deletions.
20 changes: 17 additions & 3 deletions .github/workflows/smoke-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ on:
description: "TxId of already published scripts (leave empty to publish)"
required: false

use-mithril:
description: "Bootstrap cardano-node using mithril (removes existing db/)"
required: false
type: boolean

jobs:
smoke-test:
name: "Smoke test on ${{inputs.network}}"
Expand All @@ -34,7 +39,12 @@ jobs:
extra_nix_config: |
accept-flake-config = true
- name: 🚬 Cleanup hydra-node state
- name: 🧹 Delete cardano-node db (when using mithril)
if: ${{ inputs.use-mithril }}
run: |
rm -rf ${state_dir}/db
- name: 🧹 Cleanup hydra-node state
run: |
rm -rf ${state_dir}/state-*
Expand All @@ -47,10 +57,14 @@ jobs:
- name: 🚬 Run hydra-cluster smoke test
run: |
if [ -n "${{inputs.hydra-scripts-tx-id}}" ]; then
nix develop .#exes --command bash -c "hydra-cluster --${{inputs.network}} --hydra-scripts-tx-id ${{inputs.hydra-scripts-tx-id}} --state-directory ${state_dir}"
HYDRA_SCRIPTS_ARG="--hydra-scripts-tx-id ${{inputs.hydra-scripts-tx-id}}"
else
nix develop .#exes --command bash -c "hydra-cluster --${{inputs.network}} --publish-hydra-scripts --state-directory ${state_dir}"
HYDRA_SCRIPTS_ARG="--publish-hydra-scripts"
fi
if ${{inputs.use-mithril}}; then
USE_MITHRIL_ARG="--use-mithril"
fi
nix develop .#exes --command bash -c "hydra-cluster --${{inputs.network}} --state-directory ${state_dir} ${HYDRA_SCRIPTS_ARG} ${USE_MITHRIL_ARG}"
- name: 💾 Upload logs
if: always()
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ changes.

- Adapt cardano client and the chain-sync client to survive after the fork to Conway era.

- The `hydra-cluster` binary can bootstrap `cardano-node`s running on public
networks using `mithril-client`.

## [0.14.0] - 2023-12-04

- **BREAKING** Multiple changes to the Hydra Head protocol on-chain:
Expand Down
117 changes: 117 additions & 0 deletions flake.lock

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

9 changes: 4 additions & 5 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
flake = false;
};
cardano-node.url = "github:input-output-hk/cardano-node/8.7.2";
mithril.url = "github:input-output-hk/mithril/2347.0";
};

outputs =
Expand All @@ -31,7 +32,7 @@
inherit system nixpkgs;
};
hydraPackages = import ./nix/hydra/packages.nix {
inherit hydraProject system pkgs cardano-node;
inherit hydraProject system pkgs inputs;
gitRev = self.rev or "dirty";
};
hydraImages = import ./nix/hydra/docker.nix {
Expand All @@ -52,12 +53,10 @@
};

devShells = (import ./nix/hydra/shell.nix {
inherit (inputs) cardano-node;
inherit hydraProject system;
inherit inputs hydraProject system;
}) // {
ci = (import ./nix/hydra/shell.nix {
inherit (inputs) cardano-node;
inherit hydraProject system;
inherit inputs hydraProject system;
withoutDevTools = true;
}).default;
};
Expand Down
9 changes: 6 additions & 3 deletions hydra-cluster/exe/hydra-cluster/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import Hydra.Prelude
import CardanoNode (waitForFullySynchronized, withCardanoNodeDevnet, withCardanoNodeOnKnownNetwork)
import Hydra.Cluster.Faucet (publishHydraScriptsAs)
import Hydra.Cluster.Fixture (Actor (Faucet))
import Hydra.Cluster.Options (Options (..), PublishOrReuse (Publish, Reuse), parseOptions)
import Hydra.Cluster.Mithril (downloadLatestSnapshotTo)
import Hydra.Cluster.Options (Options (..), PublishOrReuse (Publish, Reuse), UseMithril (UseMithril), parseOptions)
import Hydra.Cluster.Scenarios (EndToEndLog (..), singlePartyHeadFullLifeCycle, singlePartyOpenAHead)
import Hydra.Logging (Verbosity (Verbose), traceWith, withTracer)
import HydraNode (HydraClient (..))
Expand All @@ -22,7 +23,9 @@ run options =
let fromCardanoNode = contramap FromCardanoNode tracer
withStateDirectory $ \workDir ->
case knownNetwork of
Just network ->
Just network -> do
when (useMithril == UseMithril) $
downloadLatestSnapshotTo (contramap FromMithril tracer) network workDir
withCardanoNodeOnKnownNetwork fromCardanoNode workDir network $ \node -> do
waitForFullySynchronized fromCardanoNode node
publishOrReuseHydraScripts tracer node
Expand All @@ -33,7 +36,7 @@ run options =
singlePartyOpenAHead tracer workDir node txId $ \HydraClient{} -> do
forever (threadDelay 60) -- do nothing
where
Options{knownNetwork, stateDirectory, publishHydraScripts} = options
Options{knownNetwork, stateDirectory, publishHydraScripts, useMithril} = options

withStateDirectory action = case stateDirectory of
Nothing -> withTempDir ("hydra-cluster-" <> show knownNetwork) action
Expand Down
3 changes: 3 additions & 0 deletions hydra-cluster/hydra-cluster.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ library
CardanoNode
Hydra.Cluster.Faucet
Hydra.Cluster.Fixture
Hydra.Cluster.Mithril
Hydra.Cluster.Options
Hydra.Cluster.Scenarios
Hydra.Cluster.Util
Expand Down Expand Up @@ -104,6 +105,7 @@ library
, temporary
, text
, time
, typed-process
, unix
, websockets

Expand Down Expand Up @@ -154,6 +156,7 @@ test-suite tests
Test.GeneratorSpec
Test.Hydra.Cluster.CardanoCliSpec
Test.Hydra.Cluster.FaucetSpec
Test.Hydra.Cluster.MithrilSpec
Test.LogFilterSpec
Test.OfflineChainSpec

Expand Down
3 changes: 2 additions & 1 deletion hydra-cluster/src/Hydra/Cluster/Fixture.hs
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,5 @@ data KnownNetwork
= Preview
| Preproduction
| Mainnet
deriving stock (Show)
deriving stock (Generic, Show, Eq, Enum, Bounded)
deriving anyclass (ToJSON, FromJSON)
58 changes: 58 additions & 0 deletions hydra-cluster/src/Hydra/Cluster/Mithril.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
-- | Mithril client to bootstrap cardano nodes in the hydra-cluster.
module Hydra.Cluster.Mithril where

import Hydra.Prelude

import Control.Tracer (Tracer, traceWith)
import Data.Aeson (Value)
import Data.Aeson qualified as Aeson
import Data.ByteString qualified as BS
import Hydra.Cluster.Fixture (KnownNetwork (..))
import Network.HTTP.Simple (getResponseBody, httpBS, parseRequest)
import System.IO.Error (isEOFError)
import System.Process.Typed (createPipe, getStdout, proc, setStdout, withProcessWait_)

data MithrilLog
= StartSnapshotDownload {network :: KnownNetwork, directory :: FilePath}
| -- | Output captured directly from mithril-client
StdOut {output :: Value}
deriving stock (Eq, Show, Generic)
deriving anyclass (ToJSON, FromJSON)

-- | Downloads and unpacks latest snapshot for given network in db/ of given
-- directory.
downloadLatestSnapshotTo :: Tracer IO MithrilLog -> KnownNetwork -> FilePath -> IO ()
downloadLatestSnapshotTo tracer network directory = do
traceWith tracer StartSnapshotDownload{network, directory}
genesisKey <- parseRequest (genesisKeyURLForNetwork network) >>= httpBS <&> getResponseBody
let cmd =
setStdout createPipe $
proc "mithril-client" $
concat
[ ["--aggregator-endpoint", aggregatorEndpointForNetwork network]
, ["snapshot", "download", "latest"]
, ["--genesis-verification-key", decodeUtf8 genesisKey]
, ["--download-dir", directory]
, ["--json"]
]
withProcessWait_ cmd traceStdout
where
traceStdout p =
ignoreEOFErrors . forever $ do
bytes <- BS.hGetLine (getStdout p)
case Aeson.eitherDecodeStrict bytes of
Left err -> error $ "failed to decode: \n" <> show bytes <> "\nerror: " <> show err
Right output -> traceWith tracer StdOut{output}

ignoreEOFErrors =
handleJust (guard . isEOFError) (const $ pure ())

genesisKeyURLForNetwork = \case
Mainnet -> "https://raw.githubusercontent.com/input-output-hk/mithril/main/mithril-infra/configuration/release-mainnet/genesis.vkey"
Preproduction -> "https://raw.githubusercontent.com/input-output-hk/mithril/main/mithril-infra/configuration/release-preprod/genesis.vkey"
Preview -> "https://raw.githubusercontent.com/input-output-hk/mithril/main/mithril-infra/configuration/pre-release-preview/genesis.vkey"

aggregatorEndpointForNetwork = \case
Mainnet -> "https://aggregator.release-mainnet.api.mithril.network/aggregator"
Preproduction -> "https://aggregator.release-preprod.api.mithril.network/aggregator"
Preview -> "https://aggregator.pre-release-preview.api.mithril.network/aggregator"
Loading

0 comments on commit 2a68a74

Please sign in to comment.