Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit 8e26a7a

Browse files
authored
Merge pull request #3629 from input-output-hk/KtorZ/CO-390/run-demo-cluster
[CO-390] Run Demo Cluster
2 parents ccca8b3 + 8b76d29 commit 8e26a7a

File tree

21 files changed

+2361
-37
lines changed

21 files changed

+2361
-37
lines changed

cabal.project.freeze

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ constraints: Cabal ==2.0.1.1,
5050
directory ==1.3.1.1,
5151
dlist ==0.8.0.4,
5252
dns ==3.0.4,
53+
docopt ==0.7.0.5,
5354
ekg ==0.4.0.15,
5455
ekg-core ==0.1.1.4,
5556
ekg-statsd ==0.2.3.0,
@@ -129,6 +130,7 @@ constraints: Cabal ==2.0.1.1,
129130
resourcet ==1.2.1,
130131
retry ==0.7.6.2,
131132
rocksdb-haskell-ng ==0.0.0,
133+
safe ==0.3.17,
132134
safe-exceptions ==0.1.7.0,
133135
safecopy ==0.9.4.1,
134136
scientific ==0.3.6.2,

cluster/LICENSE

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2018 IOHK
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of
4+
this software and associated documentation files (the "Software"), to deal in
5+
the Software without restriction, including without limitation the rights to
6+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7+
of the Software, and to permit persons to whom the Software is furnished to
8+
do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

cluster/README.md

+147
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
# Cluster
2+
3+
## Getting Started
4+
5+
This module provides an executable for starting a demo cluster of nodes.
6+
It is designed to remove all the overhead of setting up a configuration
7+
and an environment and to _just work_, out-of-the-box. Minor configuration
8+
adjustments are however possible via environment variables.
9+
10+
```
11+
$> stack exec -- cardano-sl-cluster-demo
12+
Cluster is starting (4 core(s), 1 relay(s), 1 edge(s))...
13+
...core0 has no health-check API.
14+
......system start: 1539179287
15+
......address: 127.0.0.1:3000
16+
......locked assets: -
17+
...core1 has no health-check API.
18+
......system start: 1539179287
19+
......address: 127.0.0.1:3001
20+
......locked assets: -
21+
...core2 has no health-check API.
22+
......system start: 1539179287
23+
......address: 127.0.0.1:3002
24+
......locked assets: -
25+
...core3 has no health-check API.
26+
......system start: 1539179287
27+
......address: 127.0.0.1:3003
28+
......locked assets: -
29+
...relay has no health-check API.
30+
......system start: 1539179287
31+
......address: 127.0.0.1:3100
32+
...wallet OK!
33+
......system start: 1539179287
34+
......api address: 127.0.0.1:8090
35+
......doc address: 127.0.0.1:8190
36+
Cluster is (probably) ready!
37+
```
38+
39+
40+
## Configuring Nodes
41+
42+
_Almost anything_ from the normal CLI arguments of a node or a wallet node can be
43+
configured via an ENV variable using an `UPPER_SNAKE_CASE` naming, correctly
44+
prefixed with `DEMO_` with a few gotchas:
45+
46+
- Flags need an explicit boolean value
47+
48+
- There's no ENV vars mapping to (i.e. you can't configure):
49+
- `--db-path`
50+
- `--logger-config`
51+
- `--node-id`
52+
- `--tlsca`
53+
- `--tlscert`
54+
- `--tlskey`
55+
- `--topology`
56+
- `--wallet-db-path`
57+
- `--keyfile`
58+
Those variables actually corresponds to artifacts or location handled by the
59+
cluster library. Messing up with one of those can break the whole cluster.
60+
61+
- There's an extra `LOG_SEVERITY` variable that can be set to `Debug`, `Info`
62+
and so forth to ajust logging severity for _all_ nodes.
63+
64+
- There's an extra `STATE_DIR` variable used to provide the working directory
65+
for all nodes. See the [State Directory](#state-directory) section here-below.
66+
67+
- There's an extra `SYSTEM_START_OFFSET` which can be used to tweak the system
68+
start offset such that nodes can all correctly boot.
69+
70+
- When it make senses, variable values are automatically incremented by the
71+
node index. For instance, if you provide `LISTEN=127.0.0.1:3000`, then
72+
- core0 will receive "127.0.0.1:3000"
73+
- core1 will receive "127.0.0.1:3001"
74+
- core2 will receive "127.0.0.1:3002"
75+
- etc.
76+
77+
This is the case for:
78+
- `--listen`
79+
- `--wallet-address`
80+
- `--wallet-doc-address`
81+
82+
For instance, one can disable TLS client authentication doing:
83+
84+
```
85+
$> DEMO_NO_CLIENT_AUTH=True stack exec -- cardano-sl-wallet-new:demo
86+
```
87+
88+
### Relative FilePath
89+
90+
One can provide relative filepath as values for ENV vars. They are computed from
91+
the root repository folder, so for instance, providing `./state-demo` will point
92+
to the directory `$(git rev-parse --show-toplevel)/state-demo`.
93+
94+
95+
### State Directory
96+
97+
By default, each node receives a temporary state directory from the system;
98+
probably somewhere in `/tmp`. This location can always be overriden by
99+
providing an extra `DEMO_STATE_DIR` variable with a custom location.
100+
101+
Note that, each default has been choosen in such way that they won't conflict
102+
if all nodes were to share the same state directory :)
103+
104+
### Configuring Cluster
105+
106+
The `cardano-sl-cluster-demo` is actually a full-blown CLI with default arguments.
107+
108+
```
109+
$> stack exec -- cardano-sl-cluster-demo --help
110+
cardano-sl-cluster-demo
111+
112+
Spawn a demo cluster of nodes running cardano-sl, ready-to-use
113+
114+
Usage:
115+
cardano-sl-cluster-demo [--no-genesis-wallets] [options]
116+
cardano-sl-cluster-demo --help
117+
118+
Options:
119+
--cores=INT Number of core nodes to start [default: 4]
120+
--relays=INT Number of relay nodes to start [default: 1]
121+
--edges=INT Number of edge nodes (wallet) to start [default: 1]
122+
```
123+
124+
So, the components of the cluster may be tweaked by providing arguments to the CLI.
125+
For instance, one could switch off the wallet node by doing:
126+
127+
```
128+
$> stack exec -- cardano-sl-cluster-demo --edges 0
129+
```
130+
131+
## Known Issues
132+
133+
The current logging implementation of _cardano-sl_ heavily relies on a global mutable state
134+
stored in a shared `MVar`. Since every node in `cardano-sl-cluster-demo` is spawned from a
135+
common parent thread, they all eventually end up sharing the same logging state.
136+
137+
This result in a non-friendly behavior where, every logging handler get replaced by the one
138+
from the next node started by the cluster. So once started, every log entry gets logged _as-if_
139+
they were logged by the last node started (with default parameters, the wallet node).
140+
141+
This is why you won't find any log (apart from a couple of lines on start-up) inside log files,
142+
and duplicated lines in one of them (likely `wallet.log.pub`); fixing this is non-trivial.
143+
144+
145+
<p align="center">
146+
(✿ ͡◕ ᴗ◕ )つ━━✫ ✧・゚* <i>enjoy</i> *:・゚✧*:・゚❤
147+
</p>

