This repository has been archived by the owner on Aug 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 629
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CO-390] Create a 'demo' executable for cardano-sl-wallet-new
This code makes use of the 'Cardano.Wallet.Demo' module and show how it can be used to spawn a demo cluster of nodes. More details in the README.md
- Loading branch information
Showing
3 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{-| Demo cluster of wallet nodes. See demo/README.md -} | ||
|
||
{-# LANGUAGE LambdaCase #-} | ||
|
||
module Main where | ||
|
||
import Universum | ||
|
||
import Control.Concurrent.Async (waitAny) | ||
import System.IO (BufferMode (..), hSetBuffering, stdout) | ||
|
||
import Cardano.Wallet.Demo (MaxWaitingTime (..), NodeName (..), | ||
NodeType (..), RunningNode (..), startCluster, | ||
waitForNode) | ||
|
||
|
||
-- | Cluster configuration can be tweaked via ENV vars. Each ENV var is prefixed | ||
-- with the following. | ||
-- | ||
-- (e.g. `DEMO_NO_CLIENT_AUTH=True`) | ||
prefix :: String | ||
prefix = "DEMO_" | ||
|
||
|
||
main :: IO () | ||
main = void $ do | ||
hSetBuffering stdout NoBuffering -- Instead of LineBuffering | ||
|
||
putTextLn "Cluster is starting..." | ||
cluster <- startCluster prefix | ||
[ ("core0", NodeCore) | ||
, ("core1", NodeCore) | ||
, ("core2", NodeCore) | ||
, ("core3", NodeCore) | ||
, ("relay", NodeRelay) | ||
, ("wallet", NodeEdge) | ||
] | ||
handles <- forM cluster $ \case | ||
RunningCoreNode (NodeName nodeId) handle -> do | ||
putTextLn $ "..." <> nodeId <> " skipped!" | ||
return handle | ||
|
||
RunningRelayNode (NodeName nodeId) handle -> do | ||
putTextLn $ "..." <> nodeId <> " skipped!" | ||
return handle | ||
|
||
RunningWalletNode (NodeName nodeId) client handle -> do | ||
putText "..." >> waitForNode client (MaxWaitingTime 10) | ||
putTextLn $ nodeId <> " OK!" | ||
return handle | ||
putTextLn "Cluster is ready!" | ||
|
||
waitAny handles |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Demo | ||
|
||
## Getting Started | ||
|
||
This module provides an executable for starting a demo cluster of wallet nodes. | ||
It is designed to remove all the overhead of setting up a configuration | ||
and an environment and to _just work_, out-of-the-box. Minor configuration | ||
adjustments are however possible via environment variables. | ||
|
||
``` | ||
stack test cardano-sl-wallet-new:demo | ||
``` | ||
|
||
This spawns three wallet-nodes running respectively on: | ||
|
||
| NodeId | Address | API Address | API Doc Address | | ||
| --- | --- | --- | --- | | ||
| node0 | localhost:3000 | localhost:8090 | localhost:8190 | | ||
| node1 | localhost:3001 | localhost:8091 | localhost:8191 | | ||
| node2 | localhost:3002 | localhost:8092 | localhost:8192 | | ||
|
||
|
||
## Configuring Nodes | ||
|
||
Almost _anything_ from the normal CLI arguments of a node or a wallet node can be | ||
configured via an ENV variable using an `UPPER_SNAKE_CASE` naming, correctly | ||
prefixed with `DEMO_` with a few gotchas: | ||
|
||
- Flags need an explicit boolean value | ||
|
||
- There's no ENV vars mapping to (i.e. you can't configure): | ||
- `--topology` | ||
- `--tlscert` | ||
- `--tlsca` | ||
- `--tlskey` | ||
- `--logger-config` | ||
- `--node-id` | ||
- `--db-path` | ||
- `--wallet-db-path` | ||
|
||
- There's an extra `LOG_SEVERITY` variable that can be set to `Debug`, `Info` | ||
and so forth to ajust logging severity for _all_ nodes. | ||
|
||
- When it make senses, variable values are automatically incremented by the | ||
node index. For instance, if you provide `LISTEN=127.0.0.1:3000`, then | ||
- node0 will receive "127.0.0.1:3000" | ||
- node1 will receive "127.0.0.1:3001" | ||
- node2 will receive "127.0.0.1:3002" | ||
|
||
This is the case for: | ||
- `--listen` | ||
- `--wallet-address` | ||
- `--wallet-doc-address` | ||
|
||
For instance, one can disable TLS client authentication doing: | ||
|
||
``` | ||
DEMO_NO_CLIENT_AUTH=True stack test cardano-sl-wallet-new:demo | ||
``` | ||
|
||
|
||
### Relative FilePath | ||
|
||
One can provide relative filepath as values for ENV vars. They are computed from | ||
the `wallet-new` folder, so for instance, providing `./state-demo` will point | ||
to the directory `$(git rev-parse --show-toplevel)/wallet-new/state-demo`. | ||
|
||
|
||
### State Directory | ||
|
||
By default, each node receives a temporary state directory from the system; | ||
probably somewhere in `/tmp`. This location can always be overriden by | ||
providing an extra `DEMO_STATE_DIR` variable with a custom location. | ||
|
||
Note that, each default has been choosen in such way that they won't conflict | ||
if all nodes were to share the same state directory :) |