Skip to content

Commit

Permalink
Merge pull request #1367 from input-output-hk/fix-tutorial
Browse files Browse the repository at this point in the history
Fix tutorial download instructions
  • Loading branch information
ch1bo authored Mar 20, 2024
2 parents 09800bd + b3ed1bc commit 66f560c
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check-tutorial.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
import re
with open("docs/docs/tutorial/index.md", "r") as tutorial:
body = tutorial.read()
usedCardanoNodeVersions = re.findall(r"cardano-node-.*-([0-9]+\.[0-9]+\.[0-9]+).zip", body)
usedCardanoNodeVersions = re.findall(r"cardano-node-([0-9]+\.[0-9]+\.[0-9]+)-.*\.tar\.gz", body)
with open("hydra-cluster/test/Test/CardanoNodeSpec.hs", "r") as cardanoNodeSpecFile:
body = cardanoNodeSpecFile.read()
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ changes.

## [0.16.0] - UNRELEASED

- Update to and tested against `cardano-node 8.9.0` and `cardano-cli 8.20.3.0`.
- Tested with `cardano-node 8.9.0`, `cardano-cli 8.20.3.0` and `mithril 2408.0`.

- **BREAKING** Hydra scripts changed due to updates in the `plutus` toolchain:
- Overall slight increase in script size.
Expand Down
13 changes: 6 additions & 7 deletions docs/docs/tutorial/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ version=0.15.0
curl -L -O https://github.com/input-output-hk/hydra/releases/download/${version}/hydra-x86_64-linux-${version}.zip
unzip -d bin hydra-x86_64-linux-${version}.zip
curl -L -o - https://github.com/input-output-hk/cardano-node/releases/download/8.9.0/cardano-node-8.9.0-linux.tar.gz \
| tar xz -C bin ./cardano-node ./cardano-cli
curl -L -o - https://github.com/input-output-hk/mithril/releases/download/2347.0/mithril-2347.0-linux-x64.tar.gz \
| tar xz ./bin/cardano-node ./bin/cardano-cli
curl -L -o - https://github.com/input-output-hk/mithril/releases/download/2408.0/mithril-2408.0-linux-x64.tar.gz \
| tar xz -C bin mithril-client
chmod +x bin/*
```
Expand All @@ -59,10 +59,10 @@ mkdir -p bin
version=0.15.0
curl -L -O https://github.com/input-output-hk/hydra/releases/download/${version}/hydra-aarch64-darwin-${version}.zip
unzip -d bin hydra-aarch64-darwin-${version}.zip
curl -L -o - https://github.com/input-output-hk/hydra/releases/download/${version}/cardano-node-aarch-darwin-8.9.0.zip
unzip -d bin cardano-node-8.9.0-linux.zip
curl -L -o - https://github.com/input-output-hk/cardano-node/releases/download/8.9.0/cardano-node-8.9.0-macos.tar.gz \
| tar xz -C bin --wildcards ./cardano-node ./cardano-cli '*.dylib'
| tar xz --wildcards ./bin/cardano-node ./bin/cardano-cli './bin/*.dylib'
curl -L -o - https://github.com/input-output-hk/mithril/releases/download/2408.0/mithril-2408.0-macos-x64.tar.gz \
| tar xz -C bin
chmod +x bin/*
```

Expand Down Expand Up @@ -122,8 +122,7 @@ We will be using the `mithril-client` configured to download from
`preprod` network to download the latest blockchain snapshot:

```shell
SNAPSHOT_DIGEST=$(mithril-client snapshot list --json | jq -r '.[0].digest')
mithril-client snapshot download $SNAPSHOT_DIGEST
mithril-client snapshot download latest
```

<details>
Expand Down
38 changes: 19 additions & 19 deletions flake.lock

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

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
flake = false;
};
cardano-node.url = "github:intersectmbo/cardano-node/8.9.0";
mithril.url = "github:input-output-hk/mithril/2347.0";
mithril.url = "github:input-output-hk/mithril/2408.0";
nix-npm-buildpackage.url = "github:serokell/nix-npm-buildpackage";
};

Expand Down
16 changes: 8 additions & 8 deletions hydra-cluster/src/Hydra/Cluster/Mithril.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ 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_)
import System.Process.Typed (createPipe, getStderr, proc, setStderr, withProcessWait_)

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

Expand All @@ -28,7 +28,7 @@ downloadLatestSnapshotTo tracer network directory = do
traceWith tracer StartSnapshotDownload{network, directory}
genesisKey <- parseRequest genesisKeyURL >>= httpBS <&> getResponseBody
let cmd =
setStdout createPipe $
setStderr createPipe $
proc "mithril-client" $
concat
[ ["--aggregator-endpoint", aggregatorEndpoint]
Expand All @@ -37,15 +37,15 @@ downloadLatestSnapshotTo tracer network directory = do
, ["--download-dir", directory]
, ["--json"]
]
withProcessWait_ cmd traceStdout
withProcessWait_ cmd traceStderr
_ -> error $ "Network " <> show network <> " not supported by mithril."
where
traceStdout p =
traceStderr p =
ignoreEOFErrors . forever $ do
bytes <- BS.hGetLine (getStdout p)
bytes <- BS.hGetLine (getStderr p)
case Aeson.eitherDecodeStrict bytes of
Left err -> error $ "failed to decode: \n" <> show bytes <> "\nerror: " <> show err
Right output -> traceWith tracer StdOut{output}
Right output -> traceWith tracer StdErr{output}

ignoreEOFErrors =
handleJust (guard . isEOFError) (const $ pure ())
Expand Down
22 changes: 11 additions & 11 deletions hydra-cluster/test/Test/Hydra/Cluster/MithrilSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import Hydra.Prelude
import Test.Hydra.Prelude

import Control.Concurrent.Class.MonadSTM (newTVarIO, readTVarIO)
import Control.Lens ((^?!))
import Data.Aeson.Lens (key, _Number)
import Control.Lens ((^?))
import Data.Aeson.Lens (key)
import Hydra.Cluster.Mithril (MithrilLog (..), downloadLatestSnapshotTo)
import Hydra.Logging (Envelope (..), Tracer, traceInTVar)
import System.Directory (doesDirectoryExist)
Expand All @@ -22,19 +22,19 @@ spec = parallel $ do
doesDirectoryExist dbPath `shouldReturn` False
race_
(downloadLatestSnapshotTo tracer network tmpDir)
(waitForStep 3 getTraces)
(waitForDownload getTraces)

-- | Wait for the 'StdOut' message that matches the given step number.
waitForStep :: HasCallStack => Natural -> IO [Envelope MithrilLog] -> IO ()
waitForStep step getTraces = do
-- | Wait for the 'StdErr' message to indicate it starts downloading.
waitForDownload :: HasCallStack => IO [Envelope MithrilLog] -> IO ()
waitForDownload getTraces = do
traces <- getTraces
unless (any isRightStep traces) $ do
unless (any isRightTrace traces) $ do
threadDelay 1
waitForStep step getTraces
waitForDownload getTraces
where
isRightStep = \case
Envelope{message = StdOut{output}} ->
output ^?! key "step_num" . _Number == fromIntegral step
isRightTrace = \case
Envelope{message = StdErr{output}} ->
isJust $ output ^? key "bytes_downloaded"
_ -> False

-- | Create a tracer that captures all messages and a function to retrieve all
Expand Down

0 comments on commit 66f560c

Please sign in to comment.