cluster/cardano-sl-cluster.cabal

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
name: cardano-sl-cluster
2+
version: 1.0.0
3+
synopsis: Utilities to generate and run cluster of nodes
4+
description: See README
5+
homepage: https://github.com/input-output-hk/cardano-sl/cluster/README.md
6+
author: IOHK Engineering Team
7+
maintainer: [email protected]
8+
copyright: 2018 IOHK
9+
license: MIT
10+
license-file: LICENSE
11+
category: Data
12+
build-type: Simple
13+
extra-source-files: README.md
14+
cabal-version: >=1.10
15+
16+
library
17+
default-language: Haskell2010
18+
default-extensions: DeriveGeneric
19+
LambdaCase
20+
NoImplicitPrelude
21+
OverloadedStrings
22+
TupleSections
23+
TypeApplications
24+
ScopedTypeVariables
25+
26+
hs-source-dirs: src
27+
28+
build-depends: base >=4.7 && <5
29+
30+
, cardano-sl
31+
, cardano-sl-chain
32+
, cardano-sl-core
33+
, cardano-sl-infra
34+
, cardano-sl-networking
35+
, cardano-sl-util
36+
, cardano-sl-wallet-new
37+
, cardano-sl-x509
38+
39+
, aeson
40+
, async
41+
, attoparsec
42+
, bytestring
43+
, containers
44+
, cryptonite
45+
, directory
46+
, filepath
47+
, formatting
48+
, iproute
49+
, lens
50+
, optparse-applicative
51+
, parsec
52+
, safe
53+
, servant-client
54+
, temporary
55+
, text
56+
, time
57+
, tls
58+
, universum
59+
60+
exposed-modules: Cardano.Cluster
61+
Cardano.Cluster.Environment
62+
Cardano.Cluster.Util
63+
64+
65+
test-suite cardano-sl-cluster-test
66+
default-language: Haskell2010
67+
default-extensions: DeriveGeneric
68+
LambdaCase
69+
NoImplicitPrelude
70+
OverloadedStrings
71+
TupleSections
72+
TypeApplications
73+
ScopedTypeVariables
74+
75+
type: exitcode-stdio-1.0
76+
77+
hs-source-dirs: test
78+
main-is: Main.hs
79+
other-modules: Cardano.Cluster.Util.Arbitrary
80+
Cardano.Cluster.Util.Spec
81+
Cardano.Cluster.Environment.Arbitrary
82+
Cardano.Cluster.Environment.Spec
83+
84+
build-depends: base
85+
86+
, cardano-sl-cluster
87+
, cardano-sl-core
88+
, cardano-sl-infra
89+
90+
, async
91+
, containers
92+
, lens
93+
, QuickCheck
94+
, time
95+
, universum
96+
97+
98+
executable cardano-sl-cluster-demo
99+
ghc-options: -threaded -O2 -rtsopts
100+
default-language: Haskell2010
101+
default-extensions: DeriveGeneric
102+
LambdaCase
103+
NoImplicitPrelude
104+
OverloadedStrings
105+
TupleSections
106+
TypeApplications
107+
ScopedTypeVariables
108+
109+
hs-source-dirs: demo
110+
main-is: Main.hs
111+
112+
build-depends: base
113+
114+
, cardano-sl-cluster
115+
, cardano-sl-wallet-new
116+
117+
, ansi-terminal
118+
, async
119+
, containers
120+
, docopt
121+
, formatting
122+
, universum

0 commit comments

Comments
 (0)