Skip to content

Commit

Permalink
Merge pull request #26 from eigerco/feat/10/testing-environment
Browse files Browse the repository at this point in the history
test: setup testing environment and reproducible build
  • Loading branch information
serg-temchenko authored May 16, 2024
2 parents 6ea4d8a + d5324c6 commit 63f2846
Show file tree
Hide file tree
Showing 11 changed files with 311 additions and 39 deletions.
8 changes: 8 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

if ! has nix_direnv_version || ! nix_direnv_version 3.0.4; then
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.4/direnvrc" "sha256-DzlYZ33mWF/Gs8DDeyjr8mnVmQGx7ASYqA5WlxwvBG4="
fi

watch_file rust-toolchain.toml
use flake
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ target/

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

# reproducible local environment
.direnv
2 changes: 2 additions & 0 deletions .taplo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
exclude = [".direnv/*", "target/*"]

[[rule]]
include = ["**/*.toml"]

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ cumulus-pallet-parachain-system = { git = "https://github.com/paritytech/polkado
cumulus-pallet-session-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false }
cumulus-pallet-xcm = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false }
cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false }
cumulus-primitives-core = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default_features = false }
cumulus-primitives-core = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false }
cumulus-primitives-parachain-inherent = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" }
cumulus-primitives-storage-weight-reclaim = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false }
cumulus-primitives-utility = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false }
Expand Down
42 changes: 42 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Development environment for Polka Storage Node

## Setup

### Requirements
- [nix](https://nixos.org/download/) with [flakes](https://nixos.wiki/wiki/flakes) enabled (`echo 'experimental-features = nix-command flakes' >> ~/.config/nix/nix.conf`)
- reasoning: every developer has the same version of development tools (rust, protoc, zombienet), directed by [flake.nix](./flake.nix)`.
- how it works? fasterthanli.me has [a whole series on it](https://fasterthanli.me/series/building-a-rust-service-with-nix/part-10).
- optional: [vscode extension for Nix](https://marketplace.visualstudio.com/items?itemName=jnoortheen.nix-ide)
- [direnv](https://direnv.net/) with a [shell hook](https://direnv.net/docs/hook.html)
- *VS Code only* [direnv extension](https://marketplace.visualstudio.com/items?itemName=mkhl.direnv) (uses the same tooling as rust-toolchain.toml defined).
- reasoning: when you enter a directory it uses everything defined in [.envrc](./.envrc), e.g. environment variables, `nix`, secrets.

## How it works?
Nix is a package manager, which sneakily downloads all of the dependencies and updates PATH when you launch it with `nix develop`.
You end up having all of the required dependencies in a configured shell (so you don't have to install a specific cargo version, just, polkadot on your own).
`nix develop` needs to be used in the workspace root, as it depends on [flake.nix](./flake.nix) file.
`direnv` is a shell hook, which configures your shell based on the [.envrc](./.envrc) file.
In our case it just launches `nix develop` shell for you and when you exit the folder, it disables it.


## Usage

1. Verify:
```
$ polkadot --version
polkadot 1.11.0-0bb6249
$ cargo --version
cargo 1.77.0 (3fe68eabf 2024-02-29)
$ zombienet version
1.3.103
```
2. `just testnet`
3. Click `charlie`'s direct link (should look like `https://polkadot.js.org/apps/?rpc=ws://<address here>#/explorer`). It will take you to the parachain interface where you can monitor block production.
- testnet is defined via [zombienet configuration](https://paritytech.github.io/zombienet/guide.html) in [local-testnet.toml](./scripts//local-testnet.toml)

## Maintenance

- Updating nix flakes (`flake.lock` file has frozen state of package): `nix flake update`.
- Running out of the disk space? `nix-collect-garbage`.
16 changes: 16 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
alias b := build
alias r := release
alias t := testnet

lint:
cargo clippy --locked --no-deps -- -D warnings
taplo lint && taplo fmt --check

build: lint
cargo build

release: lint
cargo build --release

testnet: release
zombienet -p native spawn zombienet/local-testnet.toml
159 changes: 159 additions & 0 deletions flake.lock

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

54 changes: 54 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
};
};
zombienet = {
url = "github:paritytech/zombienet";
inputs = {
nixpkgs.follows = "nixpkgs";
};
};
};
outputs = { self, nixpkgs, flake-utils, rust-overlay, zombienet }:
flake-utils.lib.eachDefaultSystem (system:
let
overlays = [ (import rust-overlay) zombienet.overlays.default ];
pkgs = import nixpkgs {
inherit system overlays;
};
rustToolchain = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
buildInputs = with pkgs; [
clang
pkg-config
rustToolchain
just
taplo
polkadot
# Due to zombienet's flake.nix, needs to be prefixed with pkg.zombienet
pkgs.zombienet.default
] ++ lib.optionals stdenv.isDarwin [
darwin.apple_sdk.frameworks.Security
darwin.apple_sdk.frameworks.CoreServices
darwin.apple_sdk.frameworks.SystemConfiguration
];
in
with pkgs;
{
devShells.default = mkShell {
inherit buildInputs;

LIBCLANG_PATH = "${llvmPackages.libclang.lib}/lib";
PROTOC = "${protobuf}/bin/protoc";
RUST_SRC_PATH = "${rustToolchain}/lib/rustlib/src/rust/library/";
ROCKSDB_LIB_DIR = "${rocksdb}/lib";
};
}
);
}
38 changes: 0 additions & 38 deletions polkadot-launch/config.json

This file was deleted.

5 changes: 5 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[toolchain]
channel = "1.77.0"
components = ["cargo", "clippy", "rust-analyzer", "rust-src", "rust-std", "rustc", "rustc-dev", "rustfmt"]
profile = "minimal"
targets = ["wasm32-unknown-unknown"]
21 changes: 21 additions & 0 deletions zombienet/local-testnet.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[relaychain]
chain = "rococo-local"
default_command = "polkadot"

[[relaychain.nodes]]
name = "alice"
validator = true

[[relaychain.nodes]]
name = "bob"
validator = true

[[parachains]]
cumulus_based = true
id = 2000

# run charlie as parachain collator
[[parachains.collators]]
command = "target/release/polka-storage-node"
name = "charlie"
validator = true

0 comments on commit 63f2846

Please sign in to comment.