|
| 1 | +# Zombienet overview |
| 2 | + |
| 3 | +- [Zombienet overview](#zombienet-overview) |
| 4 | + - [Requirements](#requirements) |
| 5 | + - [Initial setup](#initial-setup) |
| 6 | + - [Creating a zombienet-valid dockerfile](#creating-a-zombienet-valid-dockerfile) |
| 7 | + - [Creating the zombienet manifest](#creating-the-zombienet-manifest) |
| 8 | + - [Deploying the custom parachain locally](#deploying-the-custom-parachain-locally) |
| 9 | + - [Updating the parachain image](#updating-the-parachain-image) |
| 10 | + - [Troubleshooting](#troubleshooting) |
| 11 | + - [Timeout errors](#timeout-errors) |
| 12 | + - [Cannot exec into a container in a completed pod](#cannot-exec-into-a-container-in-a-completed-pod) |
| 13 | + |
| 14 | +## Requirements |
| 15 | +- Docker |
| 16 | +- Dockerhub account |
| 17 | +- Minikube |
| 18 | +- Kubectl |
| 19 | +- Node 16 |
| 20 | +- Clone and follow the [Zombienet installation and setup](https://github.com/paritytech/zombienet#installation) (PATH setup is optional) |
| 21 | + |
| 22 | +## Initial setup |
| 23 | + |
| 24 | +First, start the minikube cluster. |
| 25 | + |
| 26 | +```bash |
| 27 | +minikube start |
| 28 | +``` |
| 29 | + |
| 30 | +Within the Zombienet repo directory, make sure that the tool is deploying the network examples correctly. |
| 31 | +```bash |
| 32 | +cd zombienet |
| 33 | +node dist/cli.js spawn ./examples/0001-small-network.toml |
| 34 | +``` |
| 35 | +If the process results in a Timeout error, refer to the [troubleshooting guide](#timeout-errors) taking into consideration the image that zombienet failed to pull. |
| 36 | + |
| 37 | +After some intermediate tables, a successful deployment should print a `Network launched 🚀🚀` table. Note that the polkadotjs endpoints are specified in the `Direct link` rows. Both the relay and parachain should be running at this point. |
| 38 | + |
| 39 | + |
| 40 | +By pressing `ctr+c` all the processes should stop. |
| 41 | + |
| 42 | +The zombienet manifest that was deployed is a simple relaychain to parachain connection, in which the rococo chain has 2 nodes (alice and bob nodes), while the connected parachain (100) is a template with only one collator: |
| 43 | +```toml |
| 44 | +[relaychain] |
| 45 | +default_image = "docker.io/paritypr/polkadot-debug:master" |
| 46 | +default_command = "polkadot" |
| 47 | +default_args = [ "-lparachain=debug" ] |
| 48 | + |
| 49 | +chain = "rococo-local" |
| 50 | + |
| 51 | + [[relaychain.nodes]] |
| 52 | + name = "alice" |
| 53 | + validator = true |
| 54 | + |
| 55 | + [[relaychain.nodes]] |
| 56 | + name = "bob" |
| 57 | + validator = true |
| 58 | + |
| 59 | +[[parachains]] |
| 60 | +id = 100 |
| 61 | + |
| 62 | + [parachains.collator] |
| 63 | + name = "collator01" |
| 64 | + image = "docker.io/paritypr/colander:master" |
| 65 | + command = "adder-collator" |
| 66 | +``` |
| 67 | +The `command = "adder-collator"` specifies the node executable (similar to `./target/release/hashed-parachain`). |
| 68 | + |
| 69 | +## Creating a zombienet-valid dockerfile |
| 70 | +The next section will be performed under the parachain repository instead of the zombienet one. |
| 71 | + |
| 72 | +Now that all the tools are functional, the next step is to create a docker image that replaces the parachain template (the file exists in this repository under the name of `collator.Dockerfile`): |
| 73 | +```docker |
| 74 | +FROM paritytech/ci-linux:production |
| 75 | +
|
| 76 | +# this dir doesnt exists but zombienet script tries to create a file within |
| 77 | +RUN mkdir /cfg |
| 78 | +
|
| 79 | +WORKDIR /var/www |
| 80 | +
|
| 81 | +RUN git clone https://github.com/hashed-io/hashed-substrate.git |
| 82 | +
|
| 83 | +WORKDIR /var/www/hashed-substrate |
| 84 | +# change to main or develop |
| 85 | +RUN git checkout develop && cargo build --release |
| 86 | +
|
| 87 | +EXPOSE 30333 40333 9933 9944 9946 |
| 88 | +
|
| 89 | +# add binary to usr folder, according to the best practices |
| 90 | +RUN mv /var/www/hashed-substrate/target/release/hashed-parachain /usr/local/bin |
| 91 | +
|
| 92 | +# check if executable works in this container |
| 93 | +RUN /usr/local/bin/hashed-parachain --version |
| 94 | +# ENTRYPOINT allows to add parameters/flags via k8 manifests |
| 95 | +ENTRYPOINT [ "hashed-parachain" ] |
| 96 | +``` |
| 97 | + |
| 98 | +Build and publish the docker image using the `collator.Dockerfile`, it is recommended to change the tag and name: |
| 99 | +```bash |
| 100 | +# change abhashed/test-collator to a desired tag/dockerhub-name. Building the image will take a while. |
| 101 | +docker build -t abhashed/test-collator -f collator.Dockerfile . |
| 102 | +# When the process is finished, push the image to the desired dockerhub account. |
| 103 | +docker push abhashed/test-collator |
| 104 | +``` |
| 105 | + |
| 106 | +## Creating the zombienet manifest |
| 107 | +Based on the example provided by zombienet, a simple deployment was declared using a compatible `polkadot` image (in this case, v0.9.27), while the parachain nodes will be instanced from the custom docker image (this file exists in this repo under the name `k8-manifests/zombienet-local.toml`). |
| 108 | +```toml |
| 109 | +[relaychain] |
| 110 | +default_image = "docker.io/parity/polkadot:v0.9.27" |
| 111 | +default_command = "polkadot" |
| 112 | +default_args = [ "-lparachain=debug" ] |
| 113 | + |
| 114 | +chain = "rococo-local" |
| 115 | + |
| 116 | + [[relaychain.nodes]] |
| 117 | + name = "alice" |
| 118 | + validator = true |
| 119 | + |
| 120 | + [[relaychain.nodes]] |
| 121 | + name = "bob" |
| 122 | + validator = true |
| 123 | + |
| 124 | +[[parachains]] |
| 125 | +# it can be any number, doesn't need be aligned to the parachain_id declared on the chainspec |
| 126 | +id = 2000 |
| 127 | +cumulus_based = true |
| 128 | + |
| 129 | + [parachains.collator] |
| 130 | + name = "collator01" |
| 131 | + image = "docker.io/abhashed/test-collator" |
| 132 | + command = "hashed-parachain" |
| 133 | +``` |
| 134 | + |
| 135 | +## Deploying the custom parachain locally |
| 136 | + |
| 137 | +It is highly recommended to pull the published parachain image before deploying [using these steps](#timeout-errors), as it is highly probable to get timeout errors due to the image size. |
| 138 | + |
| 139 | +When executing the zombienet command, the only thing that must be specified is the zombienet manifest (in this case, `../hashed-substrate/k8-manifests/zombienet-local.toml`) instead of the example file. |
| 140 | + |
| 141 | +```bash |
| 142 | +node dist/cli.js spawn ../hashed-substrate/k8-manifests/zombienet-local.toml |
| 143 | +``` |
| 144 | + |
| 145 | +The process should display an almost identical process from the testing deployment. |
| 146 | + |
| 147 | +## Updating the parachain image |
| 148 | +If there's a change that needs to be locally tested, it is recommended to rebuild and publish the docker image and [download the update on minikube](#timeout-errors). |
| 149 | + |
| 150 | +## Troubleshooting |
| 151 | + |
| 152 | +### Timeout errors |
| 153 | + |
| 154 | +If an image takes too long to download, it will result in a timeout error. It is recommended to pull the required images beforehand. |
| 155 | +```bash |
| 156 | +# Enter to the minikube container through ssh |
| 157 | +minikube ssh |
| 158 | +# Pull the required images, it may take a while |
| 159 | +docker@minikube:~$ docker pull abhashed/test-collator |
| 160 | +# When finished exit the minikube container |
| 161 | +docker@minikube:~$ exit |
| 162 | +# Retry the zombienet deployment process |
| 163 | +node dist/cli.js spawn ./examples/md5.toml |
| 164 | +``` |
| 165 | +It is also recommended to check if the image is published by the same name and tag. |
| 166 | + |
| 167 | +### Cannot exec into a container in a completed pod |
| 168 | + |
| 169 | + |
| 170 | + |
| 171 | +This error usually implies there's at least one misconfiguration on the parachain image, the following examples were found: |
| 172 | +- Zombienet tried to create a file in a directory that doesn't exist. |
| 173 | +- The parachain executable (e.g. `./target/release/hashed-parachain`) wasn't found in the provided `command = <executable>` path. |
| 174 | +- Zombienet tried to replace the `para_id` in the chain spec, but it wasn't found. |
| 175 | +- Any other issue that might cause the container to end unexpectedly. |
| 176 | + |
| 177 | +In order to discover the exact issue, the following steps are recommended: |
| 178 | +1. Zombienet produces intermediate pods for each step. Identify the last pod that was instanced successfully before the error logs appeared (e.g. `temp-1`, `temp-2`, etc). |
| 179 | + |
| 180 | +2. Prepare another terminal with the command for getting the logs for the temporal pod (e.g `kubectl logs -f temp-2 -n <namespace>`), the namespace will be pasted when available on later steps. |
| 181 | +3. In the first terminal, run the zombienet spawn command again, the first table will have the generated namespace, copy the string. |
| 182 | + |
| 183 | +4. Paste the string in the namespace option on the second terminal to complete the command (e.g `kubectl logs -f temp-2 -n zombie-8445ff441ef788f160070687bb33f3a0`), and run the command when the first terminal initializes the desired container, in this case, temp-2. |
| 184 | +5. The output should contain an error description. |
| 185 | +``` |
| 186 | +❯ kubectl logs -f temp-2 -n zombie-943cbea55d3294c8968afeca7dcf8bd3 |
| 187 | +Defaulted container "temp-2" out of: temp-2, transfer-files-container (init) |
| 188 | +Error: Input("Error parsing spec file: unknown field `para_id` at line 113 column 1") |
| 189 | +copy files has finished |
| 190 | +``` |
| 191 | +In this specific case, the para_id field was not recognized by the chain, which means the `#[serde(rename_all = "camelCase")]` line in the `collator/src/chain_spec/mod.rs` was renaming para_id as paraId, causing conflicts in the zombienet internal processes. Removing that line was enough to fix the error. |
0 commit comments