Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blockade integration #83

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,73 @@ in order to create a local test network.
- `wasm` is generated using the `<node> export-genesis-wasm` subcommand.
- `header` is retrieved by calling `api.rpc.chain.getHeader(genesis_hash)`.

## Simulating chaos

By default `polkadot-launch` will spawn the nodes as regular processes on your computer, additionally it also
supports launching the nodes as docker containers and it integrates with [blockade](https://github.com/worstcase/blockade)
to be able to simulate arbitrary network failures.

### Requirements

- docker
- blockade

You'll need to have docker running on your computer and will need to have docker images available for all
the nodes you're going to launch. Docker files for the relaychain nodes and collators are provided in the
`docker/` folder and can be built with `./docker/build-images.sh`.

To install blockade you'll need to have Python 2.7 installed and you should then be able to do:

`pip install blockade`

For nix users the provided `shell.nix` defines all the dependencies required to install blockade locally.

### Usage

Launch the network with `polkadot-launch config.json`. Once the launch process is complete you can use
the blockade tool to generate network failures.

```
> blockade status
NODE CONTAINER ID STATUS IP NETWORK PARTITION
parachain1 0bcd0e676c2e UP 172.17.0.2 NORMAL
parachain2 e425a139093c UP 172.17.0.4 NORMAL
relay1 327e79ecc829 UP 172.17.0.8 NORMAL
relay2 5ecc3364293b UP 172.17.0.7 NORMAL
relay3 bd6ebe188b4a UP 172.17.0.3 NORMAL
relay4 225719ce1933 UP 172.17.0.5 NORMAL
simpleParachain1 af10c596612d UP 172.17.0.6 NORMAL
```

```
> blockade flaky parachain1
```

This command will induce a packet loss of ~30% on the node `parachain1`.

Latency can be simulated with:

```
> blockade slow parachain1
```

And we can also add arbitrary partitions to the network:

```
blockade partition relay1,relay2,relay3,relay4
```

This will create a partition on the network where the relay chain nodes will be
on their own partition and therefore unable to connect to the collators.

To heal the partitions do:

```
> blockade join
```

For reference on how to use blockade check: https://github.com/worstcase/blockade#commands.

## Development

To work on this project, you will need [`yarn`](https://yarnpkg.com/).
Expand Down
5 changes: 5 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"blockade": true,
"relaychain": {
"bin": "./bin/polkadot",
"chain": "rococo-local",
"dockerImage": "polkadot",
"nodes": [
{
"name": "alice",
Expand All @@ -28,6 +30,7 @@
"parachains": [
{
"bin": "./bin/rococo-collator",
"dockerImage": "cumulus",
"id": "200",
"wsPort": 9988,
"port": 31200,
Expand All @@ -36,6 +39,7 @@
},
{
"bin": "./bin/rococo-collator",
"dockerImage": "cumulus",
"id": "300",
"wsPort": 9999,
"port": 31300,
Expand All @@ -46,6 +50,7 @@
"simpleParachains": [
{
"bin": "./bin/adder-collator",
"dockerImage": "adder-collator",
"id": "400",
"port": "31400",
"balance": "1000000000000000000000"
Expand Down
47 changes: 47 additions & 0 deletions docker/adder-collator.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
FROM debian:buster-slim

# install tools and dependencies
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get upgrade -y && \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
clang cmake curl git pkg-config && \
# apt cleanup
apt-get autoremove -y && \
apt-get clean && \
find /var/lib/apt/lists/ -type f -not -name lock -delete; \
# add user and link ~/.local/share/adder-collator to /data
useradd -m -u 1000 -U -s /bin/sh -d /adder-collator adder-collator && \
mkdir -p /data /adder-collator/.local/share && \
chown -R adder-collator:adder-collator /data && \
ln -s /data /adder-collator/.local/share/adder-collator

# install rust toolchain
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y && \
export PATH="$PATH:$HOME/.cargo/bin" && \
rustup toolchain install nightly && \
rustup target add wasm32-unknown-unknown --toolchain nightly && \
rustup default stable

# clone polkadot. the trick of using the github API will make the docker cache
# invalidate when there's a new commit.
ADD https://api.github.com/repos/paritytech/polkadot/git/refs/heads/rococo-v1 version.json
RUN git clone -b rococo-v1 https://github.com/paritytech/polkadot.git /tmp/polkadot

# build polkadot
RUN cd /tmp/polkadot && \
export PATH="$PATH:$HOME/.cargo/bin" && \
cargo build --release -p test-parachain-adder-collator && \
cp /tmp/polkadot/target/release/adder-collator /usr/local/bin

# show backtraces
ENV RUST_BACKTRACE 1

USER adder-collator

# check if executable works in this container
RUN /usr/local/bin/adder-collator --version

EXPOSE 30333 9933 9944
VOLUME ["/adder-collator"]

ENTRYPOINT ["/usr/local/bin/adder-collator"]
10 changes: 10 additions & 0 deletions docker/build-images.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env sh

echo 'Building polkadot docker image'
docker build -f polkadot.Dockerfile . --tag=polkadot

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

following the docs, shouldn't this be ./docker/polkadot.Dockerfile?


echo 'Building cumulus docker image'
docker build -f cumulus.Dockerfile . --tag=cumulus

echo 'Building adder collator docker image'
docker build -f adder-collator.Dockerfile . --tag=adder-collator
47 changes: 47 additions & 0 deletions docker/cumulus.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
FROM debian:buster-slim

# install tools and dependencies
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get upgrade -y && \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
clang cmake curl git pkg-config && \
# apt cleanup
apt-get autoremove -y && \
apt-get clean && \
find /var/lib/apt/lists/ -type f -not -name lock -delete; \
# add user and link ~/.local/share/cumulus to /data
useradd -m -u 1000 -U -s /bin/sh -d /cumulus cumulus && \
mkdir -p /data /cumulus/.local/share && \
chown -R cumulus:cumulus /data && \
ln -s /data /cumulus/.local/share/cumulus

# install rust toolchain
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y && \
export PATH="$PATH:$HOME/.cargo/bin" && \
rustup toolchain install nightly && \
rustup target add wasm32-unknown-unknown --toolchain nightly && \
rustup default stable

# clone cumulus. the trick of using the github API will make the docker cache
# invalidate when there's a new commit.
ADD https://api.github.com/repos/paritytech/cumulus/git/refs/heads/rococo-v1 version.json
RUN git clone -b rococo-v1 https://github.com/paritytech/cumulus.git /tmp/cumulus

# build cumulus
RUN cd /tmp/cumulus && \
export PATH="$PATH:$HOME/.cargo/bin" && \
cargo build --release -p rococo-collator && \
cp /tmp/cumulus/target/release/rococo-collator /usr/local/bin

# show backtraces
ENV RUST_BACKTRACE 1

USER cumulus

# check if executable works in this container
RUN /usr/local/bin/rococo-collator --version

EXPOSE 30333 9933 9944
VOLUME ["/cumulus"]

ENTRYPOINT ["/usr/local/bin/rococo-collator"]
47 changes: 47 additions & 0 deletions docker/polkadot.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
FROM debian:buster-slim

# install tools and dependencies
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get upgrade -y && \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
clang cmake curl git pkg-config && \
# apt cleanup
apt-get autoremove -y && \
apt-get clean && \
find /var/lib/apt/lists/ -type f -not -name lock -delete; \
# add user and link ~/.local/share/polkadot to /data
useradd -m -u 1000 -U -s /bin/sh -d /polkadot polkadot && \
mkdir -p /data /polkadot/.local/share && \
chown -R polkadot:polkadot /data && \
ln -s /data /polkadot/.local/share/polkadot

# install rust toolchain
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y && \
export PATH="$PATH:$HOME/.cargo/bin" && \
rustup toolchain install nightly && \
rustup target add wasm32-unknown-unknown --toolchain nightly && \
rustup default stable

# clone polkadot. the trick of using the github API will make the docker cache
# invalidate when there's a new commit.
ADD https://api.github.com/repos/paritytech/polkadot/git/refs/heads/rococo-v1 version.json
RUN git clone -b rococo-v1 https://github.com/paritytech/polkadot.git /tmp/polkadot

# build polkadot
RUN cd /tmp/polkadot && \
export PATH="$PATH:$HOME/.cargo/bin" && \
cargo build --release && \
cp /tmp/polkadot/target/release/polkadot /usr/local/bin

# show backtraces
ENV RUST_BACKTRACE 1

USER polkadot

# check if executable works in this container
RUN /usr/local/bin/polkadot --version

EXPOSE 30333 9933 9944
VOLUME ["/polkadot"]

ENTRYPOINT ["/usr/local/bin/polkadot"]
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@polkadot/util-crypto": "^6.1.1",
"filter-console": "^0.1.1",
"typescript": "^4.1.5",
"yaml": "^1.10.2",
"yargs": "^15.4.1",
"yarn": "^1.22.10"
},
Expand Down
25 changes: 20 additions & 5 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
{ pkgs ? import <nixpkgs> { } }:
let
polkadot-launch = pkgs.callPackage ./default.nix { };
in
pkgs.mkShell {

with pkgs; mkShell {
buildInputs = [
polkadot-launch
nodejs
python27
python27Packages.pip
python27Packages.setuptools
stdenv
yarn
yarn2nix
];

shellHook = ''
# Tells pip to put packages into $PIP_PREFIX instead of the usual locations.
# See https://pip.pypa.io/en/stable/user_guide/#environment-variables.
export PIP_PREFIX=${toString ./.}/_build/pip_packages
export PYTHONPATH="$PIP_PREFIX/${python27.sitePackages}:$PYTHONPATH"
export PATH="$PIP_PREFIX/bin:$PATH"
unset SOURCE_DATE_EPOCH
# NOTE: the line below is commented as this is not compatible with lorri
# pip install blockade
'';
}
Loading