From 2e85e5ad09b8364552a0f35f8133fa72742d14f9 Mon Sep 17 00:00:00 2001 From: aidan Date: Wed, 8 May 2024 14:07:53 +0200 Subject: [PATCH 01/48] feat: Add taplo CI `taplo lint` and `taplo format`, in that order, have been add on push and pull request into any branch. --- .github/workflows/taplo.yaml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .github/workflows/taplo.yaml diff --git a/.github/workflows/taplo.yaml b/.github/workflows/taplo.yaml new file mode 100644 index 000000000..900eea7f2 --- /dev/null +++ b/.github/workflows/taplo.yaml @@ -0,0 +1,24 @@ +name: Taplo formatting and linting + +on: + [push, pull_request] + +jobs: + lint: + name: Lint Cargo.toml + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: uncenter/setup-taplo@v1.0.8 + + - run: taplo lint --verbose + fmt: + name: Format Cargo.toml + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: uncenter/setup-taplo@v1.0.8 + + - run: taplo format --check --verbose From a89271e39979edbef2d73e73c80c632ed254adb2 Mon Sep 17 00:00:00 2001 From: aidan Date: Wed, 8 May 2024 16:03:12 +0200 Subject: [PATCH 02/48] feat: Add taplo config file Add a configuration file for taplo so CI and local can use the same taplo rules. --- .taplo.toml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .taplo.toml diff --git a/.taplo.toml b/.taplo.toml new file mode 100644 index 000000000..f37a20722 --- /dev/null +++ b/.taplo.toml @@ -0,0 +1,6 @@ +[[rule]] +include = ["**/Cargo.toml"] + +[rule.formatting] +reorder_arrays = true +reorder_keys = true From 3dd4d069d961a2d1b97395575632ec086a874cc1 Mon Sep 17 00:00:00 2001 From: aidan Date: Wed, 8 May 2024 17:07:22 +0200 Subject: [PATCH 03/48] feat: Add path to taplo CI --- .github/workflows/taplo.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/taplo.yaml b/.github/workflows/taplo.yaml index 900eea7f2..fcb6e1b4e 100644 --- a/.github/workflows/taplo.yaml +++ b/.github/workflows/taplo.yaml @@ -1,7 +1,10 @@ name: Taplo formatting and linting on: - [push, pull_request] + push: + paths: "**/Cargo.toml" + pull_request: + paths: "**/Cargo.toml" jobs: lint: From 7625986e08a7f5a777bd4ed04429be7faafc71c5 Mon Sep 17 00:00:00 2001 From: aidan Date: Wed, 8 May 2024 18:28:40 +0200 Subject: [PATCH 04/48] ci: Update taplo CI Switch from Action for taplo CI to manual install and running. Use only `taplo format` and remove `taplo lint` check. --- .github/workflows/taplo.yaml | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/.github/workflows/taplo.yaml b/.github/workflows/taplo.yaml index fcb6e1b4e..15cca0b01 100644 --- a/.github/workflows/taplo.yaml +++ b/.github/workflows/taplo.yaml @@ -1,4 +1,4 @@ -name: Taplo formatting and linting +name: Taplo formatting on: push: @@ -7,21 +7,17 @@ on: paths: "**/Cargo.toml" jobs: - lint: - name: Lint Cargo.toml + toml: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - - uses: uncenter/setup-taplo@v1.0.8 - - - run: taplo lint --verbose - fmt: - name: Format Cargo.toml - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - uses: uncenter/setup-taplo@v1.0.8 - - - run: taplo format --check --verbose + - uses: dtolnay/rust-toolchain@stable + - name: Install taplo + run: cargo install taplo-cli --lock + - name: Run taplo + run: taplo format --check --diff + - name: Taplo failure info + if: failure() + run: | + echo 'TOML is not formatted correctly' + echo 'Please run `taplo format`' From e8d98237f182a18678fd14c09a1bbde3b7a4bdfc Mon Sep 17 00:00:00 2001 From: Aidan Date: Wed, 8 May 2024 20:12:43 +0200 Subject: [PATCH 05/48] ci: Move taplo.yaml into ci.yaml --- .github/workflows/{taplo.yaml => ci.yaml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{taplo.yaml => ci.yaml} (100%) diff --git a/.github/workflows/taplo.yaml b/.github/workflows/ci.yaml similarity index 100% rename from .github/workflows/taplo.yaml rename to .github/workflows/ci.yaml From 4e27a18010983028339233dd514888be2901a9cf Mon Sep 17 00:00:00 2001 From: Aidan Date: Wed, 8 May 2024 20:13:36 +0200 Subject: [PATCH 06/48] ci: Change taplo rules --- .github/workflows/ci.yaml | 4 ++-- .taplo.toml | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 15cca0b01..e40a0716e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -2,9 +2,9 @@ name: Taplo formatting on: push: - paths: "**/Cargo.toml" + paths: "**/*.toml" pull_request: - paths: "**/Cargo.toml" + paths: "**/*.toml" jobs: toml: diff --git a/.taplo.toml b/.taplo.toml index f37a20722..d5aa3c0ce 100644 --- a/.taplo.toml +++ b/.taplo.toml @@ -1,6 +1,7 @@ [[rule]] -include = ["**/Cargo.toml"] +include = ["**/*.toml"] [rule.formatting] reorder_arrays = true reorder_keys = true +column_width = 150 From a7c35dc3552a70e00eabd2dd9744cd9116613aa1 Mon Sep 17 00:00:00 2001 From: Aidan Date: Wed, 8 May 2024 20:15:25 +0200 Subject: [PATCH 07/48] ci: Add cargo version for debugging --- .github/workflows/ci.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index e40a0716e..24af8a277 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -12,6 +12,8 @@ jobs: steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable + - name: List cargo version + run: cargo --version - name: Install taplo run: cargo install taplo-cli --lock - name: Run taplo From 0306e16801ea8aa4c6bfd8fb9d5c630a7b61c891 Mon Sep 17 00:00:00 2001 From: Aidan Date: Wed, 8 May 2024 20:20:45 +0200 Subject: [PATCH 08/48] ci: Add taplo version for debugging --- .github/workflows/ci.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 24af8a277..53b6d46e9 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -15,7 +15,9 @@ jobs: - name: List cargo version run: cargo --version - name: Install taplo - run: cargo install taplo-cli --lock + run: cargo install taplo-cli --locked + - name: List taplo version + run: taplo --version - name: Run taplo run: taplo format --check --diff - name: Taplo failure info From af2e853ec0a740b90d9ca135241a21da3ac6658f Mon Sep 17 00:00:00 2001 From: Aidan Date: Wed, 8 May 2024 20:29:00 +0200 Subject: [PATCH 09/48] ci: Add version for debugging --- .github/workflows/ci.yaml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 53b6d46e9..9c15128b8 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -12,12 +12,14 @@ jobs: steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable - - name: List cargo version - run: cargo --version - name: Install taplo run: cargo install taplo-cli --locked - - name: List taplo version - run: taplo --version + - name: List versions + run: | + cargo --version + cargo clippy --version + cargo fmt --version + taplo --version - name: Run taplo run: taplo format --check --diff - name: Taplo failure info From 0d868f3fdb880f82d04bf4c4d88127eda38c25ac Mon Sep 17 00:00:00 2001 From: Aidan Date: Wed, 8 May 2024 20:31:17 +0200 Subject: [PATCH 10/48] ci: Formatting --- .github/workflows/ci.yaml | 2 -- .taplo.toml | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 9c15128b8..5efc42936 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -17,8 +17,6 @@ jobs: - name: List versions run: | cargo --version - cargo clippy --version - cargo fmt --version taplo --version - name: Run taplo run: taplo format --check --diff diff --git a/.taplo.toml b/.taplo.toml index d5aa3c0ce..a5e91e369 100644 --- a/.taplo.toml +++ b/.taplo.toml @@ -2,6 +2,6 @@ include = ["**/*.toml"] [rule.formatting] +column_width = 150 reorder_arrays = true reorder_keys = true -column_width = 150 From e6fda54cb98f1504ad10e49643149ba13d46c509 Mon Sep 17 00:00:00 2001 From: aidan Date: Thu, 9 May 2024 17:37:33 +0200 Subject: [PATCH 11/48] ci: Change workflow name --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5efc42936..0b3a5b267 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,4 +1,4 @@ -name: Taplo formatting +name: CI on: push: From c2ec968884cb7b806348f206a7a70e6ed7f28519 Mon Sep 17 00:00:00 2001 From: aidan Date: Fri, 10 May 2024 11:22:40 +0200 Subject: [PATCH 12/48] ci: Remove path filtering --- .github/workflows/ci.yaml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 0b3a5b267..d469d9d49 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,10 +1,6 @@ name: CI -on: - push: - paths: "**/*.toml" - pull_request: - paths: "**/*.toml" +on: [push, pull_request] jobs: toml: From 878fc5d21d716bb593e93f9d32683ca40bb96bc8 Mon Sep 17 00:00:00 2001 From: aidan Date: Fri, 10 May 2024 15:46:21 +0200 Subject: [PATCH 13/48] ci: Add cargo fmt job --- .github/workflows/ci.yaml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index d469d9d49..4006a055f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -21,3 +21,20 @@ jobs: run: | echo 'TOML is not formatted correctly' echo 'Please run `taplo format`' + + format: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + - name: List version + run: | + cargo --version + cargo fmt --version + - name: Cargo format + run: cargo fmt --all -- --check + - name: Cargo fmt failure info + if: failure() + run: | + echo '.rs files are not formatted correctly' + echo 'Please run `cargo fmt --all`' From f7823aa30dada0e94e229070e58dd9f4755d5ff3 Mon Sep 17 00:00:00 2001 From: aidan Date: Fri, 10 May 2024 15:53:42 +0200 Subject: [PATCH 14/48] ci: Add rustfmt for format rules --- .rustfmt.toml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .rustfmt.toml diff --git a/.rustfmt.toml b/.rustfmt.toml new file mode 100644 index 000000000..a0347832e --- /dev/null +++ b/.rustfmt.toml @@ -0,0 +1,3 @@ +edition = "2021" +imports_granularity = "Crate" +group_imports = "StdExternalCrate" From 73f634c269aafeaf44016d85585c5928047646e8 Mon Sep 17 00:00:00 2001 From: aidan Date: Fri, 10 May 2024 15:58:12 +0200 Subject: [PATCH 15/48] ci: Add clippy job --- .github/workflows/ci.yaml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 4006a055f..44690c6d6 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -38,3 +38,20 @@ jobs: run: | echo '.rs files are not formatted correctly' echo 'Please run `cargo fmt --all`' + + clippy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + - name: List version + run: | + cargo --version + cargo clippy --version + - name: Cargo clippy + run: cargo clippy -- -D warnings + - name: Cargo clippy failure info + if: failure() + run: | + echo '`cargo clippy` failed' + echo 'Please fix the issue generated by clippy' From fb95a522230553f75211da117fd103eb0960965f Mon Sep 17 00:00:00 2001 From: aidan Date: Fri, 10 May 2024 16:25:19 +0200 Subject: [PATCH 16/48] ci: Add build job --- .github/workflows/ci.yaml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 44690c6d6..85387014a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -55,3 +55,19 @@ jobs: run: | echo '`cargo clippy` failed' echo 'Please fix the issue generated by clippy' + + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + - name: List version + run: cargo --version + - name: Build with try-runtime feature + run: RUSTFLAGS="-D warnings" cargo build --features try-runtime + - name: Build node runtime + run: RUSTFLAGS="-D warnings" cargo build -p polka-storage-runtime + - name: Build node with runtime-benchmark feature + run: RUSTFLAGS="-D warnings" cargo build -p polka-storage-node --features runtime-benchmarks + - name: Build in release mode + run: RUSTFLAGS="-D warnings" cargo build --release From 60ea24b682875aa5e557179403fef4eaeab25ce5 Mon Sep 17 00:00:00 2001 From: aidan Date: Fri, 10 May 2024 16:26:44 +0200 Subject: [PATCH 17/48] ci: Add test job --- .github/workflows/ci.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 85387014a..3f58acdbe 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -71,3 +71,13 @@ jobs: run: RUSTFLAGS="-D warnings" cargo build -p polka-storage-node --features runtime-benchmarks - name: Build in release mode run: RUSTFLAGS="-D warnings" cargo build --release + + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + - name: List version + run: cargo --version + - name: Run tests + run: RUSTFLAGS="-D warnings" cargo test --workspace From 5ba437de00994e12e405c85fe41678c10f54679c Mon Sep 17 00:00:00 2001 From: aidan Date: Fri, 10 May 2024 16:30:30 +0200 Subject: [PATCH 18/48] ci: Add failure handling --- .github/workflows/ci.yaml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3f58acdbe..6a5b9412d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -65,12 +65,28 @@ jobs: run: cargo --version - name: Build with try-runtime feature run: RUSTFLAGS="-D warnings" cargo build --features try-runtime + - name: try-runtime build failure + if: failure() + run: | + echo 'Building with `try-runtime` feature failed' - name: Build node runtime run: RUSTFLAGS="-D warnings" cargo build -p polka-storage-runtime + - name: Node runtime build failure + if: failure() + run: | + echo 'Building the node runtime failed' - name: Build node with runtime-benchmark feature run: RUSTFLAGS="-D warnings" cargo build -p polka-storage-node --features runtime-benchmarks + - name: runtime-benchmark build failure + if: failure() + run: | + echo 'Failed to build node with runtime-benchmark feature' - name: Build in release mode run: RUSTFLAGS="-D warnings" cargo build --release + - name: Release build failed + if: failure() + run: | + echo '`cargo build --release` failed' test: runs-on: ubuntu-latest @@ -81,3 +97,7 @@ jobs: run: cargo --version - name: Run tests run: RUSTFLAGS="-D warnings" cargo test --workspace + - name: Cargo test fail + if: failure() + run: | + echo '`cargo test --workspace` failed' From 4b0688495dca5c21f09d7fdc1423ccbe4acbe532 Mon Sep 17 00:00:00 2001 From: aidan Date: Mon, 13 May 2024 13:35:09 +0200 Subject: [PATCH 19/48] ci: Add wasm target to relevant jobs --- .github/workflows/ci.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6a5b9412d..49154131f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -44,6 +44,9 @@ jobs: steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable + with: + target: wasm32-unknown-unknown + components: clippy - name: List version run: | cargo --version @@ -61,6 +64,8 @@ jobs: steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable + with: + target: wasm32-unknown-unknown - name: List version run: cargo --version - name: Build with try-runtime feature @@ -93,6 +98,8 @@ jobs: steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable + with: + target: wasm32-unknown-unknown - name: List version run: cargo --version - name: Run tests From e826882ca220b506f2b508f54bbf13170301b2f2 Mon Sep 17 00:00:00 2001 From: aidan Date: Mon, 13 May 2024 13:42:33 +0200 Subject: [PATCH 20/48] ci: Add nightly toolchain to fmt job --- .github/workflows/ci.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 49154131f..95d0c2777 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -27,6 +27,8 @@ jobs: steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable + with: + toolchain: nightly - name: List version run: | cargo --version From 97b7fe52209d87babbb63731be78775974ba721b Mon Sep 17 00:00:00 2001 From: aidan Date: Mon, 13 May 2024 13:45:49 +0200 Subject: [PATCH 21/48] ci: Add rusfmt component to format job --- .github/workflows/ci.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 95d0c2777..2a131694c 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -29,6 +29,7 @@ jobs: - uses: dtolnay/rust-toolchain@stable with: toolchain: nightly + components: rustfmt - name: List version run: | cargo --version From a18daba66f83399a979c4cd5dcfddd051eb9ab3f Mon Sep 17 00:00:00 2001 From: aidan Date: Mon, 13 May 2024 13:57:28 +0200 Subject: [PATCH 22/48] ci: Add protobuf compiler package to test job --- .github/workflows/ci.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 2a131694c..5ea675ca9 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -100,6 +100,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - name: Install protobuf compiler + run: | + sudo apt-get update + sudo apt-get install protobuf-compiler - uses: dtolnay/rust-toolchain@stable with: target: wasm32-unknown-unknown From e25520953ed66c788d64d657cddcb54ed1b96e25 Mon Sep 17 00:00:00 2001 From: aidan Date: Mon, 13 May 2024 13:58:01 +0200 Subject: [PATCH 23/48] ci: Add protobuf compiler to build job --- .github/workflows/ci.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5ea675ca9..81b5a6f01 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -66,6 +66,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - name: Install protobuf compiler + run: | + sudo apt-get update + sudo apt-get install protobuf-compiler - uses: dtolnay/rust-toolchain@stable with: target: wasm32-unknown-unknown From d0fe799247a33a2583de93360d43d4ecb9ea2310 Mon Sep 17 00:00:00 2001 From: aidan Date: Mon, 13 May 2024 13:58:38 +0200 Subject: [PATCH 24/48] ci: Add protobuf compiler to format job --- .github/workflows/ci.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 81b5a6f01..65856f1b7 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -46,6 +46,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - name: Install protobuf compiler + run: | + sudo apt-get update + sudo apt-get install protobuf-compiler - uses: dtolnay/rust-toolchain@stable with: target: wasm32-unknown-unknown From 418e60c2bfb2dfd0c9bdec6140d9f056abf64176 Mon Sep 17 00:00:00 2001 From: aidan Date: Mon, 13 May 2024 14:40:11 +0200 Subject: [PATCH 25/48] ci: Add stable target to relevant jobs --- .github/workflows/ci.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 65856f1b7..0c423bc11 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -52,7 +52,7 @@ jobs: sudo apt-get install protobuf-compiler - uses: dtolnay/rust-toolchain@stable with: - target: wasm32-unknown-unknown + target: wasm32-unknown-unknown, stable-x86_64-unknown-linux-gnu components: clippy - name: List version run: | @@ -76,7 +76,7 @@ jobs: sudo apt-get install protobuf-compiler - uses: dtolnay/rust-toolchain@stable with: - target: wasm32-unknown-unknown + target: wasm32-unknown-unknown, stable-x86_64-unknown-linux-gnu - name: List version run: cargo --version - name: Build with try-runtime feature @@ -114,7 +114,7 @@ jobs: sudo apt-get install protobuf-compiler - uses: dtolnay/rust-toolchain@stable with: - target: wasm32-unknown-unknown + target: wasm32-unknown-unknown, stable-x86_64-unknown-linux-gnu - name: List version run: cargo --version - name: Run tests From 6c51b1f9d06c9518733f66d880f15317921376f1 Mon Sep 17 00:00:00 2001 From: aidan Date: Mon, 13 May 2024 14:53:45 +0200 Subject: [PATCH 26/48] ci: Add nightly toolchain --- .github/workflows/ci.yaml | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 0c423bc11..18aaf5b0f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -20,7 +20,7 @@ jobs: if: failure() run: | echo 'TOML is not formatted correctly' - echo 'Please run `taplo format`' + echo 'Please run taplo format' format: runs-on: ubuntu-latest @@ -40,7 +40,7 @@ jobs: if: failure() run: | echo '.rs files are not formatted correctly' - echo 'Please run `cargo fmt --all`' + echo 'Please run cargo fmt --all' clippy: runs-on: ubuntu-latest @@ -52,7 +52,8 @@ jobs: sudo apt-get install protobuf-compiler - uses: dtolnay/rust-toolchain@stable with: - target: wasm32-unknown-unknown, stable-x86_64-unknown-linux-gnu + toolchain: nightly + target: wasm32-unknown-unknown components: clippy - name: List version run: | @@ -63,7 +64,7 @@ jobs: - name: Cargo clippy failure info if: failure() run: | - echo '`cargo clippy` failed' + echo 'cargo clippy failed' echo 'Please fix the issue generated by clippy' build: @@ -76,7 +77,8 @@ jobs: sudo apt-get install protobuf-compiler - uses: dtolnay/rust-toolchain@stable with: - target: wasm32-unknown-unknown, stable-x86_64-unknown-linux-gnu + toolchain: nightly + target: wasm32-unknown-unknown - name: List version run: cargo --version - name: Build with try-runtime feature @@ -102,7 +104,7 @@ jobs: - name: Release build failed if: failure() run: | - echo '`cargo build --release` failed' + echo 'cargo build --release failed' test: runs-on: ubuntu-latest @@ -114,7 +116,8 @@ jobs: sudo apt-get install protobuf-compiler - uses: dtolnay/rust-toolchain@stable with: - target: wasm32-unknown-unknown, stable-x86_64-unknown-linux-gnu + toolchain: nightly + target: wasm32-unknown-unknown - name: List version run: cargo --version - name: Run tests @@ -122,4 +125,4 @@ jobs: - name: Cargo test fail if: failure() run: | - echo '`cargo test --workspace` failed' + echo 'cargo test --workspace failed' From af59493d9fa1a05e9f961500e3caa9137c17a10d Mon Sep 17 00:00:00 2001 From: aidan Date: Mon, 13 May 2024 15:09:23 +0200 Subject: [PATCH 27/48] ci: Pin rust toolchain to 1.77 --- .github/workflows/ci.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 18aaf5b0f..c1f2bdcd9 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -52,7 +52,7 @@ jobs: sudo apt-get install protobuf-compiler - uses: dtolnay/rust-toolchain@stable with: - toolchain: nightly + toolchain: 1.77.0 target: wasm32-unknown-unknown components: clippy - name: List version @@ -77,7 +77,7 @@ jobs: sudo apt-get install protobuf-compiler - uses: dtolnay/rust-toolchain@stable with: - toolchain: nightly + toolchain: 1.77.0 target: wasm32-unknown-unknown - name: List version run: cargo --version @@ -116,7 +116,7 @@ jobs: sudo apt-get install protobuf-compiler - uses: dtolnay/rust-toolchain@stable with: - toolchain: nightly + toolchain: 1.77.0 target: wasm32-unknown-unknown - name: List version run: cargo --version From c3a5895902c9cdbeeda44feccd40224d22dfd3a0 Mon Sep 17 00:00:00 2001 From: aidan Date: Mon, 13 May 2024 15:18:13 +0200 Subject: [PATCH 28/48] style: Format toml files --- .rustfmt.toml | 2 +- Cargo.toml | 102 +++++++++++----------- node/Cargo.toml | 46 +++++----- runtime/Cargo.toml | 208 ++++++++++++++++++++++----------------------- 4 files changed, 174 insertions(+), 184 deletions(-) diff --git a/.rustfmt.toml b/.rustfmt.toml index a0347832e..6380de253 100644 --- a/.rustfmt.toml +++ b/.rustfmt.toml @@ -1,3 +1,3 @@ edition = "2021" -imports_granularity = "Crate" group_imports = "StdExternalCrate" +imports_granularity = "Crate" diff --git a/Cargo.toml b/Cargo.toml index 2247fead5..059cacf9e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,35 +1,35 @@ [workspace.package] edition = "2021" -repository = "https://github.com/eigerco/polka-storage" homepage = "https://github.com/eigerco/polka-storage" +repository = "https://github.com/eigerco/polka-storage" [workspace] -resolver = "2" members = ["node", "runtime"] +resolver = "2" [workspace.dependencies] -scale-info = { version = "2.11.1", default-features = false } +clap = { version = "4.5.3" } +codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false } +color-print = "0.3.4" +futures = "0.3.28" +hex-literal = { version = "0.4.1" } +jsonrpsee = { version = "0.22" } +log = { version = "0.4.21", default-features = false } polkavm = "0.9.3" -polkavm-linker = "0.9.2" polkavm-derive = "0.9.1" -log = { version = "0.4.21", default-features = false } +polkavm-linker = "0.9.2" quote = { version = "1.0.33" } +scale-info = { version = "2.11.1", default-features = false } serde = { version = "1.0.197", default-features = false } serde-big-array = { version = "0.3.2" } serde_derive = { version = "1.0.117" } serde_json = { version = "1.0.114", default-features = false } serde_yaml = { version = "0.9" } +smallvec = "1.11.0" syn = { version = "2.0.53" } thiserror = { version = "1.0.48" } tracing-subscriber = { version = "0.3.18" } -jsonrpsee = { version = "0.22" } -clap = { version = "4.5.3" } -futures = "0.3.28" -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false } -hex-literal = { version = "0.4.1" } -smallvec = "1.11.0" -color-print = "0.3.4" # Local polka-storage-runtime = { path = "runtime" } @@ -40,11 +40,11 @@ sc-basic-authorship = { git = "https://github.com/eigerco/polkadot-sdk", rev = " sc-chain-spec = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a" } sc-cli = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a" } sc-client-api = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a" } -sc-offchain = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a" } sc-consensus = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a" } sc-executor = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a" } sc-network = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a" } sc-network-sync = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a" } +sc-offchain = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a" } sc-rpc = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a" } sc-service = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a" } sc-sysinfo = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a" } @@ -57,27 +57,25 @@ sp-block-builder = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4 sp-blockchain = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a" } sp-consensus-aura = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false } sp-core = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false } -sp-keystore = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a" } -sp-io = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a" } -sp-runtime = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false } -sp-timestamp = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a" } -substrate-frame-rpc-system = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a" } -substrate-prometheus-endpoint = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a" } sp-genesis-builder = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false } sp-inherents = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false } +sp-io = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a" } +sp-keystore = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a" } sp-offchain = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false } +sp-runtime = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false } sp-session = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false } sp-std = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false } +sp-timestamp = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a" } sp-transaction-pool = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false } sp-version = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false } +substrate-frame-rpc-system = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a" } +substrate-prometheus-endpoint = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a" } # Polkadot -polkadot-cli = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", features = [ - "rococo-native", -] } -polkadot-primitives = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a" } pallet-xcm = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false } +polkadot-cli = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", features = ["rococo-native"] } polkadot-parachain-primitives = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false } +polkadot-primitives = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a" } polkadot-runtime-common = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false } xcm = { package = "staging-xcm", git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false } xcm-builder = { package = "staging-xcm-builder", git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false } @@ -85,13 +83,13 @@ xcm-executor = { package = "staging-xcm-executor", git = "https://github.com/eig # Substrate / FRAME frame-benchmarking = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false } +frame-benchmarking-cli = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a" } frame-executive = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false } frame-support = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false } frame-system = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false } frame-system-benchmarking = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false } frame-system-rpc-runtime-api = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false } frame-try-runtime = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false } -frame-benchmarking-cli = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a" } # FRAME Pallets pallet-aura = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false } @@ -106,53 +104,53 @@ pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/eigerco # Cumulus -cumulus-pallet-aura-ext = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false } -cumulus-pallet-parachain-system = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false, features = [ - "parameterized-consensus-hook", -] } -cumulus-pallet-session-benchmarking = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false } -cumulus-pallet-xcm = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false } -cumulus-pallet-xcmp-queue = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false } -cumulus-primitives-utility = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false } -cumulus-primitives-storage-weight-reclaim = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false } -pallet-collator-selection = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false } -parachains-common = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false } -parachain-info = { package = "staging-parachain-info", git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false } cumulus-client-cli = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a" } cumulus-client-collator = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a" } cumulus-client-consensus-aura = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a" } cumulus-client-consensus-common = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a" } cumulus-client-consensus-proposer = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a" } cumulus-client-service = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a" } +cumulus-pallet-aura-ext = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false } +cumulus-pallet-parachain-system = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false, features = [ + "parameterized-consensus-hook", +] } +cumulus-pallet-session-benchmarking = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false } +cumulus-pallet-xcm = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false } +cumulus-pallet-xcmp-queue = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false } cumulus-primitives-core = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default_features = false } cumulus-primitives-parachain-inherent = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a" } +cumulus-primitives-storage-weight-reclaim = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false } +cumulus-primitives-utility = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false } cumulus-relay-chain-interface = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a" } +pallet-collator-selection = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false } +parachain-info = { package = "staging-parachain-info", git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false } +parachains-common = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", default-features = false } [workspace.lints.rust] suspicious_double_ref_op = { level = "allow", priority = 2 } [workspace.lints.clippy] all = { level = "allow", priority = 0 } -correctness = { level = "warn", priority = 1 } +bind_instead_of_map = { level = "allow", priority = 2 } # stylistic +borrowed-box = { level = "allow", priority = 2 } # Reasonable to fix this one complexity = { level = "warn", priority = 1 } +correctness = { level = "warn", priority = 1 } +default_constructed_unit_structs = { level = "allow", priority = 2 } # stylistic +derivable_impls = { level = "allow", priority = 2 } # false positives +eq_op = { level = "allow", priority = 2 } # In tests we test equality. +erasing_op = { level = "allow", priority = 2 } # E.g. 0 * DOLLARS +extra-unused-type-parameters = { level = "allow", priority = 2 } # stylistic +identity-op = { level = "allow", priority = 2 } # One case where we do 0 + if-same-then-else = { level = "allow", priority = 2 } -zero-prefixed-literal = { level = "allow", priority = 2 } # 00_1000_000 -type_complexity = { level = "allow", priority = 2 } # raison d'etre +needless-lifetimes = { level = "allow", priority = 2 } # generated code +needless_option_as_deref = { level = "allow", priority = 2 } # false positives nonminimal-bool = { level = "allow", priority = 2 } # maybe -borrowed-box = { level = "allow", priority = 2 } # Reasonable to fix this one +option-map-unit-fn = { level = "allow", priority = 2 } # stylistic +stable_sort_primitive = { level = "allow", priority = 2 } # prefer stable sort too-many-arguments = { level = "allow", priority = 2 } # (Turning this on would lead to) -needless-lifetimes = { level = "allow", priority = 2 } # generated code +type_complexity = { level = "allow", priority = 2 } # raison d'etre +unit_arg = { level = "allow", priority = 2 } # stylistic unnecessary_cast = { level = "allow", priority = 2 } # Types may change -identity-op = { level = "allow", priority = 2 } # One case where we do 0 + useless_conversion = { level = "allow", priority = 2 } # Types may change -unit_arg = { level = "allow", priority = 2 } # stylistic -option-map-unit-fn = { level = "allow", priority = 2 } # stylistic -bind_instead_of_map = { level = "allow", priority = 2 } # stylistic -erasing_op = { level = "allow", priority = 2 } # E.g. 0 * DOLLARS -eq_op = { level = "allow", priority = 2 } # In tests we test equality. while_immutable_condition = { level = "allow", priority = 2 } # false positives -needless_option_as_deref = { level = "allow", priority = 2 } # false positives -derivable_impls = { level = "allow", priority = 2 } # false positives -stable_sort_primitive = { level = "allow", priority = 2 } # prefer stable sort -extra-unused-type-parameters = { level = "allow", priority = 2 } # stylistic -default_constructed_unit_structs = { level = "allow", priority = 2 } # stylistic +zero-prefixed-literal = { level = "allow", priority = 2 } # 00_1000_000 diff --git a/node/Cargo.toml b/node/Cargo.toml index 938bbb3de..3073f2842 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -1,13 +1,13 @@ [package] -name = "polka-storage-node" +build = "build.rs" description = "A parachain node template built with Substrate and Cumulus, part of Polkadot Sdk." -version = "0.0.0" -license = "MIT-0" -homepage.workspace = true -repository.workspace = true edition.workspace = true +homepage.workspace = true +license = "MIT-0" +name = "polka-storage-node" publish = false -build = "build.rs" +repository.workspace = true +version = "0.0.0" [lints] workspace = true @@ -17,11 +17,11 @@ workspace = true [dependencies] clap = { workspace = true, features = ["derive"] } -log = { workspace = true, default-features = true } codec = { workspace = true } -serde = { features = ["derive"], workspace = true, default-features = true } -jsonrpsee = { workspace = true, features = ["server"] } futures = { workspace = true } +jsonrpsee = { workspace = true, features = ["server"] } +log = { workspace = true, default-features = true } +serde = { features = ["derive"], workspace = true, default-features = true } serde_json = { workspace = true, default-features = true } # Local @@ -35,11 +35,11 @@ sc-basic-authorship = { workspace = true } sc-chain-spec = { workspace = true } sc-cli = { workspace = true } sc-client-api = { workspace = true } -sc-offchain = { workspace = true } sc-consensus = { workspace = true } sc-executor = { workspace = true } sc-network = { workspace = true } sc-network-sync = { workspace = true } +sc-offchain = { workspace = true } sc-rpc = { workspace = true } sc-service = { workspace = true } sc-sysinfo = { workspace = true } @@ -52,8 +52,8 @@ sp-block-builder = { workspace = true } sp-blockchain = { workspace = true } sp-consensus-aura = { workspace = true } sp-core = { workspace = true } -sp-keystore = { workspace = true } sp-io = { workspace = true } +sp-keystore = { workspace = true } sp-runtime = { workspace = true } sp-timestamp = { workspace = true } substrate-frame-rpc-system = { workspace = true } @@ -65,6 +65,7 @@ polkadot-primitives = { workspace = true } xcm = { workspace = true, default-features = false } # Cumulus +color-print = "0.3.4" cumulus-client-cli = { workspace = true } cumulus-client-collator = { workspace = true } cumulus-client-consensus-aura = { workspace = true } @@ -74,7 +75,6 @@ cumulus-client-service = { workspace = true } cumulus-primitives-core = { workspace = true } cumulus-primitives-parachain-inherent = { workspace = true } cumulus-relay-chain-interface = { workspace = true } -color-print = "0.3.4" [build-dependencies] substrate-build-script-utils = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a" } @@ -82,17 +82,13 @@ substrate-build-script-utils = { git = "https://github.com/eigerco/polkadot-sdk" [features] default = [] runtime-benchmarks = [ - "cumulus-primitives-core/runtime-benchmarks", - "frame-benchmarking-cli/runtime-benchmarks", - "frame-benchmarking/runtime-benchmarks", - "polka-storage-runtime/runtime-benchmarks", - "polkadot-cli/runtime-benchmarks", - "polkadot-primitives/runtime-benchmarks", - "sc-service/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", -] -try-runtime = [ - "polka-storage-runtime/try-runtime", - "polkadot-cli/try-runtime", - "sp-runtime/try-runtime", + "cumulus-primitives-core/runtime-benchmarks", + "frame-benchmarking-cli/runtime-benchmarks", + "frame-benchmarking/runtime-benchmarks", + "polka-storage-runtime/runtime-benchmarks", + "polkadot-cli/runtime-benchmarks", + "polkadot-primitives/runtime-benchmarks", + "sc-service/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", ] +try-runtime = ["polka-storage-runtime/try-runtime", "polkadot-cli/try-runtime", "sp-runtime/try-runtime"] diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 4a8ce906b..628854493 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -1,12 +1,12 @@ [package] -name = "polka-storage-runtime" description = "A parachain runtime template built with Substrate and Cumulus, part of Polkadot Sdk." -version = "0.0.0" -license = "MIT-0" -homepage.workspace = true -repository.workspace = true edition.workspace = true +homepage.workspace = true +license = "MIT-0" +name = "polka-storage-runtime" publish = false +repository.workspace = true +version = "0.0.0" [lints] workspace = true @@ -18,12 +18,10 @@ targets = ["x86_64-unknown-linux-gnu"] substrate-wasm-builder = { git = "https://github.com/eigerco/polkadot-sdk", rev = "cb4554c95552c0e46734e64e56289c547146b98a", optional = true } [dependencies] -log = { workspace = true } codec = { workspace = true, default-features = false, features = ["derive"] } hex-literal = { workspace = true, optional = true } -scale-info = { workspace = true, default-features = false, features = [ - "derive", -] } +log = { workspace = true } +scale-info = { workspace = true, default-features = false, features = ["derive"] } smallvec = { workspace = true } # Substrate / FRAME @@ -70,118 +68,116 @@ xcm-executor = { workspace = true, default-features = false } # Cumulus cumulus-pallet-aura-ext = { workspace = true, default-features = false } -cumulus-pallet-parachain-system = { workspace = true, default-features = false, features = [ - "parameterized-consensus-hook", -] } +cumulus-pallet-parachain-system = { workspace = true, default-features = false, features = ["parameterized-consensus-hook"] } cumulus-pallet-session-benchmarking = { workspace = true, default-features = false } cumulus-pallet-xcm = { workspace = true, default-features = false } cumulus-pallet-xcmp-queue = { workspace = true, default-features = false } cumulus-primitives-core = { workspace = true, default-features = false } -cumulus-primitives-utility = { workspace = true, default-features = false } cumulus-primitives-storage-weight-reclaim = { workspace = true, default-features = false } +cumulus-primitives-utility = { workspace = true, default-features = false } pallet-collator-selection = { workspace = true, default-features = false } -parachains-common = { workspace = true, default-features = false } parachain-info = { workspace = true, default-features = false } +parachains-common = { workspace = true, default-features = false } [features] default = ["std"] std = [ - "codec/std", - "cumulus-pallet-aura-ext/std", - "cumulus-pallet-parachain-system/std", - "cumulus-pallet-session-benchmarking/std", - "cumulus-pallet-xcm/std", - "cumulus-pallet-xcmp-queue/std", - "cumulus-primitives-core/std", - "cumulus-primitives-storage-weight-reclaim/std", - "cumulus-primitives-utility/std", - "frame-benchmarking?/std", - "frame-executive/std", - "frame-support/std", - "frame-system-benchmarking?/std", - "frame-system-rpc-runtime-api/std", - "frame-system/std", - "frame-try-runtime?/std", - "log/std", - "pallet-aura/std", - "pallet-authorship/std", - "pallet-balances/std", - "pallet-collator-selection/std", - "pallet-message-queue/std", - "pallet-session/std", - "pallet-sudo/std", - "pallet-timestamp/std", - "pallet-transaction-payment-rpc-runtime-api/std", - "pallet-transaction-payment/std", - "pallet-xcm/std", - "parachain-info/std", - "parachains-common/std", - "polkadot-parachain-primitives/std", - "polkadot-runtime-common/std", - "scale-info/std", - "sp-api/std", - "sp-block-builder/std", - "sp-consensus-aura/std", - "sp-core/std", - "sp-genesis-builder/std", - "sp-inherents/std", - "sp-offchain/std", - "sp-runtime/std", - "sp-session/std", - "sp-std/std", - "sp-transaction-pool/std", - "sp-version/std", - "substrate-wasm-builder", - "xcm-builder/std", - "xcm-executor/std", - "xcm/std", + "codec/std", + "cumulus-pallet-aura-ext/std", + "cumulus-pallet-parachain-system/std", + "cumulus-pallet-session-benchmarking/std", + "cumulus-pallet-xcm/std", + "cumulus-pallet-xcmp-queue/std", + "cumulus-primitives-core/std", + "cumulus-primitives-storage-weight-reclaim/std", + "cumulus-primitives-utility/std", + "frame-benchmarking?/std", + "frame-executive/std", + "frame-support/std", + "frame-system-benchmarking?/std", + "frame-system-rpc-runtime-api/std", + "frame-system/std", + "frame-try-runtime?/std", + "log/std", + "pallet-aura/std", + "pallet-authorship/std", + "pallet-balances/std", + "pallet-collator-selection/std", + "pallet-message-queue/std", + "pallet-session/std", + "pallet-sudo/std", + "pallet-timestamp/std", + "pallet-transaction-payment-rpc-runtime-api/std", + "pallet-transaction-payment/std", + "pallet-xcm/std", + "parachain-info/std", + "parachains-common/std", + "polkadot-parachain-primitives/std", + "polkadot-runtime-common/std", + "scale-info/std", + "sp-api/std", + "sp-block-builder/std", + "sp-consensus-aura/std", + "sp-core/std", + "sp-genesis-builder/std", + "sp-inherents/std", + "sp-offchain/std", + "sp-runtime/std", + "sp-session/std", + "sp-std/std", + "sp-transaction-pool/std", + "sp-version/std", + "substrate-wasm-builder", + "xcm-builder/std", + "xcm-executor/std", + "xcm/std", ] runtime-benchmarks = [ - "cumulus-pallet-parachain-system/runtime-benchmarks", - "cumulus-pallet-session-benchmarking/runtime-benchmarks", - "cumulus-pallet-xcmp-queue/runtime-benchmarks", - "cumulus-primitives-core/runtime-benchmarks", - "cumulus-primitives-utility/runtime-benchmarks", - "frame-benchmarking/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system-benchmarking/runtime-benchmarks", - "frame-system/runtime-benchmarks", - "hex-literal", - "pallet-balances/runtime-benchmarks", - "pallet-collator-selection/runtime-benchmarks", - "pallet-message-queue/runtime-benchmarks", - "pallet-sudo/runtime-benchmarks", - "pallet-timestamp/runtime-benchmarks", - "pallet-xcm/runtime-benchmarks", - "parachains-common/runtime-benchmarks", - "polkadot-parachain-primitives/runtime-benchmarks", - "polkadot-runtime-common/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", - "xcm-builder/runtime-benchmarks", - "xcm-executor/runtime-benchmarks", + "cumulus-pallet-parachain-system/runtime-benchmarks", + "cumulus-pallet-session-benchmarking/runtime-benchmarks", + "cumulus-pallet-xcmp-queue/runtime-benchmarks", + "cumulus-primitives-core/runtime-benchmarks", + "cumulus-primitives-utility/runtime-benchmarks", + "frame-benchmarking/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "frame-system-benchmarking/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "hex-literal", + "pallet-balances/runtime-benchmarks", + "pallet-collator-selection/runtime-benchmarks", + "pallet-message-queue/runtime-benchmarks", + "pallet-sudo/runtime-benchmarks", + "pallet-timestamp/runtime-benchmarks", + "pallet-xcm/runtime-benchmarks", + "parachains-common/runtime-benchmarks", + "polkadot-parachain-primitives/runtime-benchmarks", + "polkadot-runtime-common/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", + "xcm-builder/runtime-benchmarks", + "xcm-executor/runtime-benchmarks", ] try-runtime = [ - "cumulus-pallet-aura-ext/try-runtime", - "cumulus-pallet-parachain-system/try-runtime", - "cumulus-pallet-xcm/try-runtime", - "cumulus-pallet-xcmp-queue/try-runtime", - "frame-executive/try-runtime", - "frame-support/try-runtime", - "frame-system/try-runtime", - "frame-try-runtime/try-runtime", - "pallet-aura/try-runtime", - "pallet-authorship/try-runtime", - "pallet-balances/try-runtime", - "pallet-collator-selection/try-runtime", - "pallet-message-queue/try-runtime", - "pallet-session/try-runtime", - "pallet-sudo/try-runtime", - "pallet-timestamp/try-runtime", - "pallet-transaction-payment/try-runtime", - "pallet-xcm/try-runtime", - "parachain-info/try-runtime", - "polkadot-runtime-common/try-runtime", - "sp-runtime/try-runtime", + "cumulus-pallet-aura-ext/try-runtime", + "cumulus-pallet-parachain-system/try-runtime", + "cumulus-pallet-xcm/try-runtime", + "cumulus-pallet-xcmp-queue/try-runtime", + "frame-executive/try-runtime", + "frame-support/try-runtime", + "frame-system/try-runtime", + "frame-try-runtime/try-runtime", + "pallet-aura/try-runtime", + "pallet-authorship/try-runtime", + "pallet-balances/try-runtime", + "pallet-collator-selection/try-runtime", + "pallet-message-queue/try-runtime", + "pallet-session/try-runtime", + "pallet-sudo/try-runtime", + "pallet-timestamp/try-runtime", + "pallet-transaction-payment/try-runtime", + "pallet-xcm/try-runtime", + "parachain-info/try-runtime", + "polkadot-runtime-common/try-runtime", + "sp-runtime/try-runtime", ] From 86ba23b27f0485d41de715d9c0fc951a67ab82d4 Mon Sep 17 00:00:00 2001 From: aidan Date: Mon, 13 May 2024 15:26:41 +0200 Subject: [PATCH 29/48] style: Format `.rs` files --- node/build.rs | 4 +- node/src/command.rs | 666 +++++++++++----------- node/src/main.rs | 2 +- node/src/rpc.rs | 1 - node/src/service.rs | 690 ++++++++++++----------- runtime/build.rs | 2 +- runtime/src/apis.rs | 472 ++++++++-------- runtime/src/benchmarks.rs | 18 +- runtime/src/configs/mod.rs | 2 +- runtime/src/configs/xcm_config.rs | 279 ++++----- runtime/src/lib.rs | 30 +- runtime/src/weights/block_weights.rs | 60 +- runtime/src/weights/extrinsic_weights.rs | 60 +- runtime/src/weights/paritydb_weights.rs | 83 +-- runtime/src/weights/rocksdb_weights.rs | 83 +-- 15 files changed, 1245 insertions(+), 1207 deletions(-) diff --git a/node/build.rs b/node/build.rs index e3bfe3116..f9d839f9b 100644 --- a/node/build.rs +++ b/node/build.rs @@ -1,7 +1,7 @@ use substrate_build_script_utils::{generate_cargo_keys, rerun_if_git_head_changed}; fn main() { - generate_cargo_keys(); + generate_cargo_keys(); - rerun_if_git_head_changed(); + rerun_if_git_head_changed(); } diff --git a/node/src/command.rs b/node/src/command.rs index 45ab7f5ad..0fc7b754e 100644 --- a/node/src/command.rs +++ b/node/src/command.rs @@ -6,96 +6,98 @@ use frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE}; use log::info; use polka_storage_runtime::Block; use sc_cli::{ - ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams, - NetworkParams, Result, SharedParams, SubstrateCli, + ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams, + NetworkParams, Result, SharedParams, SubstrateCli, }; use sc_service::config::{BasePath, PrometheusConfig}; use crate::{ - chain_spec, - cli::{Cli, RelayChainCli, Subcommand}, - service::new_partial, + chain_spec, + cli::{Cli, RelayChainCli, Subcommand}, + service::new_partial, }; fn load_spec(id: &str) -> std::result::Result, String> { - Ok(match id { - "dev" => Box::new(chain_spec::development_config()), - "template-rococo" => Box::new(chain_spec::local_testnet_config()), - "" | "local" => Box::new(chain_spec::local_testnet_config()), - path => Box::new(chain_spec::ChainSpec::from_json_file(std::path::PathBuf::from(path))?), - }) + Ok(match id { + "dev" => Box::new(chain_spec::development_config()), + "template-rococo" => Box::new(chain_spec::local_testnet_config()), + "" | "local" => Box::new(chain_spec::local_testnet_config()), + path => Box::new(chain_spec::ChainSpec::from_json_file( + std::path::PathBuf::from(path), + )?), + }) } impl SubstrateCli for Cli { - fn impl_name() -> String { - "Parachain Collator Template".into() - } + fn impl_name() -> String { + "Parachain Collator Template".into() + } - fn impl_version() -> String { - env!("SUBSTRATE_CLI_IMPL_VERSION").into() - } + fn impl_version() -> String { + env!("SUBSTRATE_CLI_IMPL_VERSION").into() + } - fn description() -> String { - format!( - "Parachain Collator Template\n\nThe command-line arguments provided first will be \ + fn description() -> String { + format!( + "Parachain Collator Template\n\nThe command-line arguments provided first will be \ passed to the parachain node, while the arguments provided after -- will be passed \ to the relay chain node.\n\n\ {} -- ", - Self::executable_name() - ) - } + Self::executable_name() + ) + } - fn author() -> String { - env!("CARGO_PKG_AUTHORS").into() - } + fn author() -> String { + env!("CARGO_PKG_AUTHORS").into() + } - fn support_url() -> String { - "https://github.com/paritytech/polkadot-sdk/issues/new".into() - } + fn support_url() -> String { + "https://github.com/paritytech/polkadot-sdk/issues/new".into() + } - fn copyright_start_year() -> i32 { - 2020 - } + fn copyright_start_year() -> i32 { + 2020 + } - fn load_spec(&self, id: &str) -> std::result::Result, String> { - load_spec(id) - } + fn load_spec(&self, id: &str) -> std::result::Result, String> { + load_spec(id) + } } impl SubstrateCli for RelayChainCli { - fn impl_name() -> String { - "Parachain Collator Template".into() - } + fn impl_name() -> String { + "Parachain Collator Template".into() + } - fn impl_version() -> String { - env!("SUBSTRATE_CLI_IMPL_VERSION").into() - } + fn impl_version() -> String { + env!("SUBSTRATE_CLI_IMPL_VERSION").into() + } - fn description() -> String { - format!( - "Parachain Collator Template\n\nThe command-line arguments provided first will be \ + fn description() -> String { + format!( + "Parachain Collator Template\n\nThe command-line arguments provided first will be \ passed to the parachain node, while the arguments provided after -- will be passed \ to the relay chain node.\n\n\ {} -- ", - Self::executable_name() - ) - } + Self::executable_name() + ) + } - fn author() -> String { - env!("CARGO_PKG_AUTHORS").into() - } + fn author() -> String { + env!("CARGO_PKG_AUTHORS").into() + } - fn support_url() -> String { - "https://github.com/paritytech/polkadot-sdk/issues/new".into() - } + fn support_url() -> String { + "https://github.com/paritytech/polkadot-sdk/issues/new".into() + } - fn copyright_start_year() -> i32 { - 2020 - } + fn copyright_start_year() -> i32 { + 2020 + } - fn load_spec(&self, id: &str) -> std::result::Result, String> { - polkadot_cli::Cli::from_iter([RelayChainCli::executable_name()].iter()).load_spec(id) - } + fn load_spec(&self, id: &str) -> std::result::Result, String> { + polkadot_cli::Cli::from_iter([RelayChainCli::executable_name()].iter()).load_spec(id) + } } macro_rules! construct_async_run { @@ -111,277 +113,297 @@ macro_rules! construct_async_run { /// Parse command line arguments into service configuration. pub fn run() -> Result<()> { - let cli = Cli::from_args(); - - match &cli.subcommand { - Some(Subcommand::BuildSpec(cmd)) => { - let runner = cli.create_runner(cmd)?; - runner.sync_run(|config| cmd.run(config.chain_spec, config.network)) - }, - Some(Subcommand::CheckBlock(cmd)) => { - construct_async_run!(|components, cli, cmd, config| { - Ok(cmd.run(components.client, components.import_queue)) - }) - }, - Some(Subcommand::ExportBlocks(cmd)) => { - construct_async_run!(|components, cli, cmd, config| { - Ok(cmd.run(components.client, config.database)) - }) - }, - Some(Subcommand::ExportState(cmd)) => { - construct_async_run!(|components, cli, cmd, config| { - Ok(cmd.run(components.client, config.chain_spec)) - }) - }, - Some(Subcommand::ImportBlocks(cmd)) => { - construct_async_run!(|components, cli, cmd, config| { - Ok(cmd.run(components.client, components.import_queue)) - }) - }, - Some(Subcommand::Revert(cmd)) => { - construct_async_run!(|components, cli, cmd, config| { - Ok(cmd.run(components.client, components.backend, None)) - }) - }, - Some(Subcommand::PurgeChain(cmd)) => { - let runner = cli.create_runner(cmd)?; - - runner.sync_run(|config| { - let polkadot_cli = RelayChainCli::new( - &config, - [RelayChainCli::executable_name()].iter().chain(cli.relay_chain_args.iter()), - ); - - let polkadot_config = SubstrateCli::create_configuration( - &polkadot_cli, - &polkadot_cli, - config.tokio_handle.clone(), - ) - .map_err(|err| format!("Relay chain argument error: {}", err))?; - - cmd.run(config, polkadot_config) - }) - }, - Some(Subcommand::ExportGenesisHead(cmd)) => { - let runner = cli.create_runner(cmd)?; - runner.sync_run(|config| { - let partials = new_partial(&config)?; - - cmd.run(partials.client) - }) - }, - Some(Subcommand::ExportGenesisWasm(cmd)) => { - let runner = cli.create_runner(cmd)?; - runner.sync_run(|_config| { - let spec = cli.load_spec(&cmd.shared_params.chain.clone().unwrap_or_default())?; - cmd.run(&*spec) - }) - }, - Some(Subcommand::Benchmark(cmd)) => { - let runner = cli.create_runner(cmd)?; - // Switch on the concrete benchmark sub-command- - match cmd { - BenchmarkCmd::Pallet(cmd) => - if cfg!(feature = "runtime-benchmarks") { - runner.sync_run(|config| cmd.run_with_spec::, ReclaimHostFunctions>(Some(config.chain_spec))) - } else { - Err("Benchmarking wasn't enabled when building the node. \ + let cli = Cli::from_args(); + + match &cli.subcommand { + Some(Subcommand::BuildSpec(cmd)) => { + let runner = cli.create_runner(cmd)?; + runner.sync_run(|config| cmd.run(config.chain_spec, config.network)) + } + Some(Subcommand::CheckBlock(cmd)) => { + construct_async_run!(|components, cli, cmd, config| { + Ok(cmd.run(components.client, components.import_queue)) + }) + } + Some(Subcommand::ExportBlocks(cmd)) => { + construct_async_run!(|components, cli, cmd, config| { + Ok(cmd.run(components.client, config.database)) + }) + } + Some(Subcommand::ExportState(cmd)) => { + construct_async_run!(|components, cli, cmd, config| { + Ok(cmd.run(components.client, config.chain_spec)) + }) + } + Some(Subcommand::ImportBlocks(cmd)) => { + construct_async_run!(|components, cli, cmd, config| { + Ok(cmd.run(components.client, components.import_queue)) + }) + } + Some(Subcommand::Revert(cmd)) => { + construct_async_run!(|components, cli, cmd, config| { + Ok(cmd.run(components.client, components.backend, None)) + }) + } + Some(Subcommand::PurgeChain(cmd)) => { + let runner = cli.create_runner(cmd)?; + + runner.sync_run(|config| { + let polkadot_cli = RelayChainCli::new( + &config, + [RelayChainCli::executable_name()] + .iter() + .chain(cli.relay_chain_args.iter()), + ); + + let polkadot_config = SubstrateCli::create_configuration( + &polkadot_cli, + &polkadot_cli, + config.tokio_handle.clone(), + ) + .map_err(|err| format!("Relay chain argument error: {}", err))?; + + cmd.run(config, polkadot_config) + }) + } + Some(Subcommand::ExportGenesisHead(cmd)) => { + let runner = cli.create_runner(cmd)?; + runner.sync_run(|config| { + let partials = new_partial(&config)?; + + cmd.run(partials.client) + }) + } + Some(Subcommand::ExportGenesisWasm(cmd)) => { + let runner = cli.create_runner(cmd)?; + runner.sync_run(|_config| { + let spec = cli.load_spec(&cmd.shared_params.chain.clone().unwrap_or_default())?; + cmd.run(&*spec) + }) + } + Some(Subcommand::Benchmark(cmd)) => { + let runner = cli.create_runner(cmd)?; + // Switch on the concrete benchmark sub-command- + match cmd { + BenchmarkCmd::Pallet(cmd) => { + if cfg!(feature = "runtime-benchmarks") { + runner.sync_run(|config| cmd.run_with_spec::, ReclaimHostFunctions>(Some(config.chain_spec))) + } else { + Err("Benchmarking wasn't enabled when building the node. \ You can enable it with `--features runtime-benchmarks`." - .into()) - }, - BenchmarkCmd::Block(cmd) => runner.sync_run(|config| { - let partials = new_partial(&config)?; - cmd.run(partials.client) - }), - #[cfg(not(feature = "runtime-benchmarks"))] - BenchmarkCmd::Storage(_) => - return Err(sc_cli::Error::Input( - "Compile with --features=runtime-benchmarks \ + .into()) + } + } + BenchmarkCmd::Block(cmd) => runner.sync_run(|config| { + let partials = new_partial(&config)?; + cmd.run(partials.client) + }), + #[cfg(not(feature = "runtime-benchmarks"))] + BenchmarkCmd::Storage(_) => { + return Err(sc_cli::Error::Input( + "Compile with --features=runtime-benchmarks \ to enable storage benchmarks." - .into(), - ) - .into()), - #[cfg(feature = "runtime-benchmarks")] - BenchmarkCmd::Storage(cmd) => runner.sync_run(|config| { - let partials = new_partial(&config)?; - let db = partials.backend.expose_db(); - let storage = partials.backend.expose_storage(); - cmd.run(config, partials.client.clone(), db, storage) - }), - BenchmarkCmd::Machine(cmd) => - runner.sync_run(|config| cmd.run(&config, SUBSTRATE_REFERENCE_HARDWARE.clone())), - // NOTE: this allows the Client to leniently implement - // new benchmark commands without requiring a companion MR. - #[allow(unreachable_patterns)] - _ => Err("Benchmarking sub-command unsupported".into()), - } - }, - None => { - let runner = cli.create_runner(&cli.run.normalize())?; - let collator_options = cli.run.collator_options(); - - runner.run_node_until_exit(|config| async move { - let hwbench = (!cli.no_hardware_benchmarks) - .then_some(config.database.path().map(|database_path| { - let _ = std::fs::create_dir_all(database_path); - sc_sysinfo::gather_hwbench(Some(database_path)) - })) - .flatten(); - - let para_id = chain_spec::Extensions::try_get(&*config.chain_spec) - .map(|e| e.para_id) - .ok_or("Could not find parachain ID in chain-spec.")?; - - let polkadot_cli = RelayChainCli::new( - &config, - [RelayChainCli::executable_name()].iter().chain(cli.relay_chain_args.iter()), - ); - - let id = ParaId::from(para_id); - - let tokio_handle = config.tokio_handle.clone(); - let polkadot_config = - SubstrateCli::create_configuration(&polkadot_cli, &polkadot_cli, tokio_handle) - .map_err(|err| format!("Relay chain argument error: {}", err))?; - - info!("Is collating: {}", if config.role.is_authority() { "yes" } else { "no" }); - - crate::service::start_parachain_node( - config, - polkadot_config, - collator_options, - id, - hwbench, - ) - .await - .map(|r| r.0) - .map_err(Into::into) - }) - }, - } + .into(), + ) + .into()) + } + #[cfg(feature = "runtime-benchmarks")] + BenchmarkCmd::Storage(cmd) => runner.sync_run(|config| { + let partials = new_partial(&config)?; + let db = partials.backend.expose_db(); + let storage = partials.backend.expose_storage(); + cmd.run(config, partials.client.clone(), db, storage) + }), + BenchmarkCmd::Machine(cmd) => { + runner.sync_run(|config| cmd.run(&config, SUBSTRATE_REFERENCE_HARDWARE.clone())) + } + // NOTE: this allows the Client to leniently implement + // new benchmark commands without requiring a companion MR. + #[allow(unreachable_patterns)] + _ => Err("Benchmarking sub-command unsupported".into()), + } + } + None => { + let runner = cli.create_runner(&cli.run.normalize())?; + let collator_options = cli.run.collator_options(); + + runner.run_node_until_exit(|config| async move { + let hwbench = (!cli.no_hardware_benchmarks) + .then_some(config.database.path().map(|database_path| { + let _ = std::fs::create_dir_all(database_path); + sc_sysinfo::gather_hwbench(Some(database_path)) + })) + .flatten(); + + let para_id = chain_spec::Extensions::try_get(&*config.chain_spec) + .map(|e| e.para_id) + .ok_or("Could not find parachain ID in chain-spec.")?; + + let polkadot_cli = RelayChainCli::new( + &config, + [RelayChainCli::executable_name()] + .iter() + .chain(cli.relay_chain_args.iter()), + ); + + let id = ParaId::from(para_id); + + let tokio_handle = config.tokio_handle.clone(); + let polkadot_config = + SubstrateCli::create_configuration(&polkadot_cli, &polkadot_cli, tokio_handle) + .map_err(|err| format!("Relay chain argument error: {}", err))?; + + info!( + "Is collating: {}", + if config.role.is_authority() { + "yes" + } else { + "no" + } + ); + + crate::service::start_parachain_node( + config, + polkadot_config, + collator_options, + id, + hwbench, + ) + .await + .map(|r| r.0) + .map_err(Into::into) + }) + } + } } impl DefaultConfigurationValues for RelayChainCli { - fn p2p_listen_port() -> u16 { - 30334 - } + fn p2p_listen_port() -> u16 { + 30334 + } - fn rpc_listen_port() -> u16 { - 9945 - } + fn rpc_listen_port() -> u16 { + 9945 + } - fn prometheus_listen_port() -> u16 { - 9616 - } + fn prometheus_listen_port() -> u16 { + 9616 + } } impl CliConfiguration for RelayChainCli { - fn shared_params(&self) -> &SharedParams { - self.base.base.shared_params() - } - - fn import_params(&self) -> Option<&ImportParams> { - self.base.base.import_params() - } - - fn network_params(&self) -> Option<&NetworkParams> { - self.base.base.network_params() - } - - fn keystore_params(&self) -> Option<&KeystoreParams> { - self.base.base.keystore_params() - } - - fn base_path(&self) -> Result> { - Ok(self - .shared_params() - .base_path()? - .or_else(|| self.base_path.clone().map(Into::into))) - } - - fn rpc_addr(&self, default_listen_port: u16) -> Result> { - self.base.base.rpc_addr(default_listen_port) - } - - fn prometheus_config( - &self, - default_listen_port: u16, - chain_spec: &Box, - ) -> Result> { - self.base.base.prometheus_config(default_listen_port, chain_spec) - } - - fn init( - &self, - _support_url: &String, - _impl_version: &String, - _logger_hook: F, - _config: &sc_service::Configuration, - ) -> Result<()> - where - F: FnOnce(&mut sc_cli::LoggerBuilder, &sc_service::Configuration), - { - unreachable!("PolkadotCli is never initialized; qed"); - } - - fn chain_id(&self, is_dev: bool) -> Result { - let chain_id = self.base.base.chain_id(is_dev)?; - - Ok(if chain_id.is_empty() { self.chain_id.clone().unwrap_or_default() } else { chain_id }) - } - - fn role(&self, is_dev: bool) -> Result { - self.base.base.role(is_dev) - } - - fn transaction_pool(&self, is_dev: bool) -> Result { - self.base.base.transaction_pool(is_dev) - } - - fn trie_cache_maximum_size(&self) -> Result> { - self.base.base.trie_cache_maximum_size() - } - - fn rpc_methods(&self) -> Result { - self.base.base.rpc_methods() - } - - fn rpc_max_connections(&self) -> Result { - self.base.base.rpc_max_connections() - } - - fn rpc_cors(&self, is_dev: bool) -> Result>> { - self.base.base.rpc_cors(is_dev) - } - - fn default_heap_pages(&self) -> Result> { - self.base.base.default_heap_pages() - } - - fn force_authoring(&self) -> Result { - self.base.base.force_authoring() - } - - fn disable_grandpa(&self) -> Result { - self.base.base.disable_grandpa() - } - - fn max_runtime_instances(&self) -> Result> { - self.base.base.max_runtime_instances() - } - - fn announce_block(&self) -> Result { - self.base.base.announce_block() - } - - fn telemetry_endpoints( - &self, - chain_spec: &Box, - ) -> Result> { - self.base.base.telemetry_endpoints(chain_spec) - } - - fn node_name(&self) -> Result { - self.base.base.node_name() - } + fn shared_params(&self) -> &SharedParams { + self.base.base.shared_params() + } + + fn import_params(&self) -> Option<&ImportParams> { + self.base.base.import_params() + } + + fn network_params(&self) -> Option<&NetworkParams> { + self.base.base.network_params() + } + + fn keystore_params(&self) -> Option<&KeystoreParams> { + self.base.base.keystore_params() + } + + fn base_path(&self) -> Result> { + Ok(self + .shared_params() + .base_path()? + .or_else(|| self.base_path.clone().map(Into::into))) + } + + fn rpc_addr(&self, default_listen_port: u16) -> Result> { + self.base.base.rpc_addr(default_listen_port) + } + + fn prometheus_config( + &self, + default_listen_port: u16, + chain_spec: &Box, + ) -> Result> { + self.base + .base + .prometheus_config(default_listen_port, chain_spec) + } + + fn init( + &self, + _support_url: &String, + _impl_version: &String, + _logger_hook: F, + _config: &sc_service::Configuration, + ) -> Result<()> + where + F: FnOnce(&mut sc_cli::LoggerBuilder, &sc_service::Configuration), + { + unreachable!("PolkadotCli is never initialized; qed"); + } + + fn chain_id(&self, is_dev: bool) -> Result { + let chain_id = self.base.base.chain_id(is_dev)?; + + Ok(if chain_id.is_empty() { + self.chain_id.clone().unwrap_or_default() + } else { + chain_id + }) + } + + fn role(&self, is_dev: bool) -> Result { + self.base.base.role(is_dev) + } + + fn transaction_pool(&self, is_dev: bool) -> Result { + self.base.base.transaction_pool(is_dev) + } + + fn trie_cache_maximum_size(&self) -> Result> { + self.base.base.trie_cache_maximum_size() + } + + fn rpc_methods(&self) -> Result { + self.base.base.rpc_methods() + } + + fn rpc_max_connections(&self) -> Result { + self.base.base.rpc_max_connections() + } + + fn rpc_cors(&self, is_dev: bool) -> Result>> { + self.base.base.rpc_cors(is_dev) + } + + fn default_heap_pages(&self) -> Result> { + self.base.base.default_heap_pages() + } + + fn force_authoring(&self) -> Result { + self.base.base.force_authoring() + } + + fn disable_grandpa(&self) -> Result { + self.base.base.disable_grandpa() + } + + fn max_runtime_instances(&self) -> Result> { + self.base.base.max_runtime_instances() + } + + fn announce_block(&self) -> Result { + self.base.base.announce_block() + } + + fn telemetry_endpoints( + &self, + chain_spec: &Box, + ) -> Result> { + self.base.base.telemetry_endpoints(chain_spec) + } + + fn node_name(&self) -> Result { + self.base.base.node_name() + } } diff --git a/node/src/main.rs b/node/src/main.rs index 12738a679..60e49b7b0 100644 --- a/node/src/main.rs +++ b/node/src/main.rs @@ -9,5 +9,5 @@ mod rpc; mod service; fn main() -> sc_cli::Result<()> { - command::run() + command::run() } diff --git a/node/src/rpc.rs b/node/src/rpc.rs index 6766c62e5..7c5caa6dd 100644 --- a/node/src/rpc.rs +++ b/node/src/rpc.rs @@ -8,7 +8,6 @@ use std::sync::Arc; use polka_storage_runtime::{opaque::Block, AccountId, Balance, Nonce}; - pub use sc_rpc::DenyUnsafe; use sc_transaction_pool_api::TransactionPool; use sp_api::ProvideRuntimeApi; diff --git a/node/src/service.rs b/node/src/service.rs index 3e37b9b62..f72b5057e 100644 --- a/node/src/service.rs +++ b/node/src/service.rs @@ -4,26 +4,24 @@ use std::{sync::Arc, time::Duration}; use cumulus_client_cli::CollatorOptions; -// Local Runtime Types -use polka_storage_runtime::{ - apis::RuntimeApi, - opaque::{Block, Hash}, -}; - // Cumulus Imports use cumulus_client_collator::service::CollatorService; use cumulus_client_consensus_common::ParachainBlockImport as TParachainBlockImport; use cumulus_client_consensus_proposer::Proposer; use cumulus_client_service::{ - build_network, build_relay_chain_interface, prepare_node_config, start_relay_chain_tasks, - BuildNetworkParams, CollatorSybilResistance, DARecoveryProfile, ParachainHostFunctions, - StartRelayChainTasksParams, + build_network, build_relay_chain_interface, prepare_node_config, start_relay_chain_tasks, + BuildNetworkParams, CollatorSybilResistance, DARecoveryProfile, ParachainHostFunctions, + StartRelayChainTasksParams, }; use cumulus_primitives_core::{relay_chain::CollatorPair, ParaId}; use cumulus_relay_chain_interface::{OverseerHandle, RelayChainInterface}; - // Substrate Imports use frame_benchmarking_cli::SUBSTRATE_REFERENCE_HARDWARE; +// Local Runtime Types +use polka_storage_runtime::{ + apis::RuntimeApi, + opaque::{Block, Hash}, +}; use sc_client_api::Backend; use sc_consensus::ImportQueue; use sc_executor::{HeapAllocStrategy, WasmExecutor, DEFAULT_HEAP_ALLOC_STRATEGY}; @@ -45,12 +43,16 @@ type ParachainBlockImport = TParachainBlockImport, P /// Assembly of PartialComponents (enough to run chain ops subcommands) pub type Service = PartialComponents< - ParachainClient, - ParachainBackend, - (), - sc_consensus::DefaultImportQueue, - sc_transaction_pool::FullPool, - (ParachainBlockImport, Option, Option), + ParachainClient, + ParachainBackend, + (), + sc_consensus::DefaultImportQueue, + sc_transaction_pool::FullPool, + ( + ParachainBlockImport, + Option, + Option, + ), >; /// Starts a `ServiceBuilder` for a full service. @@ -58,347 +60,353 @@ pub type Service = PartialComponents< /// Use this macro if you don't actually need the full service, but just the builder in order to /// be able to perform chain operations. pub fn new_partial(config: &Configuration) -> Result { - let telemetry = config - .telemetry_endpoints - .clone() - .filter(|x| !x.is_empty()) - .map(|endpoints| -> Result<_, sc_telemetry::Error> { - let worker = TelemetryWorker::new(16)?; - let telemetry = worker.handle().new_telemetry(endpoints); - Ok((worker, telemetry)) - }) - .transpose()?; - - let heap_pages = config - .default_heap_pages - .map_or(DEFAULT_HEAP_ALLOC_STRATEGY, |h| HeapAllocStrategy::Static { extra_pages: h as _ }); - - let executor = ParachainExecutor::builder() - .with_execution_method(config.wasm_method) - .with_onchain_heap_alloc_strategy(heap_pages) - .with_offchain_heap_alloc_strategy(heap_pages) - .with_max_runtime_instances(config.max_runtime_instances) - .with_runtime_cache_size(config.runtime_cache_size) - .build(); - - let (client, backend, keystore_container, task_manager) = - sc_service::new_full_parts_record_import::( - config, - telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()), - executor, - true, - )?; - let client = Arc::new(client); - - let telemetry_worker_handle = telemetry.as_ref().map(|(worker, _)| worker.handle()); - - let telemetry = telemetry.map(|(worker, telemetry)| { - task_manager.spawn_handle().spawn("telemetry", None, worker.run()); - telemetry - }); - - let transaction_pool = sc_transaction_pool::BasicPool::new_full( - config.transaction_pool.clone(), - config.role.is_authority().into(), - config.prometheus_registry(), - task_manager.spawn_essential_handle(), - client.clone(), - ); - - let block_import = ParachainBlockImport::new(client.clone(), backend.clone()); - - let import_queue = build_import_queue( - client.clone(), - block_import.clone(), - config, - telemetry.as_ref().map(|telemetry| telemetry.handle()), - &task_manager, - ); - - Ok(PartialComponents { - backend, - client, - import_queue, - keystore_container, - task_manager, - transaction_pool, - select_chain: (), - other: (block_import, telemetry, telemetry_worker_handle), - }) + let telemetry = config + .telemetry_endpoints + .clone() + .filter(|x| !x.is_empty()) + .map(|endpoints| -> Result<_, sc_telemetry::Error> { + let worker = TelemetryWorker::new(16)?; + let telemetry = worker.handle().new_telemetry(endpoints); + Ok((worker, telemetry)) + }) + .transpose()?; + + let heap_pages = config + .default_heap_pages + .map_or(DEFAULT_HEAP_ALLOC_STRATEGY, |h| HeapAllocStrategy::Static { + extra_pages: h as _, + }); + + let executor = ParachainExecutor::builder() + .with_execution_method(config.wasm_method) + .with_onchain_heap_alloc_strategy(heap_pages) + .with_offchain_heap_alloc_strategy(heap_pages) + .with_max_runtime_instances(config.max_runtime_instances) + .with_runtime_cache_size(config.runtime_cache_size) + .build(); + + let (client, backend, keystore_container, task_manager) = + sc_service::new_full_parts_record_import::( + config, + telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()), + executor, + true, + )?; + let client = Arc::new(client); + + let telemetry_worker_handle = telemetry.as_ref().map(|(worker, _)| worker.handle()); + + let telemetry = telemetry.map(|(worker, telemetry)| { + task_manager + .spawn_handle() + .spawn("telemetry", None, worker.run()); + telemetry + }); + + let transaction_pool = sc_transaction_pool::BasicPool::new_full( + config.transaction_pool.clone(), + config.role.is_authority().into(), + config.prometheus_registry(), + task_manager.spawn_essential_handle(), + client.clone(), + ); + + let block_import = ParachainBlockImport::new(client.clone(), backend.clone()); + + let import_queue = build_import_queue( + client.clone(), + block_import.clone(), + config, + telemetry.as_ref().map(|telemetry| telemetry.handle()), + &task_manager, + ); + + Ok(PartialComponents { + backend, + client, + import_queue, + keystore_container, + task_manager, + transaction_pool, + select_chain: (), + other: (block_import, telemetry, telemetry_worker_handle), + }) } /// Build the import queue for the parachain runtime. fn build_import_queue( - client: Arc, - block_import: ParachainBlockImport, - config: &Configuration, - telemetry: Option, - task_manager: &TaskManager, + client: Arc, + block_import: ParachainBlockImport, + config: &Configuration, + telemetry: Option, + task_manager: &TaskManager, ) -> sc_consensus::DefaultImportQueue { - cumulus_client_consensus_aura::equivocation_import_queue::fully_verifying_import_queue::< - sp_consensus_aura::sr25519::AuthorityPair, - _, - _, - _, - _, - >( - client, - block_import, - move |_, _| async move { - let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); - Ok(timestamp) - }, - &task_manager.spawn_essential_handle(), - config.prometheus_registry(), - telemetry, - ) + cumulus_client_consensus_aura::equivocation_import_queue::fully_verifying_import_queue::< + sp_consensus_aura::sr25519::AuthorityPair, + _, + _, + _, + _, + >( + client, + block_import, + move |_, _| async move { + let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); + Ok(timestamp) + }, + &task_manager.spawn_essential_handle(), + config.prometheus_registry(), + telemetry, + ) } fn start_consensus( - client: Arc, - block_import: ParachainBlockImport, - prometheus_registry: Option<&Registry>, - telemetry: Option, - task_manager: &TaskManager, - relay_chain_interface: Arc, - transaction_pool: Arc>, - sync_oracle: Arc>, - keystore: KeystorePtr, - relay_chain_slot_duration: Duration, - para_id: ParaId, - collator_key: CollatorPair, - overseer_handle: OverseerHandle, - announce_block: Arc>) + Send + Sync>, + client: Arc, + block_import: ParachainBlockImport, + prometheus_registry: Option<&Registry>, + telemetry: Option, + task_manager: &TaskManager, + relay_chain_interface: Arc, + transaction_pool: Arc>, + sync_oracle: Arc>, + keystore: KeystorePtr, + relay_chain_slot_duration: Duration, + para_id: ParaId, + collator_key: CollatorPair, + overseer_handle: OverseerHandle, + announce_block: Arc>) + Send + Sync>, ) -> Result<(), sc_service::Error> { - use cumulus_client_consensus_aura::collators::basic::{ - self as basic_aura, Params as BasicAuraParams, - }; - - let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording( - task_manager.spawn_handle(), - client.clone(), - transaction_pool, - prometheus_registry, - telemetry.clone(), - ); - - let proposer = Proposer::new(proposer_factory); - - let collator_service = CollatorService::new( - client.clone(), - Arc::new(task_manager.spawn_handle()), - announce_block, - client.clone(), - ); - - let params = BasicAuraParams { - create_inherent_data_providers: move |_, ()| async move { Ok(()) }, - block_import, - para_client: client, - relay_client: relay_chain_interface, - sync_oracle, - keystore, - collator_key, - para_id, - overseer_handle, - relay_chain_slot_duration, - proposer, - collator_service, - // Very limited proposal time. - authoring_duration: Duration::from_millis(500), - collation_request_receiver: None, - }; - - let fut = - basic_aura::run::( - params, - ); - task_manager.spawn_essential_handle().spawn("aura", None, fut); - - Ok(()) + use cumulus_client_consensus_aura::collators::basic::{ + self as basic_aura, Params as BasicAuraParams, + }; + + let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording( + task_manager.spawn_handle(), + client.clone(), + transaction_pool, + prometheus_registry, + telemetry.clone(), + ); + + let proposer = Proposer::new(proposer_factory); + + let collator_service = CollatorService::new( + client.clone(), + Arc::new(task_manager.spawn_handle()), + announce_block, + client.clone(), + ); + + let params = BasicAuraParams { + create_inherent_data_providers: move |_, ()| async move { Ok(()) }, + block_import, + para_client: client, + relay_client: relay_chain_interface, + sync_oracle, + keystore, + collator_key, + para_id, + overseer_handle, + relay_chain_slot_duration, + proposer, + collator_service, + // Very limited proposal time. + authoring_duration: Duration::from_millis(500), + collation_request_receiver: None, + }; + + let fut = + basic_aura::run::( + params, + ); + task_manager + .spawn_essential_handle() + .spawn("aura", None, fut); + + Ok(()) } /// Start a node with the given parachain `Configuration` and relay chain `Configuration`. #[sc_tracing::logging::prefix_logs_with("Parachain")] pub async fn start_parachain_node( - parachain_config: Configuration, - polkadot_config: Configuration, - collator_options: CollatorOptions, - para_id: ParaId, - hwbench: Option, + parachain_config: Configuration, + polkadot_config: Configuration, + collator_options: CollatorOptions, + para_id: ParaId, + hwbench: Option, ) -> sc_service::error::Result<(TaskManager, Arc)> { - let parachain_config = prepare_node_config(parachain_config); - - let params = new_partial(¶chain_config)?; - let (block_import, mut telemetry, telemetry_worker_handle) = params.other; - let net_config = sc_network::config::FullNetworkConfiguration::< - _, - _, - sc_network::NetworkWorker, - >::new(¶chain_config.network); - - let client = params.client.clone(); - let backend = params.backend.clone(); - let mut task_manager = params.task_manager; - - let (relay_chain_interface, collator_key) = build_relay_chain_interface( - polkadot_config, - ¶chain_config, - telemetry_worker_handle, - &mut task_manager, - collator_options.clone(), - hwbench.clone(), - ) - .await - .map_err(|e| sc_service::Error::Application(Box::new(e) as Box<_>))?; - - let validator = parachain_config.role.is_authority(); - let prometheus_registry = parachain_config.prometheus_registry().cloned(); - let transaction_pool = params.transaction_pool.clone(); - let import_queue_service = params.import_queue.service(); - - // NOTE: because we use Aura here explicitly, we can use `CollatorSybilResistance::Resistant` - // when starting the network. - let (network, system_rpc_tx, tx_handler_controller, start_network, sync_service) = - build_network(BuildNetworkParams { - parachain_config: ¶chain_config, - net_config, - client: client.clone(), - transaction_pool: transaction_pool.clone(), - para_id, - spawn_handle: task_manager.spawn_handle(), - relay_chain_interface: relay_chain_interface.clone(), - import_queue: params.import_queue, - sybil_resistance_level: CollatorSybilResistance::Resistant, // because of Aura - }) - .await?; - - if parachain_config.offchain_worker.enabled { - use futures::FutureExt; - - task_manager.spawn_handle().spawn( - "offchain-workers-runner", - "offchain-work", - sc_offchain::OffchainWorkers::new(sc_offchain::OffchainWorkerOptions { - runtime_api_provider: client.clone(), - keystore: Some(params.keystore_container.keystore()), - offchain_db: backend.offchain_storage(), - transaction_pool: Some(OffchainTransactionPoolFactory::new( - transaction_pool.clone(), - )), - network_provider: Arc::new(network.clone()), - is_validator: parachain_config.role.is_authority(), - enable_http_requests: false, - custom_extensions: move |_| vec![], - }) - .run(client.clone(), task_manager.spawn_handle()) - .boxed(), - ); - } - - let rpc_builder = { - let client = client.clone(); - let transaction_pool = transaction_pool.clone(); - - Box::new(move |deny_unsafe, _| { - let deps = crate::rpc::FullDeps { - client: client.clone(), - pool: transaction_pool.clone(), - deny_unsafe, - }; - - crate::rpc::create_full(deps).map_err(Into::into) - }) - }; - - sc_service::spawn_tasks(sc_service::SpawnTasksParams { - rpc_builder, - client: client.clone(), - transaction_pool: transaction_pool.clone(), - task_manager: &mut task_manager, - config: parachain_config, - keystore: params.keystore_container.keystore(), - backend, - network: network.clone(), - sync_service: sync_service.clone(), - system_rpc_tx, - tx_handler_controller, - telemetry: telemetry.as_mut(), - })?; - - if let Some(hwbench) = hwbench { - sc_sysinfo::print_hwbench(&hwbench); - // Here you can check whether the hardware meets your chains' requirements. Putting a link - // in there and swapping out the requirements for your own are probably a good idea. The - // requirements for a para-chain are dictated by its relay-chain. - match SUBSTRATE_REFERENCE_HARDWARE.check_hardware(&hwbench) { - Err(err) if validator => { - log::warn!( + let parachain_config = prepare_node_config(parachain_config); + + let params = new_partial(¶chain_config)?; + let (block_import, mut telemetry, telemetry_worker_handle) = params.other; + let net_config = sc_network::config::FullNetworkConfiguration::< + _, + _, + sc_network::NetworkWorker, + >::new(¶chain_config.network); + + let client = params.client.clone(); + let backend = params.backend.clone(); + let mut task_manager = params.task_manager; + + let (relay_chain_interface, collator_key) = build_relay_chain_interface( + polkadot_config, + ¶chain_config, + telemetry_worker_handle, + &mut task_manager, + collator_options.clone(), + hwbench.clone(), + ) + .await + .map_err(|e| sc_service::Error::Application(Box::new(e) as Box<_>))?; + + let validator = parachain_config.role.is_authority(); + let prometheus_registry = parachain_config.prometheus_registry().cloned(); + let transaction_pool = params.transaction_pool.clone(); + let import_queue_service = params.import_queue.service(); + + // NOTE: because we use Aura here explicitly, we can use `CollatorSybilResistance::Resistant` + // when starting the network. + let (network, system_rpc_tx, tx_handler_controller, start_network, sync_service) = + build_network(BuildNetworkParams { + parachain_config: ¶chain_config, + net_config, + client: client.clone(), + transaction_pool: transaction_pool.clone(), + para_id, + spawn_handle: task_manager.spawn_handle(), + relay_chain_interface: relay_chain_interface.clone(), + import_queue: params.import_queue, + sybil_resistance_level: CollatorSybilResistance::Resistant, // because of Aura + }) + .await?; + + if parachain_config.offchain_worker.enabled { + use futures::FutureExt; + + task_manager.spawn_handle().spawn( + "offchain-workers-runner", + "offchain-work", + sc_offchain::OffchainWorkers::new(sc_offchain::OffchainWorkerOptions { + runtime_api_provider: client.clone(), + keystore: Some(params.keystore_container.keystore()), + offchain_db: backend.offchain_storage(), + transaction_pool: Some(OffchainTransactionPoolFactory::new( + transaction_pool.clone(), + )), + network_provider: Arc::new(network.clone()), + is_validator: parachain_config.role.is_authority(), + enable_http_requests: false, + custom_extensions: move |_| vec![], + }) + .run(client.clone(), task_manager.spawn_handle()) + .boxed(), + ); + } + + let rpc_builder = { + let client = client.clone(); + let transaction_pool = transaction_pool.clone(); + + Box::new(move |deny_unsafe, _| { + let deps = crate::rpc::FullDeps { + client: client.clone(), + pool: transaction_pool.clone(), + deny_unsafe, + }; + + crate::rpc::create_full(deps).map_err(Into::into) + }) + }; + + sc_service::spawn_tasks(sc_service::SpawnTasksParams { + rpc_builder, + client: client.clone(), + transaction_pool: transaction_pool.clone(), + task_manager: &mut task_manager, + config: parachain_config, + keystore: params.keystore_container.keystore(), + backend, + network: network.clone(), + sync_service: sync_service.clone(), + system_rpc_tx, + tx_handler_controller, + telemetry: telemetry.as_mut(), + })?; + + if let Some(hwbench) = hwbench { + sc_sysinfo::print_hwbench(&hwbench); + // Here you can check whether the hardware meets your chains' requirements. Putting a link + // in there and swapping out the requirements for your own are probably a good idea. The + // requirements for a para-chain are dictated by its relay-chain. + match SUBSTRATE_REFERENCE_HARDWARE.check_hardware(&hwbench) { + Err(err) if validator => { + log::warn!( "⚠️ The hardware does not meet the minimal requirements {} for role 'Authority'.", err ); - }, - _ => {}, - } - - if let Some(ref mut telemetry) = telemetry { - let telemetry_handle = telemetry.handle(); - task_manager.spawn_handle().spawn( - "telemetry_hwbench", - None, - sc_sysinfo::initialize_hwbench_telemetry(telemetry_handle, hwbench), - ); - } - } - - let announce_block = { - let sync_service = sync_service.clone(); - Arc::new(move |hash, data| sync_service.announce_block(hash, data)) - }; - - let relay_chain_slot_duration = Duration::from_secs(6); - - let overseer_handle = relay_chain_interface - .overseer_handle() - .map_err(|e| sc_service::Error::Application(Box::new(e)))?; - - start_relay_chain_tasks(StartRelayChainTasksParams { - client: client.clone(), - announce_block: announce_block.clone(), - para_id, - relay_chain_interface: relay_chain_interface.clone(), - task_manager: &mut task_manager, - da_recovery_profile: if validator { - DARecoveryProfile::Collator - } else { - DARecoveryProfile::FullNode - }, - import_queue: import_queue_service, - relay_chain_slot_duration, - recovery_handle: Box::new(overseer_handle.clone()), - sync_service: sync_service.clone(), - })?; - - if validator { - start_consensus( - client.clone(), - block_import, - prometheus_registry.as_ref(), - telemetry.as_ref().map(|t| t.handle()), - &task_manager, - relay_chain_interface.clone(), - transaction_pool, - sync_service.clone(), - params.keystore_container.keystore(), - relay_chain_slot_duration, - para_id, - collator_key.expect("Command line arguments do not allow this. qed"), - overseer_handle, - announce_block, - )?; - } - - start_network.start_network(); - - Ok((task_manager, client)) + } + _ => {} + } + + if let Some(ref mut telemetry) = telemetry { + let telemetry_handle = telemetry.handle(); + task_manager.spawn_handle().spawn( + "telemetry_hwbench", + None, + sc_sysinfo::initialize_hwbench_telemetry(telemetry_handle, hwbench), + ); + } + } + + let announce_block = { + let sync_service = sync_service.clone(); + Arc::new(move |hash, data| sync_service.announce_block(hash, data)) + }; + + let relay_chain_slot_duration = Duration::from_secs(6); + + let overseer_handle = relay_chain_interface + .overseer_handle() + .map_err(|e| sc_service::Error::Application(Box::new(e)))?; + + start_relay_chain_tasks(StartRelayChainTasksParams { + client: client.clone(), + announce_block: announce_block.clone(), + para_id, + relay_chain_interface: relay_chain_interface.clone(), + task_manager: &mut task_manager, + da_recovery_profile: if validator { + DARecoveryProfile::Collator + } else { + DARecoveryProfile::FullNode + }, + import_queue: import_queue_service, + relay_chain_slot_duration, + recovery_handle: Box::new(overseer_handle.clone()), + sync_service: sync_service.clone(), + })?; + + if validator { + start_consensus( + client.clone(), + block_import, + prometheus_registry.as_ref(), + telemetry.as_ref().map(|t| t.handle()), + &task_manager, + relay_chain_interface.clone(), + transaction_pool, + sync_service.clone(), + params.keystore_container.keystore(), + relay_chain_slot_duration, + para_id, + collator_key.expect("Command line arguments do not allow this. qed"), + overseer_handle, + announce_block, + )?; + } + + start_network.start_network(); + + Ok((task_manager, client)) } diff --git a/runtime/build.rs b/runtime/build.rs index bb05afe02..eccd7f724 100644 --- a/runtime/build.rs +++ b/runtime/build.rs @@ -1,6 +1,6 @@ #[cfg(feature = "std")] fn main() { - substrate_wasm_builder::WasmBuilder::build_using_defaults(); + substrate_wasm_builder::WasmBuilder::build_using_defaults(); } /// The wasm builder is deactivated when compiling diff --git a/runtime/src/apis.rs b/runtime/src/apis.rs index b13ba278f..f527eb94b 100644 --- a/runtime/src/apis.rs +++ b/runtime/src/apis.rs @@ -25,255 +25,255 @@ // External crates imports use frame_support::{ - genesis_builder_helper::{build_state, get_preset}, - weights::Weight, + genesis_builder_helper::{build_state, get_preset}, + weights::Weight, }; use pallet_aura::Authorities; use sp_api::impl_runtime_apis; use sp_consensus_aura::sr25519::AuthorityId as AuraId; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; use sp_runtime::{ - traits::Block as BlockT, - transaction_validity::{TransactionSource, TransactionValidity}, - ApplyExtrinsicResult, + traits::Block as BlockT, + transaction_validity::{TransactionSource, TransactionValidity}, + ApplyExtrinsicResult, }; use sp_std::prelude::Vec; use sp_version::RuntimeVersion; // Local module imports use super::{ - AccountId, Aura, Balance, Block, Executive, InherentDataExt, Nonce, ParachainSystem, Runtime, - RuntimeCall, RuntimeGenesisConfig, SessionKeys, System, TransactionPayment, VERSION, + AccountId, Aura, Balance, Block, Executive, InherentDataExt, Nonce, ParachainSystem, Runtime, + RuntimeCall, RuntimeGenesisConfig, SessionKeys, System, TransactionPayment, VERSION, }; impl_runtime_apis! { - impl sp_consensus_aura::AuraApi for Runtime { - fn slot_duration() -> sp_consensus_aura::SlotDuration { - sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration()) - } - - fn authorities() -> Vec { - Authorities::::get().into_inner() - } - } - - impl sp_api::Core for Runtime { - fn version() -> RuntimeVersion { - VERSION - } - - fn execute_block(block: Block) { - Executive::execute_block(block) - } - - fn initialize_block(header: &::Header) -> sp_runtime::ExtrinsicInclusionMode { - Executive::initialize_block(header) - } - } - - impl sp_api::Metadata for Runtime { - fn metadata() -> OpaqueMetadata { - OpaqueMetadata::new(Runtime::metadata().into()) - } - - fn metadata_at_version(version: u32) -> Option { - Runtime::metadata_at_version(version) - } - - fn metadata_versions() -> sp_std::vec::Vec { - Runtime::metadata_versions() - } - } - - impl sp_block_builder::BlockBuilder for Runtime { - fn apply_extrinsic(extrinsic: ::Extrinsic) -> ApplyExtrinsicResult { - Executive::apply_extrinsic(extrinsic) - } - - fn finalize_block() -> ::Header { - Executive::finalize_block() - } - - fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<::Extrinsic> { - data.create_extrinsics() - } - - fn check_inherents( - block: Block, - data: sp_inherents::InherentData, - ) -> sp_inherents::CheckInherentsResult { - data.check_extrinsics(&block) - } - } - - impl sp_transaction_pool::runtime_api::TaggedTransactionQueue for Runtime { - fn validate_transaction( - source: TransactionSource, - tx: ::Extrinsic, - block_hash: ::Hash, - ) -> TransactionValidity { - Executive::validate_transaction(source, tx, block_hash) - } - } - - impl sp_offchain::OffchainWorkerApi for Runtime { - fn offchain_worker(header: &::Header) { - Executive::offchain_worker(header) - } - } - - impl sp_session::SessionKeys for Runtime { - fn generate_session_keys(seed: Option>) -> Vec { - SessionKeys::generate(seed) - } - - fn decode_session_keys( - encoded: Vec, - ) -> Option, KeyTypeId)>> { - SessionKeys::decode_into_raw_public_keys(&encoded) - } - } - - impl frame_system_rpc_runtime_api::AccountNonceApi for Runtime { - fn account_nonce(account: AccountId) -> Nonce { - System::account_nonce(account) - } - } - - impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi for Runtime { - fn query_info( - uxt: ::Extrinsic, - len: u32, - ) -> pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo { - TransactionPayment::query_info(uxt, len) - } - fn query_fee_details( - uxt: ::Extrinsic, - len: u32, - ) -> pallet_transaction_payment::FeeDetails { - TransactionPayment::query_fee_details(uxt, len) - } - fn query_weight_to_fee(weight: Weight) -> Balance { - TransactionPayment::weight_to_fee(weight) - } - fn query_length_to_fee(length: u32) -> Balance { - TransactionPayment::length_to_fee(length) - } - } - - impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentCallApi - for Runtime - { - fn query_call_info( - call: RuntimeCall, - len: u32, - ) -> pallet_transaction_payment::RuntimeDispatchInfo { - TransactionPayment::query_call_info(call, len) - } - fn query_call_fee_details( - call: RuntimeCall, - len: u32, - ) -> pallet_transaction_payment::FeeDetails { - TransactionPayment::query_call_fee_details(call, len) - } - fn query_weight_to_fee(weight: Weight) -> Balance { - TransactionPayment::weight_to_fee(weight) - } - fn query_length_to_fee(length: u32) -> Balance { - TransactionPayment::length_to_fee(length) - } - } - - impl cumulus_primitives_core::CollectCollationInfo for Runtime { - fn collect_collation_info(header: &::Header) -> cumulus_primitives_core::CollationInfo { - ParachainSystem::collect_collation_info(header) - } - } - - #[cfg(feature = "try-runtime")] - impl frame_try_runtime::TryRuntime for Runtime { - fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) { - use super::configs::RuntimeBlockWeights; - - let weight = Executive::try_runtime_upgrade(checks).unwrap(); - (weight, RuntimeBlockWeights::get().max_block) - } - - fn execute_block( - block: Block, - state_root_check: bool, - signature_check: bool, - select: frame_try_runtime::TryStateSelect, - ) -> Weight { - // NOTE: intentional unwrap: we don't want to propagate the error backwards, and want to - // have a backtrace here. - Executive::try_execute_block(block, state_root_check, signature_check, select).unwrap() - } - } - - #[cfg(feature = "runtime-benchmarks")] - impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(extra: bool) -> ( - Vec, - Vec, - ) { - use frame_benchmarking::{Benchmarking, BenchmarkList}; - use frame_support::traits::StorageInfoTrait; - use frame_system_benchmarking::Pallet as SystemBench; - use cumulus_pallet_session_benchmarking::Pallet as SessionBench; - use super::*; - - let mut list = Vec::::new(); - list_benchmarks!(list, extra); - - let storage_info = AllPalletsWithSystem::storage_info(); - (list, storage_info) - } - - fn dispatch_benchmark( - config: frame_benchmarking::BenchmarkConfig - ) -> Result, sp_runtime::RuntimeString> { - use frame_benchmarking::{BenchmarkError, Benchmarking, BenchmarkBatch}; - use super::*; - - use frame_system_benchmarking::Pallet as SystemBench; - impl frame_system_benchmarking::Config for Runtime { - fn setup_set_code_requirements(code: &sp_std::vec::Vec) -> Result<(), BenchmarkError> { - ParachainSystem::initialize_for_set_code_benchmark(code.len() as u32); - Ok(()) - } - - fn verify_set_code() { - System::assert_last_event(cumulus_pallet_parachain_system::Event::::ValidationFunctionStored.into()); - } - } - - use cumulus_pallet_session_benchmarking::Pallet as SessionBench; - impl cumulus_pallet_session_benchmarking::Config for Runtime {} - - use frame_support::traits::WhitelistedStorageKeys; - let whitelist = AllPalletsWithSystem::whitelisted_storage_keys(); - - let mut batches = Vec::::new(); - let params = (&config, &whitelist); - add_benchmarks!(params, batches); - - if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } - Ok(batches) - } - } - - impl sp_genesis_builder::GenesisBuilder for Runtime { - fn build_state(config: Vec) -> sp_genesis_builder::Result { - build_state::(config) - } - - fn get_preset(id: &Option) -> Option> { - get_preset::(id, |_| None) - } - - fn preset_names() -> Vec { - Default::default() - } - } + impl sp_consensus_aura::AuraApi for Runtime { + fn slot_duration() -> sp_consensus_aura::SlotDuration { + sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration()) + } + + fn authorities() -> Vec { + Authorities::::get().into_inner() + } + } + + impl sp_api::Core for Runtime { + fn version() -> RuntimeVersion { + VERSION + } + + fn execute_block(block: Block) { + Executive::execute_block(block) + } + + fn initialize_block(header: &::Header) -> sp_runtime::ExtrinsicInclusionMode { + Executive::initialize_block(header) + } + } + + impl sp_api::Metadata for Runtime { + fn metadata() -> OpaqueMetadata { + OpaqueMetadata::new(Runtime::metadata().into()) + } + + fn metadata_at_version(version: u32) -> Option { + Runtime::metadata_at_version(version) + } + + fn metadata_versions() -> sp_std::vec::Vec { + Runtime::metadata_versions() + } + } + + impl sp_block_builder::BlockBuilder for Runtime { + fn apply_extrinsic(extrinsic: ::Extrinsic) -> ApplyExtrinsicResult { + Executive::apply_extrinsic(extrinsic) + } + + fn finalize_block() -> ::Header { + Executive::finalize_block() + } + + fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<::Extrinsic> { + data.create_extrinsics() + } + + fn check_inherents( + block: Block, + data: sp_inherents::InherentData, + ) -> sp_inherents::CheckInherentsResult { + data.check_extrinsics(&block) + } + } + + impl sp_transaction_pool::runtime_api::TaggedTransactionQueue for Runtime { + fn validate_transaction( + source: TransactionSource, + tx: ::Extrinsic, + block_hash: ::Hash, + ) -> TransactionValidity { + Executive::validate_transaction(source, tx, block_hash) + } + } + + impl sp_offchain::OffchainWorkerApi for Runtime { + fn offchain_worker(header: &::Header) { + Executive::offchain_worker(header) + } + } + + impl sp_session::SessionKeys for Runtime { + fn generate_session_keys(seed: Option>) -> Vec { + SessionKeys::generate(seed) + } + + fn decode_session_keys( + encoded: Vec, + ) -> Option, KeyTypeId)>> { + SessionKeys::decode_into_raw_public_keys(&encoded) + } + } + + impl frame_system_rpc_runtime_api::AccountNonceApi for Runtime { + fn account_nonce(account: AccountId) -> Nonce { + System::account_nonce(account) + } + } + + impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi for Runtime { + fn query_info( + uxt: ::Extrinsic, + len: u32, + ) -> pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo { + TransactionPayment::query_info(uxt, len) + } + fn query_fee_details( + uxt: ::Extrinsic, + len: u32, + ) -> pallet_transaction_payment::FeeDetails { + TransactionPayment::query_fee_details(uxt, len) + } + fn query_weight_to_fee(weight: Weight) -> Balance { + TransactionPayment::weight_to_fee(weight) + } + fn query_length_to_fee(length: u32) -> Balance { + TransactionPayment::length_to_fee(length) + } + } + + impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentCallApi + for Runtime + { + fn query_call_info( + call: RuntimeCall, + len: u32, + ) -> pallet_transaction_payment::RuntimeDispatchInfo { + TransactionPayment::query_call_info(call, len) + } + fn query_call_fee_details( + call: RuntimeCall, + len: u32, + ) -> pallet_transaction_payment::FeeDetails { + TransactionPayment::query_call_fee_details(call, len) + } + fn query_weight_to_fee(weight: Weight) -> Balance { + TransactionPayment::weight_to_fee(weight) + } + fn query_length_to_fee(length: u32) -> Balance { + TransactionPayment::length_to_fee(length) + } + } + + impl cumulus_primitives_core::CollectCollationInfo for Runtime { + fn collect_collation_info(header: &::Header) -> cumulus_primitives_core::CollationInfo { + ParachainSystem::collect_collation_info(header) + } + } + + #[cfg(feature = "try-runtime")] + impl frame_try_runtime::TryRuntime for Runtime { + fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) { + use super::configs::RuntimeBlockWeights; + + let weight = Executive::try_runtime_upgrade(checks).unwrap(); + (weight, RuntimeBlockWeights::get().max_block) + } + + fn execute_block( + block: Block, + state_root_check: bool, + signature_check: bool, + select: frame_try_runtime::TryStateSelect, + ) -> Weight { + // NOTE: intentional unwrap: we don't want to propagate the error backwards, and want to + // have a backtrace here. + Executive::try_execute_block(block, state_root_check, signature_check, select).unwrap() + } + } + + #[cfg(feature = "runtime-benchmarks")] + impl frame_benchmarking::Benchmark for Runtime { + fn benchmark_metadata(extra: bool) -> ( + Vec, + Vec, + ) { + use frame_benchmarking::{Benchmarking, BenchmarkList}; + use frame_support::traits::StorageInfoTrait; + use frame_system_benchmarking::Pallet as SystemBench; + use cumulus_pallet_session_benchmarking::Pallet as SessionBench; + use super::*; + + let mut list = Vec::::new(); + list_benchmarks!(list, extra); + + let storage_info = AllPalletsWithSystem::storage_info(); + (list, storage_info) + } + + fn dispatch_benchmark( + config: frame_benchmarking::BenchmarkConfig + ) -> Result, sp_runtime::RuntimeString> { + use frame_benchmarking::{BenchmarkError, Benchmarking, BenchmarkBatch}; + use super::*; + + use frame_system_benchmarking::Pallet as SystemBench; + impl frame_system_benchmarking::Config for Runtime { + fn setup_set_code_requirements(code: &sp_std::vec::Vec) -> Result<(), BenchmarkError> { + ParachainSystem::initialize_for_set_code_benchmark(code.len() as u32); + Ok(()) + } + + fn verify_set_code() { + System::assert_last_event(cumulus_pallet_parachain_system::Event::::ValidationFunctionStored.into()); + } + } + + use cumulus_pallet_session_benchmarking::Pallet as SessionBench; + impl cumulus_pallet_session_benchmarking::Config for Runtime {} + + use frame_support::traits::WhitelistedStorageKeys; + let whitelist = AllPalletsWithSystem::whitelisted_storage_keys(); + + let mut batches = Vec::::new(); + let params = (&config, &whitelist); + add_benchmarks!(params, batches); + + if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } + Ok(batches) + } + } + + impl sp_genesis_builder::GenesisBuilder for Runtime { + fn build_state(config: Vec) -> sp_genesis_builder::Result { + build_state::(config) + } + + fn get_preset(id: &Option) -> Option> { + get_preset::(id, |_| None) + } + + fn preset_names() -> Vec { + Default::default() + } + } } diff --git a/runtime/src/benchmarks.rs b/runtime/src/benchmarks.rs index 9fbf1ad82..49fe15c3b 100644 --- a/runtime/src/benchmarks.rs +++ b/runtime/src/benchmarks.rs @@ -24,13 +24,13 @@ // For more information, please refer to frame_benchmarking::define_benchmarks!( - [frame_system, SystemBench::] - [pallet_balances, Balances] - [pallet_session, SessionBench::] - [pallet_timestamp, Timestamp] - [pallet_message_queue, MessageQueue] - [pallet_sudo, Sudo] - [pallet_collator_selection, CollatorSelection] - [cumulus_pallet_parachain_system, ParachainSystem] - [cumulus_pallet_xcmp_queue, XcmpQueue] + [frame_system, SystemBench::] + [pallet_balances, Balances] + [pallet_session, SessionBench::] + [pallet_timestamp, Timestamp] + [pallet_message_queue, MessageQueue] + [pallet_sudo, Sudo] + [pallet_collator_selection, CollatorSelection] + [cumulus_pallet_parachain_system, ParachainSystem] + [cumulus_pallet_xcmp_queue, XcmpQueue] ); diff --git a/runtime/src/configs/mod.rs b/runtime/src/configs/mod.rs index 26f03a060..77ae6bf0a 100644 --- a/runtime/src/configs/mod.rs +++ b/runtime/src/configs/mod.rs @@ -49,6 +49,7 @@ use sp_consensus_aura::sr25519::AuthorityId as AuraId; use sp_runtime::Perbill; use sp_version::RuntimeVersion; use xcm::latest::prelude::BodyId; +use xcm_config::{RelayLocation, XcmOriginToTransactDispatchOrigin}; // Local module imports use super::{ @@ -60,7 +61,6 @@ use super::{ MAXIMUM_BLOCK_WEIGHT, MICROUNIT, NORMAL_DISPATCH_RATIO, RELAY_CHAIN_SLOT_DURATION_MILLIS, SLOT_DURATION, UNINCLUDED_SEGMENT_CAPACITY, VERSION, }; -use xcm_config::{RelayLocation, XcmOriginToTransactDispatchOrigin}; parameter_types! { pub const Version: RuntimeVersion = VERSION; diff --git a/runtime/src/configs/xcm_config.rs b/runtime/src/configs/xcm_config.rs index c6b6e8da1..16b087363 100644 --- a/runtime/src/configs/xcm_config.rs +++ b/runtime/src/configs/xcm_config.rs @@ -1,11 +1,7 @@ -use crate::{ - AccountId, AllPalletsWithSystem, Balances, ParachainInfo, ParachainSystem, PolkadotXcm, - Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue, -}; use frame_support::{ - parameter_types, - traits::{ConstU32, Contains, Everything, Nothing}, - weights::Weight, + parameter_types, + traits::{ConstU32, Contains, Everything, Nothing}, + weights::Weight, }; use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; @@ -13,135 +9,150 @@ use polkadot_parachain_primitives::primitives::Sibling; use polkadot_runtime_common::impls::ToAuthor; use xcm::latest::prelude::*; use xcm_builder::{ - AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom, - DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, FixedWeightBounds, - FrameTransactionalProcessor, FungibleAdapter, IsConcrete, NativeAsset, ParentIsPreset, - RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, - SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, - TrailingSetTopicAsId, UsingComponents, WithComputedOrigin, WithUniqueTopic, + AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom, + DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, FixedWeightBounds, + FrameTransactionalProcessor, FungibleAdapter, IsConcrete, NativeAsset, ParentIsPreset, + RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, + SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, + TrailingSetTopicAsId, UsingComponents, WithComputedOrigin, WithUniqueTopic, }; use xcm_executor::XcmExecutor; +use crate::{ + AccountId, AllPalletsWithSystem, Balances, ParachainInfo, ParachainSystem, PolkadotXcm, + Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue, +}; + parameter_types! { - pub const RelayLocation: Location = Location::parent(); - pub const RelayNetwork: Option = None; - pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); - // For the real deployment, it is recommended to set `RelayNetwork` according to the relay chain - // and prepend `UniversalLocation` with `GlobalConsensus(RelayNetwork::get())`. - pub UniversalLocation: InteriorLocation = Parachain(ParachainInfo::parachain_id().into()).into(); + pub const RelayLocation: Location = Location::parent(); + pub const RelayNetwork: Option = None; + pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); + // For the real deployment, it is recommended to set `RelayNetwork` according to the relay chain + // and prepend `UniversalLocation` with `GlobalConsensus(RelayNetwork::get())`. + pub UniversalLocation: InteriorLocation = Parachain(ParachainInfo::parachain_id().into()).into(); } /// Type for specifying how a `Location` can be converted into an `AccountId`. This is used /// when determining ownership of accounts for asset transacting and when attempting to use XCM /// `Transact` in order to determine the dispatch Origin. pub type LocationToAccountId = ( - // The parent (Relay-chain) origin converts to the parent `AccountId`. - ParentIsPreset, - // Sibling parachain origins convert to AccountId via the `ParaId::into`. - SiblingParachainConvertsVia, - // Straight up local `AccountId32` origins just alias directly to `AccountId`. - AccountId32Aliases, + // The parent (Relay-chain) origin converts to the parent `AccountId`. + ParentIsPreset, + // Sibling parachain origins convert to AccountId via the `ParaId::into`. + SiblingParachainConvertsVia, + // Straight up local `AccountId32` origins just alias directly to `AccountId`. + AccountId32Aliases, ); /// Means for transacting assets on this chain. pub type LocalAssetTransactor = FungibleAdapter< - // Use this currency: - Balances, - // Use this currency when it is a fungible asset matching the given location or name: - IsConcrete, - // Do a simple punn to convert an AccountId32 Location into a native chain account ID: - LocationToAccountId, - // Our chain's account ID type (we can't get away without mentioning it explicitly): - AccountId, - // We don't track any teleports. - (), + // Use this currency: + Balances, + // Use this currency when it is a fungible asset matching the given location or name: + IsConcrete, + // Do a simple punn to convert an AccountId32 Location into a native chain account ID: + LocationToAccountId, + // Our chain's account ID type (we can't get away without mentioning it explicitly): + AccountId, + // We don't track any teleports. + (), >; /// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance, /// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can /// biases the kind of local `Origin` it will become. pub type XcmOriginToTransactDispatchOrigin = ( - // Sovereign account converter; this attempts to derive an `AccountId` from the origin location - // using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for - // foreign chains who want to have a local sovereign account on this chain which they control. - SovereignSignedViaLocation, - // Native converter for Relay-chain (Parent) location; will convert to a `Relay` origin when - // recognized. - RelayChainAsNative, - // Native converter for sibling Parachains; will convert to a `SiblingPara` origin when - // recognized. - SiblingParachainAsNative, - // Native signed account converter; this just converts an `AccountId32` origin into a normal - // `RuntimeOrigin::Signed` origin of the same 32-byte value. - SignedAccountId32AsNative, - // Xcm origins can be represented natively under the Xcm pallet's Xcm origin. - XcmPassthrough, + // Sovereign account converter; this attempts to derive an `AccountId` from the origin location + // using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for + // foreign chains who want to have a local sovereign account on this chain which they control. + SovereignSignedViaLocation, + // Native converter for Relay-chain (Parent) location; will convert to a `Relay` origin when + // recognized. + RelayChainAsNative, + // Native converter for sibling Parachains; will convert to a `SiblingPara` origin when + // recognized. + SiblingParachainAsNative, + // Native signed account converter; this just converts an `AccountId32` origin into a normal + // `RuntimeOrigin::Signed` origin of the same 32-byte value. + SignedAccountId32AsNative, + // Xcm origins can be represented natively under the Xcm pallet's Xcm origin. + XcmPassthrough, ); parameter_types! { - // One XCM operation is 1_000_000_000 weight - almost certainly a conservative estimate. - pub UnitWeightCost: Weight = Weight::from_parts(1_000_000_000, 64 * 1024); - pub const MaxInstructions: u32 = 100; - pub const MaxAssetsIntoHolding: u32 = 64; + // One XCM operation is 1_000_000_000 weight - almost certainly a conservative estimate. + pub UnitWeightCost: Weight = Weight::from_parts(1_000_000_000, 64 * 1024); + pub const MaxInstructions: u32 = 100; + pub const MaxAssetsIntoHolding: u32 = 64; } pub struct ParentOrParentsExecutivePlurality; impl Contains for ParentOrParentsExecutivePlurality { - fn contains(location: &Location) -> bool { - matches!(location.unpack(), (1, []) | (1, [Plurality { id: BodyId::Executive, .. }])) - } + fn contains(location: &Location) -> bool { + matches!( + location.unpack(), + (1, []) + | ( + 1, + [Plurality { + id: BodyId::Executive, + .. + }] + ) + ) + } } pub type Barrier = TrailingSetTopicAsId< - DenyThenTry< - DenyReserveTransferToRelayChain, - ( - TakeWeightCredit, - WithComputedOrigin< - ( - AllowTopLevelPaidExecutionFrom, - AllowExplicitUnpaidExecutionFrom, - // ^^^ Parent and its exec plurality get free execution - ), - UniversalLocation, - ConstU32<8>, - >, - ), - >, + DenyThenTry< + DenyReserveTransferToRelayChain, + ( + TakeWeightCredit, + WithComputedOrigin< + ( + AllowTopLevelPaidExecutionFrom, + AllowExplicitUnpaidExecutionFrom, + // ^^^ Parent and its exec plurality get free execution + ), + UniversalLocation, + ConstU32<8>, + >, + ), + >, >; pub struct XcmConfig; impl xcm_executor::Config for XcmConfig { - type RuntimeCall = RuntimeCall; - type XcmSender = XcmRouter; - // How to withdraw and deposit an asset. - type AssetTransactor = LocalAssetTransactor; - type OriginConverter = XcmOriginToTransactDispatchOrigin; - type IsReserve = NativeAsset; - type IsTeleporter = (); // Teleporting is disabled. - type UniversalLocation = UniversalLocation; - type Barrier = Barrier; - type Weigher = FixedWeightBounds; - type Trader = - UsingComponents>; - type ResponseHandler = PolkadotXcm; - type AssetTrap = PolkadotXcm; - type AssetClaims = PolkadotXcm; - type SubscriptionService = PolkadotXcm; - type PalletInstancesInfo = AllPalletsWithSystem; - type MaxAssetsIntoHolding = MaxAssetsIntoHolding; - type AssetLocker = (); - type AssetExchanger = (); - type FeeManager = (); - type MessageExporter = (); - type UniversalAliases = Nothing; - type CallDispatcher = RuntimeCall; - type SafeCallFilter = Everything; - type Aliasers = Nothing; - type TransactionalProcessor = FrameTransactionalProcessor; - type HrmpNewChannelOpenRequestHandler = (); - type HrmpChannelAcceptedHandler = (); - type HrmpChannelClosingHandler = (); + type RuntimeCall = RuntimeCall; + type XcmSender = XcmRouter; + // How to withdraw and deposit an asset. + type AssetTransactor = LocalAssetTransactor; + type OriginConverter = XcmOriginToTransactDispatchOrigin; + type IsReserve = NativeAsset; + type IsTeleporter = (); // Teleporting is disabled. + type UniversalLocation = UniversalLocation; + type Barrier = Barrier; + type Weigher = FixedWeightBounds; + type Trader = + UsingComponents>; + type ResponseHandler = PolkadotXcm; + type AssetTrap = PolkadotXcm; + type AssetClaims = PolkadotXcm; + type SubscriptionService = PolkadotXcm; + type PalletInstancesInfo = AllPalletsWithSystem; + type MaxAssetsIntoHolding = MaxAssetsIntoHolding; + type AssetLocker = (); + type AssetExchanger = (); + type FeeManager = (); + type MessageExporter = (); + type UniversalAliases = Nothing; + type CallDispatcher = RuntimeCall; + type SafeCallFilter = Everything; + type Aliasers = Nothing; + type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } /// No local origins on this chain are allowed to dispatch XCM sends/executions. @@ -150,43 +161,43 @@ pub type LocalOriginToLocation = SignedToAccountId32, - // ..and XCMP to communicate with the sibling chains. - XcmpQueue, + // Two routers - use UMP to communicate with the relay chain: + cumulus_primitives_utility::ParentAsUmp, + // ..and XCMP to communicate with the sibling chains. + XcmpQueue, )>; impl pallet_xcm::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type SendXcmOrigin = EnsureXcmOrigin; - type XcmRouter = XcmRouter; - type ExecuteXcmOrigin = EnsureXcmOrigin; - type XcmExecuteFilter = Nothing; - // ^ Disable dispatchable execute on the XCM pallet. - // Needs to be `Everything` for local testing. - type XcmExecutor = XcmExecutor; - type XcmTeleportFilter = Everything; - type XcmReserveTransferFilter = Nothing; - type Weigher = FixedWeightBounds; - type UniversalLocation = UniversalLocation; - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; + type RuntimeEvent = RuntimeEvent; + type SendXcmOrigin = EnsureXcmOrigin; + type XcmRouter = XcmRouter; + type ExecuteXcmOrigin = EnsureXcmOrigin; + type XcmExecuteFilter = Nothing; + // ^ Disable dispatchable execute on the XCM pallet. + // Needs to be `Everything` for local testing. + type XcmExecutor = XcmExecutor; + type XcmTeleportFilter = Everything; + type XcmReserveTransferFilter = Nothing; + type Weigher = FixedWeightBounds; + type UniversalLocation = UniversalLocation; + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; - const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; - // ^ Override for AdvertisedXcmVersion default - type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; - type Currency = Balances; - type CurrencyMatcher = (); - type TrustedLockers = (); - type SovereignAccountOf = LocationToAccountId; - type MaxLockers = ConstU32<8>; - type WeightInfo = pallet_xcm::TestWeightInfo; - type AdminOrigin = EnsureRoot; - type MaxRemoteLockConsumers = ConstU32<0>; - type RemoteLockConsumerIdentifier = (); + const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; + // ^ Override for AdvertisedXcmVersion default + type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; + type Currency = Balances; + type CurrencyMatcher = (); + type TrustedLockers = (); + type SovereignAccountOf = LocationToAccountId; + type MaxLockers = ConstU32<8>; + type WeightInfo = pallet_xcm::TestWeightInfo; + type AdminOrigin = EnsureRoot; + type MaxRemoteLockConsumers = ConstU32<0>; + type RemoteLockConsumerIdentifier = (); } impl cumulus_pallet_xcm::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type XcmExecutor = XcmExecutor; + type RuntimeEvent = RuntimeEvent; + type XcmExecutor = XcmExecutor; } diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 9602f08b8..1fbe72296 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -10,18 +10,6 @@ pub mod apis; mod configs; mod weights; -use smallvec::smallvec; -use sp_runtime::{ - create_runtime_str, generic, impl_opaque_keys, - traits::{BlakeTwo256, IdentifyAccount, Verify}, - MultiSignature, -}; - -use sp_std::prelude::*; -#[cfg(feature = "std")] -use sp_version::NativeVersion; -use sp_version::RuntimeVersion; - use frame_support::{ construct_runtime, weights::{ @@ -29,12 +17,20 @@ use frame_support::{ WeightToFeeCoefficients, WeightToFeePolynomial, }, }; +use smallvec::smallvec; pub use sp_consensus_aura::sr25519::AuthorityId as AuraId; -pub use sp_runtime::{MultiAddress, Perbill, Permill}; - #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; - +use sp_runtime::{ + create_runtime_str, generic, impl_opaque_keys, + traits::{BlakeTwo256, IdentifyAccount, Verify}, + MultiSignature, +}; +pub use sp_runtime::{MultiAddress, Perbill, Permill}; +use sp_std::prelude::*; +#[cfg(feature = "std")] +use sp_version::NativeVersion; +use sp_version::RuntimeVersion; use weights::ExtrinsicBaseWeight; /// Alias to 512-bit hash when used in the context of a transaction signature on the chain. @@ -129,13 +125,13 @@ impl WeightToFeePolynomial for WeightToFee { /// of data like extrinsics, allowing for them to continue syncing the network through upgrades /// to even the core data structures. pub mod opaque { - use super::*; + pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic; use sp_runtime::{ generic, traits::{BlakeTwo256, Hash as HashT}, }; - pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic; + use super::*; /// Opaque block header type. pub type Header = generic::Header; /// Opaque block type. diff --git a/runtime/src/weights/block_weights.rs b/runtime/src/weights/block_weights.rs index e7fdb2aae..df1ddd0e3 100644 --- a/runtime/src/weights/block_weights.rs +++ b/runtime/src/weights/block_weights.rs @@ -16,38 +16,38 @@ // limitations under the License. pub mod constants { - use frame_support::{ - parameter_types, - weights::{constants, Weight}, - }; + use frame_support::{ + parameter_types, + weights::{constants, Weight}, + }; - parameter_types! { - /// Importing a block with 0 Extrinsics. - pub const BlockExecutionWeight: Weight = - Weight::from_parts(constants::WEIGHT_REF_TIME_PER_NANOS.saturating_mul(5_000_000), 0); - } + parameter_types! { + /// Importing a block with 0 Extrinsics. + pub const BlockExecutionWeight: Weight = + Weight::from_parts(constants::WEIGHT_REF_TIME_PER_NANOS.saturating_mul(5_000_000), 0); + } - #[cfg(test)] - mod test_weights { - use frame_support::weights::constants; + #[cfg(test)] + mod test_weights { + use frame_support::weights::constants; - /// Checks that the weight exists and is sane. - // NOTE: If this test fails but you are sure that the generated values are fine, - // you can delete it. - #[test] - fn sane() { - let w = super::constants::BlockExecutionWeight::get(); + /// Checks that the weight exists and is sane. + // NOTE: If this test fails but you are sure that the generated values are fine, + // you can delete it. + #[test] + fn sane() { + let w = super::constants::BlockExecutionWeight::get(); - // At least 100 µs. - assert!( - w.ref_time() >= 100u64 * constants::WEIGHT_REF_TIME_PER_MICROS, - "Weight should be at least 100 µs." - ); - // At most 50 ms. - assert!( - w.ref_time() <= 50u64 * constants::WEIGHT_REF_TIME_PER_MILLIS, - "Weight should be at most 50 ms." - ); - } - } + // At least 100 µs. + assert!( + w.ref_time() >= 100u64 * constants::WEIGHT_REF_TIME_PER_MICROS, + "Weight should be at least 100 µs." + ); + // At most 50 ms. + assert!( + w.ref_time() <= 50u64 * constants::WEIGHT_REF_TIME_PER_MILLIS, + "Weight should be at most 50 ms." + ); + } + } } diff --git a/runtime/src/weights/extrinsic_weights.rs b/runtime/src/weights/extrinsic_weights.rs index 1a4adb968..ce4e86db7 100644 --- a/runtime/src/weights/extrinsic_weights.rs +++ b/runtime/src/weights/extrinsic_weights.rs @@ -16,38 +16,38 @@ // limitations under the License. pub mod constants { - use frame_support::{ - parameter_types, - weights::{constants, Weight}, - }; + use frame_support::{ + parameter_types, + weights::{constants, Weight}, + }; - parameter_types! { - /// Executing a NO-OP `System::remarks` Extrinsic. - pub const ExtrinsicBaseWeight: Weight = - Weight::from_parts(constants::WEIGHT_REF_TIME_PER_NANOS.saturating_mul(125_000), 0); - } + parameter_types! { + /// Executing a NO-OP `System::remarks` Extrinsic. + pub const ExtrinsicBaseWeight: Weight = + Weight::from_parts(constants::WEIGHT_REF_TIME_PER_NANOS.saturating_mul(125_000), 0); + } - #[cfg(test)] - mod test_weights { - use frame_support::weights::constants; + #[cfg(test)] + mod test_weights { + use frame_support::weights::constants; - /// Checks that the weight exists and is sane. - // NOTE: If this test fails but you are sure that the generated values are fine, - // you can delete it. - #[test] - fn sane() { - let w = super::constants::ExtrinsicBaseWeight::get(); + /// Checks that the weight exists and is sane. + // NOTE: If this test fails but you are sure that the generated values are fine, + // you can delete it. + #[test] + fn sane() { + let w = super::constants::ExtrinsicBaseWeight::get(); - // At least 10 µs. - assert!( - w.ref_time() >= 10u64 * constants::WEIGHT_REF_TIME_PER_MICROS, - "Weight should be at least 10 µs." - ); - // At most 1 ms. - assert!( - w.ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS, - "Weight should be at most 1 ms." - ); - } - } + // At least 10 µs. + assert!( + w.ref_time() >= 10u64 * constants::WEIGHT_REF_TIME_PER_MICROS, + "Weight should be at least 10 µs." + ); + // At most 1 ms. + assert!( + w.ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS, + "Weight should be at most 1 ms." + ); + } + } } diff --git a/runtime/src/weights/paritydb_weights.rs b/runtime/src/weights/paritydb_weights.rs index 256797038..7271abf17 100644 --- a/runtime/src/weights/paritydb_weights.rs +++ b/runtime/src/weights/paritydb_weights.rs @@ -16,48 +16,49 @@ // limitations under the License. pub mod constants { - use frame_support::{ - parameter_types, - weights::{constants, RuntimeDbWeight}, - }; + use frame_support::{ + parameter_types, + weights::{constants, RuntimeDbWeight}, + }; - parameter_types! { - /// `ParityDB` can be enabled with a feature flag, but is still experimental. These weights - /// are available for brave runtime engineers who may want to try this out as default. - pub const ParityDbWeight: RuntimeDbWeight = RuntimeDbWeight { - read: 8_000 * constants::WEIGHT_REF_TIME_PER_NANOS, - write: 50_000 * constants::WEIGHT_REF_TIME_PER_NANOS, - }; - } + parameter_types! { + /// `ParityDB` can be enabled with a feature flag, but is still experimental. These weights + /// are available for brave runtime engineers who may want to try this out as default. + pub const ParityDbWeight: RuntimeDbWeight = RuntimeDbWeight { + read: 8_000 * constants::WEIGHT_REF_TIME_PER_NANOS, + write: 50_000 * constants::WEIGHT_REF_TIME_PER_NANOS, + }; + } - #[cfg(test)] - mod test_db_weights { - use super::constants::ParityDbWeight as W; - use frame_support::weights::constants; + #[cfg(test)] + mod test_db_weights { + use frame_support::weights::constants; - /// Checks that all weights exist and have sane values. - // NOTE: If this test fails but you are sure that the generated values are fine, - // you can delete it. - #[test] - fn sane() { - // At least 1 µs. - assert!( - W::get().reads(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS, - "Read weight should be at least 1 µs." - ); - assert!( - W::get().writes(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS, - "Write weight should be at least 1 µs." - ); - // At most 1 ms. - assert!( - W::get().reads(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS, - "Read weight should be at most 1 ms." - ); - assert!( - W::get().writes(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS, - "Write weight should be at most 1 ms." - ); - } - } + use super::constants::ParityDbWeight as W; + + /// Checks that all weights exist and have sane values. + // NOTE: If this test fails but you are sure that the generated values are fine, + // you can delete it. + #[test] + fn sane() { + // At least 1 µs. + assert!( + W::get().reads(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS, + "Read weight should be at least 1 µs." + ); + assert!( + W::get().writes(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS, + "Write weight should be at least 1 µs." + ); + // At most 1 ms. + assert!( + W::get().reads(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS, + "Read weight should be at most 1 ms." + ); + assert!( + W::get().writes(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS, + "Write weight should be at most 1 ms." + ); + } + } } diff --git a/runtime/src/weights/rocksdb_weights.rs b/runtime/src/weights/rocksdb_weights.rs index 3dd817aa6..fbf498e27 100644 --- a/runtime/src/weights/rocksdb_weights.rs +++ b/runtime/src/weights/rocksdb_weights.rs @@ -16,48 +16,49 @@ // limitations under the License. pub mod constants { - use frame_support::{ - parameter_types, - weights::{constants, RuntimeDbWeight}, - }; + use frame_support::{ + parameter_types, + weights::{constants, RuntimeDbWeight}, + }; - parameter_types! { - /// By default, Substrate uses `RocksDB`, so this will be the weight used throughout - /// the runtime. - pub const RocksDbWeight: RuntimeDbWeight = RuntimeDbWeight { - read: 25_000 * constants::WEIGHT_REF_TIME_PER_NANOS, - write: 100_000 * constants::WEIGHT_REF_TIME_PER_NANOS, - }; - } + parameter_types! { + /// By default, Substrate uses `RocksDB`, so this will be the weight used throughout + /// the runtime. + pub const RocksDbWeight: RuntimeDbWeight = RuntimeDbWeight { + read: 25_000 * constants::WEIGHT_REF_TIME_PER_NANOS, + write: 100_000 * constants::WEIGHT_REF_TIME_PER_NANOS, + }; + } - #[cfg(test)] - mod test_db_weights { - use super::constants::RocksDbWeight as W; - use frame_support::weights::constants; + #[cfg(test)] + mod test_db_weights { + use frame_support::weights::constants; - /// Checks that all weights exist and have sane values. - // NOTE: If this test fails but you are sure that the generated values are fine, - // you can delete it. - #[test] - fn sane() { - // At least 1 µs. - assert!( - W::get().reads(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS, - "Read weight should be at least 1 µs." - ); - assert!( - W::get().writes(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS, - "Write weight should be at least 1 µs." - ); - // At most 1 ms. - assert!( - W::get().reads(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS, - "Read weight should be at most 1 ms." - ); - assert!( - W::get().writes(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS, - "Write weight should be at most 1 ms." - ); - } - } + use super::constants::RocksDbWeight as W; + + /// Checks that all weights exist and have sane values. + // NOTE: If this test fails but you are sure that the generated values are fine, + // you can delete it. + #[test] + fn sane() { + // At least 1 µs. + assert!( + W::get().reads(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS, + "Read weight should be at least 1 µs." + ); + assert!( + W::get().writes(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS, + "Write weight should be at least 1 µs." + ); + // At most 1 ms. + assert!( + W::get().reads(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS, + "Read weight should be at most 1 ms." + ); + assert!( + W::get().writes(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS, + "Write weight should be at most 1 ms." + ); + } + } } From 96778e16416322e3163224905571f8de1a4e634f Mon Sep 17 00:00:00 2001 From: aidan Date: Mon, 13 May 2024 15:27:39 +0200 Subject: [PATCH 30/48] ci: Remove job run on PR --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c1f2bdcd9..6261b6594 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,6 +1,6 @@ name: CI -on: [push, pull_request] +on: push jobs: toml: From 6fdf0b24d1dc4212e338ed990f85e93fc64c5a20 Mon Sep 17 00:00:00 2001 From: aidan Date: Mon, 13 May 2024 15:36:57 +0200 Subject: [PATCH 31/48] fix: Duplicate dependencies --- Cargo.toml | 60 +++++++++++++++++++++++----------------------- node/Cargo.toml | 15 +++--------- runtime/Cargo.toml | 10 ++++---- 3 files changed, 37 insertions(+), 48 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fa6484efb..9c0312b41 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,9 @@ [workspace.package] +authors = ["Eiger Oy "] edition = "2021" -repository = "https://github.com/eigerco/polka-storage" homepage = "https://eiger.co" -authors = ["Eiger Oy "] license-file = "LICENSE" +repository = "https://github.com/eigerco/polka-storage" [workspace] members = ["node", "runtime"] @@ -17,10 +17,12 @@ litep2p = "0.3.0" substrate-build-script-utils = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } substrate-wasm-builder = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } -scale-info = { version = "2.11.1", default-features = false } -polkavm = "0.9.3" -polkavm-linker = "0.9.2" -polkavm-derive = "0.9.1" +clap = { version = "4.5.3" } +codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false } +color-print = "0.3.4" +futures = "0.3.28" +hex-literal = { version = "0.4.1" } +jsonrpsee = { version = "0.22" } log = { version = "0.4.21", default-features = false } polkavm = "0.9.3" polkavm-derive = "0.9.1" @@ -46,11 +48,11 @@ sc-basic-authorship = { git = "https://github.com/paritytech/polkadot-sdk", tag sc-chain-spec = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } sc-cli = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } sc-client-api = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } -sc-offchain = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } sc-consensus = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } sc-executor = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } sc-network = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } sc-network-sync = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } +sc-offchain = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } sc-rpc = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } sc-service = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } sc-sysinfo = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } @@ -63,27 +65,25 @@ sp-block-builder = { git = "https://github.com/paritytech/polkadot-sdk", tag = " sp-blockchain = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } sp-consensus-aura = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false } sp-core = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false } -sp-keystore = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } -sp-io = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } -sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false } -sp-timestamp = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } -substrate-frame-rpc-system = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } -substrate-prometheus-endpoint = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } sp-genesis-builder = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false } sp-inherents = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false } +sp-io = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } +sp-keystore = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } sp-offchain = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false } +sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false } sp-session = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false } sp-std = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false } +sp-timestamp = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } sp-transaction-pool = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false } sp-version = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false } +substrate-frame-rpc-system = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } +substrate-prometheus-endpoint = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } # Polkadot -polkadot-cli = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", features = [ - "rococo-native", -] } -polkadot-primitives = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } pallet-xcm = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false } +polkadot-cli = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", features = ["rococo-native"] } polkadot-parachain-primitives = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false } +polkadot-primitives = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } polkadot-runtime-common = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false } xcm = { package = "staging-xcm", git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false } xcm-builder = { package = "staging-xcm-builder", git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false } @@ -91,13 +91,13 @@ xcm-executor = { package = "staging-xcm-executor", git = "https://github.com/par # Substrate / FRAME frame-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false } +frame-benchmarking-cli = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } frame-executive = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false } frame-support = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false } frame-system = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false } frame-system-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false } frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false } frame-try-runtime = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false } -frame-benchmarking-cli = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } # FRAME Pallets pallet-aura = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false } @@ -112,27 +112,27 @@ pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/parityt # Cumulus -cumulus-pallet-aura-ext = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false } -cumulus-pallet-parachain-system = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false, features = [ - "parameterized-consensus-hook", -] } -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-utility = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false } -cumulus-primitives-storage-weight-reclaim = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false } -pallet-collator-selection = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false } -parachains-common = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false } -parachain-info = { package = "staging-parachain-info", git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false } cumulus-client-cli = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } cumulus-client-collator = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } cumulus-client-consensus-aura = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } cumulus-client-consensus-common = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } cumulus-client-consensus-proposer = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } cumulus-client-service = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } +cumulus-pallet-aura-ext = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false } +cumulus-pallet-parachain-system = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false, features = [ + "parameterized-consensus-hook", +] } +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-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 } cumulus-relay-chain-interface = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0" } +pallet-collator-selection = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false } +parachain-info = { package = "staging-parachain-info", git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false } +parachains-common = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-v1.11.0", default-features = false } [workspace.lints.rust] suspicious_double_ref_op = { level = "allow", priority = 2 } diff --git a/node/Cargo.toml b/node/Cargo.toml index cb3ef4f3e..293d508a8 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -1,18 +1,10 @@ [package] -name = "polka-storage-node" -description = "Polka Storage parachain collator." -version = "0.0.0" -license-file.workspace = true -homepage.workspace = true -repository.workspace = true -edition.workspace = true authors.workspace = true -publish = false build = "build.rs" -description = "A parachain node template built with Substrate and Cumulus, part of Polkadot Sdk." +description = "Polka Storage parachain collator." edition.workspace = true homepage.workspace = true -license = "MIT-0" +license-file.workspace = true name = "polka-storage-node" publish = false repository.workspace = true @@ -74,7 +66,7 @@ polkadot-primitives = { workspace = true } xcm = { workspace = true, default-features = false } # Cumulus -color-print = "0.3.4" +color-print = { workspace = true } cumulus-client-cli = { workspace = true } cumulus-client-collator = { workspace = true } cumulus-client-consensus-aura = { workspace = true } @@ -84,7 +76,6 @@ cumulus-client-service = { workspace = true } cumulus-primitives-core = { workspace = true } cumulus-primitives-parachain-inherent = { workspace = true } cumulus-relay-chain-interface = { workspace = true } -color-print = { workspace = true } [build-dependencies] substrate-build-script-utils = { workspace = true } diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index ddfbe995c..6e22ebd23 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -1,12 +1,10 @@ [package] -name = "polka-storage-runtime" +authors.workspace = true description = "Polka Storage parachain runtime." -version = "0.0.0" -license-file.workspace = true -homepage.workspace = true -repository.workspace = true edition.workspace = true -authors.workspace = true +homepage.workspace = true +license-file.workspace = true +name = "polka-storage-runtime" publish = false repository.workspace = true version = "0.0.0" From c89ff2bf98eed6856b89231fb3f6f2f45ed2d29c Mon Sep 17 00:00:00 2001 From: aidan Date: Mon, 13 May 2024 15:45:40 +0200 Subject: [PATCH 32/48] style: Format rust files --- node/src/service.rs | 11 +++++------ runtime/src/configs/xcm_config.rs | 4 ---- runtime/src/weights/paritydb_weights.rs | 3 ++- runtime/src/weights/rocksdb_weights.rs | 3 ++- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/node/src/service.rs b/node/src/service.rs index 4b936fe9a..ebcd9fb27 100644 --- a/node/src/service.rs +++ b/node/src/service.rs @@ -4,12 +4,6 @@ use std::{sync::Arc, time::Duration}; use cumulus_client_cli::CollatorOptions; -// Local Runtime Types -use polka_storage_runtime::{ - apis::RuntimeApi, - opaque::{Block, Hash}, -}; - // Cumulus Imports use cumulus_client_collator::service::CollatorService; use cumulus_client_consensus_common::ParachainBlockImport as TParachainBlockImport; @@ -28,6 +22,11 @@ use polka_storage_runtime::{ apis::RuntimeApi, opaque::{Block, Hash}, }; +// Local Runtime Types +use polka_storage_runtime::{ + apis::RuntimeApi, + opaque::{Block, Hash}, +}; use sc_client_api::Backend; use sc_consensus::ImportQueue; use sc_executor::{HeapAllocStrategy, WasmExecutor, DEFAULT_HEAP_ALLOC_STRATEGY}; diff --git a/runtime/src/configs/xcm_config.rs b/runtime/src/configs/xcm_config.rs index 714e8f35a..16b087363 100644 --- a/runtime/src/configs/xcm_config.rs +++ b/runtime/src/configs/xcm_config.rs @@ -1,7 +1,3 @@ -use crate::{ - AccountId, AllPalletsWithSystem, Balances, ParachainInfo, ParachainSystem, PolkadotXcm, - Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue, -}; use frame_support::{ parameter_types, traits::{ConstU32, Contains, Everything, Nothing}, diff --git a/runtime/src/weights/paritydb_weights.rs b/runtime/src/weights/paritydb_weights.rs index 04dc363e0..7271abf17 100644 --- a/runtime/src/weights/paritydb_weights.rs +++ b/runtime/src/weights/paritydb_weights.rs @@ -32,9 +32,10 @@ pub mod constants { #[cfg(test)] mod test_db_weights { - use super::constants::ParityDbWeight as W; use frame_support::weights::constants; + use super::constants::ParityDbWeight as W; + /// Checks that all weights exist and have sane values. // NOTE: If this test fails but you are sure that the generated values are fine, // you can delete it. diff --git a/runtime/src/weights/rocksdb_weights.rs b/runtime/src/weights/rocksdb_weights.rs index a69621823..fbf498e27 100644 --- a/runtime/src/weights/rocksdb_weights.rs +++ b/runtime/src/weights/rocksdb_weights.rs @@ -32,9 +32,10 @@ pub mod constants { #[cfg(test)] mod test_db_weights { - use super::constants::RocksDbWeight as W; use frame_support::weights::constants; + use super::constants::RocksDbWeight as W; + /// Checks that all weights exist and have sane values. // NOTE: If this test fails but you are sure that the generated values are fine, // you can delete it. From d355a787b2d22164c5137f748d82f43525b518da Mon Sep 17 00:00:00 2001 From: aidan Date: Mon, 13 May 2024 15:48:02 +0200 Subject: [PATCH 33/48] ci: Move clippy build and test into 1 job --- .github/workflows/ci.yaml | 32 +------------------------------- 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6261b6594..4b3edead3 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -42,7 +42,7 @@ jobs: echo '.rs files are not formatted correctly' echo 'Please run cargo fmt --all' - clippy: + clippy_build_and_test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -66,21 +66,6 @@ jobs: run: | echo 'cargo clippy failed' echo 'Please fix the issue generated by clippy' - - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Install protobuf compiler - run: | - sudo apt-get update - sudo apt-get install protobuf-compiler - - uses: dtolnay/rust-toolchain@stable - with: - toolchain: 1.77.0 - target: wasm32-unknown-unknown - - name: List version - run: cargo --version - name: Build with try-runtime feature run: RUSTFLAGS="-D warnings" cargo build --features try-runtime - name: try-runtime build failure @@ -105,21 +90,6 @@ jobs: if: failure() run: | echo 'cargo build --release failed' - - test: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Install protobuf compiler - run: | - sudo apt-get update - sudo apt-get install protobuf-compiler - - uses: dtolnay/rust-toolchain@stable - with: - toolchain: 1.77.0 - target: wasm32-unknown-unknown - - name: List version - run: cargo --version - name: Run tests run: RUSTFLAGS="-D warnings" cargo test --workspace - name: Cargo test fail From 5d3b9fb978449f216233f107de66893503eee5f3 Mon Sep 17 00:00:00 2001 From: aidan Date: Mon, 13 May 2024 16:17:13 +0200 Subject: [PATCH 34/48] ci: Add rust-src component --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 4b3edead3..d6e526d77 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -54,7 +54,7 @@ jobs: with: toolchain: 1.77.0 target: wasm32-unknown-unknown - components: clippy + components: clippy rust-src - name: List version run: | cargo --version From c53aff2363fb13c2f9a7f520935d9f8fc947e99a Mon Sep 17 00:00:00 2001 From: aidan Date: Mon, 13 May 2024 16:21:20 +0200 Subject: [PATCH 35/48] ci: Single failure handling --- .github/workflows/ci.yaml | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index d6e526d77..3065bbf70 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -61,38 +61,18 @@ jobs: cargo clippy --version - name: Cargo clippy run: cargo clippy -- -D warnings - - name: Cargo clippy failure info - if: failure() - run: | - echo 'cargo clippy failed' - echo 'Please fix the issue generated by clippy' - name: Build with try-runtime feature run: RUSTFLAGS="-D warnings" cargo build --features try-runtime - - name: try-runtime build failure - if: failure() - run: | - echo 'Building with `try-runtime` feature failed' - name: Build node runtime run: RUSTFLAGS="-D warnings" cargo build -p polka-storage-runtime - - name: Node runtime build failure - if: failure() - run: | - echo 'Building the node runtime failed' - name: Build node with runtime-benchmark feature run: RUSTFLAGS="-D warnings" cargo build -p polka-storage-node --features runtime-benchmarks - - name: runtime-benchmark build failure - if: failure() - run: | - echo 'Failed to build node with runtime-benchmark feature' - name: Build in release mode run: RUSTFLAGS="-D warnings" cargo build --release - - name: Release build failed - if: failure() - run: | - echo 'cargo build --release failed' - name: Run tests run: RUSTFLAGS="-D warnings" cargo test --workspace - - name: Cargo test fail + - name: Failure handling if: failure() run: | - echo 'cargo test --workspace failed' + echo 'Job clippy_build_and_test failed.' + echo 'Please check the logs for more details' From 74461e25873c436ccc6497374f0a71f6a4f9c53c Mon Sep 17 00:00:00 2001 From: aidan Date: Mon, 13 May 2024 16:33:00 +0200 Subject: [PATCH 36/48] fix: Double import after merge --- node/src/service.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/node/src/service.rs b/node/src/service.rs index ebcd9fb27..d714dc422 100644 --- a/node/src/service.rs +++ b/node/src/service.rs @@ -22,11 +22,6 @@ use polka_storage_runtime::{ apis::RuntimeApi, opaque::{Block, Hash}, }; -// Local Runtime Types -use polka_storage_runtime::{ - apis::RuntimeApi, - opaque::{Block, Hash}, -}; use sc_client_api::Backend; use sc_consensus::ImportQueue; use sc_executor::{HeapAllocStrategy, WasmExecutor, DEFAULT_HEAP_ALLOC_STRATEGY}; From e312050e8e96b1f190a6215f5cf5da1a2b4dd0bb Mon Sep 17 00:00:00 2001 From: aidan Date: Mon, 13 May 2024 16:34:26 +0200 Subject: [PATCH 37/48] ci: Add `-q` flag to not convolute logs --- .github/workflows/ci.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3065bbf70..dad1f6300 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -60,17 +60,17 @@ jobs: cargo --version cargo clippy --version - name: Cargo clippy - run: cargo clippy -- -D warnings + run: cargo clippy -q -- -D warnings - name: Build with try-runtime feature - run: RUSTFLAGS="-D warnings" cargo build --features try-runtime + run: RUSTFLAGS="-D warnings" cargo build -q --features try-runtime - name: Build node runtime - run: RUSTFLAGS="-D warnings" cargo build -p polka-storage-runtime + run: RUSTFLAGS="-D warnings" cargo build -q -p polka-storage-runtime - name: Build node with runtime-benchmark feature - run: RUSTFLAGS="-D warnings" cargo build -p polka-storage-node --features runtime-benchmarks + run: RUSTFLAGS="-D warnings" cargo build -q -p polka-storage-node --features runtime-benchmarks - name: Build in release mode - run: RUSTFLAGS="-D warnings" cargo build --release + run: RUSTFLAGS="-D warnings" cargo build -q --release - name: Run tests - run: RUSTFLAGS="-D warnings" cargo test --workspace + run: RUSTFLAGS="-D warnings" cargo test -q --workspace - name: Failure handling if: failure() run: | From 47107ef4d02b59841b1cb8d761ba1837e783485f Mon Sep 17 00:00:00 2001 From: aidan Date: Mon, 13 May 2024 18:58:58 +0200 Subject: [PATCH 38/48] ci: Cancel previous job on push --- .github/workflows/ci.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index dad1f6300..2f85c3e3f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -2,6 +2,10 @@ name: CI on: push +concurrency: + group: ${{ github.ref }} + cancel-in-progress: true + jobs: toml: runs-on: ubuntu-latest From 9f07575dadbb80a5c03cd0e6947b69187fce0a8a Mon Sep 17 00:00:00 2001 From: aidan Date: Mon, 13 May 2024 19:02:37 +0200 Subject: [PATCH 39/48] ci: Make CI run on comment --- .github/workflows/ci.yaml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 2f85c3e3f..cecf3ff0a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,6 +1,8 @@ name: CI -on: push +on: + issue_comment: + types: [created] concurrency: group: ${{ github.ref }} @@ -9,6 +11,7 @@ concurrency: jobs: toml: runs-on: ubuntu-latest + if: github.event.issue.pull_request && github.event.comment.body == '!CI' steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable @@ -28,6 +31,7 @@ jobs: format: runs-on: ubuntu-latest + if: github.event.issue.pull_request && github.event.comment.body == '!CI' steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable @@ -48,6 +52,7 @@ jobs: clippy_build_and_test: runs-on: ubuntu-latest + if: github.event.issue.pull_request && github.event.comment.body == '!CI' steps: - uses: actions/checkout@v4 - name: Install protobuf compiler From fc7c004650570cfad01a0e773dcca849affd7a8c Mon Sep 17 00:00:00 2001 From: aidan Date: Mon, 13 May 2024 19:09:13 +0200 Subject: [PATCH 40/48] ci: Add `--locked` flag to cargo jobs --- .github/workflows/ci.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index cecf3ff0a..fa90b7a77 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -69,17 +69,17 @@ jobs: cargo --version cargo clippy --version - name: Cargo clippy - run: cargo clippy -q -- -D warnings + run: cargo clippy --locked -q -- -D warnings - name: Build with try-runtime feature - run: RUSTFLAGS="-D warnings" cargo build -q --features try-runtime + run: RUSTFLAGS="-D warnings" cargo build --locked -q --features try-runtime - name: Build node runtime - run: RUSTFLAGS="-D warnings" cargo build -q -p polka-storage-runtime + run: RUSTFLAGS="-D warnings" cargo build --locked -q -p polka-storage-runtime - name: Build node with runtime-benchmark feature - run: RUSTFLAGS="-D warnings" cargo build -q -p polka-storage-node --features runtime-benchmarks + run: RUSTFLAGS="-D warnings" cargo build --locked -q -p polka-storage-node --features runtime-benchmarks - name: Build in release mode - run: RUSTFLAGS="-D warnings" cargo build -q --release + run: RUSTFLAGS="-D warnings" cargo build --locked -q --release - name: Run tests - run: RUSTFLAGS="-D warnings" cargo test -q --workspace + run: RUSTFLAGS="-D warnings" cargo test --locked -q --workspace - name: Failure handling if: failure() run: | From a8f4c6082f77d7a74c71a26d2daac130853c4745 Mon Sep 17 00:00:00 2001 From: aidan Date: Tue, 14 May 2024 12:16:56 +0200 Subject: [PATCH 41/48] ci: Run CI on label and push to dev/main --- .github/workflows/ci.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index fa90b7a77..9ef9d85da 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,8 +1,10 @@ name: CI on: - issue_comment: - types: [created] + pull_request: + types: [labeled] + push: + branches: [develop, main] concurrency: group: ${{ github.ref }} From da3474ada6e780965444af2309178c1008659e1e Mon Sep 17 00:00:00 2001 From: aidan Date: Tue, 14 May 2024 12:18:48 +0200 Subject: [PATCH 42/48] ci: Remove run on comment --- .github/workflows/ci.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 9ef9d85da..f0322a451 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -13,7 +13,6 @@ concurrency: jobs: toml: runs-on: ubuntu-latest - if: github.event.issue.pull_request && github.event.comment.body == '!CI' steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable @@ -33,7 +32,6 @@ jobs: format: runs-on: ubuntu-latest - if: github.event.issue.pull_request && github.event.comment.body == '!CI' steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable @@ -54,7 +52,6 @@ jobs: clippy_build_and_test: runs-on: ubuntu-latest - if: github.event.issue.pull_request && github.event.comment.body == '!CI' steps: - uses: actions/checkout@v4 - name: Install protobuf compiler From 6c1a65b19bcdeeab0476f97083da9c402abb01f8 Mon Sep 17 00:00:00 2001 From: aidan Date: Tue, 14 May 2024 12:23:14 +0200 Subject: [PATCH 43/48] ci: Add caching --- .github/workflows/ci.yaml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f0322a451..a992bc8d8 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -54,6 +54,22 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - name: Cache cargo registry + uses: actions/cache@v2 + with: + path: ~/.cargo/registry + key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.toml') }} + - name: Cache cargo index + uses: actions/cache@v2 + with: + path: ~/.cargo/git + key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.toml') }} + - name: Cache target directory + id: cache-target + uses: actions/cache@v2 + with: + path: target + key: ${{ runner.os }}-cargo-build-target2-${{ hashFiles('**/Cargo.toml') }} - name: Install protobuf compiler run: | sudo apt-get update From 48b28e54186fbd5b065ac8b0bd4fd4f7e79fbf80 Mon Sep 17 00:00:00 2001 From: aidan Date: Tue, 14 May 2024 14:19:25 +0200 Subject: [PATCH 44/48] ci: Update cache action version --- .github/workflows/ci.yaml | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a992bc8d8..47ce0117a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -55,21 +55,14 @@ jobs: steps: - uses: actions/checkout@v4 - name: Cache cargo registry - uses: actions/cache@v2 + uses: actions/cache@v3 with: - path: ~/.cargo/registry - key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.toml') }} - - name: Cache cargo index - uses: actions/cache@v2 - with: - path: ~/.cargo/git - key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.toml') }} - - name: Cache target directory - id: cache-target - uses: actions/cache@v2 - with: - path: target - key: ${{ runner.os }}-cargo-build-target2-${{ hashFiles('**/Cargo.toml') }} + path: | + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - name: Install protobuf compiler run: | sudo apt-get update From 5270d5291d3315c5635c0c2aa6c5e572c1f5411b Mon Sep 17 00:00:00 2001 From: aidan Date: Tue, 14 May 2024 14:20:47 +0200 Subject: [PATCH 45/48] ci: Change cache job name --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 47ce0117a..8ebae8753 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -54,7 +54,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Cache cargo registry + - name: Cargo caching uses: actions/cache@v3 with: path: | From c7b7df45d248654cc65cb4f7e971aaba6fbc59e5 Mon Sep 17 00:00:00 2001 From: aidan Date: Tue, 14 May 2024 14:29:33 +0200 Subject: [PATCH 46/48] ci: Add hash of lock file to cache action --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 8ebae8753..5831b0f0f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -62,7 +62,7 @@ jobs: ~/.cargo/registry/cache/ ~/.cargo/git/db/ target/ - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}-${{ hashFiles('**/Cargo.toml') }} - name: Install protobuf compiler run: | sudo apt-get update From 9d604dfa7fbfb52340656ebfbdf126cba5e43190 Mon Sep 17 00:00:00 2001 From: aidan Date: Tue, 14 May 2024 14:30:17 +0200 Subject: [PATCH 47/48] ci: Add caching of cargo bin --- .github/workflows/ci.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5831b0f0f..ea611bec8 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -58,6 +58,7 @@ jobs: uses: actions/cache@v3 with: path: | + ~/.cargo/bin/ ~/.cargo/registry/index/ ~/.cargo/registry/cache/ ~/.cargo/git/db/ From cda2f9a041eb551b2e08c77e3783dad2701acf8b Mon Sep 17 00:00:00 2001 From: aidan Date: Thu, 16 May 2024 11:14:23 +0200 Subject: [PATCH 48/48] ci: Add no deps flag to clippy --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ea611bec8..c143a1f0b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -78,7 +78,7 @@ jobs: cargo --version cargo clippy --version - name: Cargo clippy - run: cargo clippy --locked -q -- -D warnings + run: cargo clippy --locked -q --no-deps -- -D warnings - name: Build with try-runtime feature run: RUSTFLAGS="-D warnings" cargo build --locked -q --features try-runtime - name: Build node runtime