diff --git a/.github/workflows/benchmarks.yml b/.github/workflows/benchmarks.yml new file mode 100644 index 000000000..2329ce16a --- /dev/null +++ b/.github/workflows/benchmarks.yml @@ -0,0 +1,178 @@ +name: Header and RPC Benchmarks +on: + push: + branches: + - main + - develop + pull_request: + branches: + - main + - develop + workflow_dispatch: + +env: + CARGO_SCCACHE_COMMIT: bed5571c + +jobs: + benchmarks_iai: + runs-on: [self-hosted, reference] + env: + SKIP_WASM_BUILD: true + RUST_BACKTRACE: full + steps: + - uses: actions/checkout@v2 + + - uses: actions/cache@v3 + with: + path: | + ~/.cache/ + ~/.cargo/bin/sccache* + key: ${{ runner.OS }}-cache-iai-${{ env.CARGO_SCCACHE_COMMIT }}-v1 + + - name: Install system dependencies + # We force to reinstall `valgrind` because `codspeed` replaces that binary and the output + # of `valgrind.codspeed` generates a + + run: | + sudo apt-get update + sudo apt remove -y valgrind + sudo apt-get install -y build-essential pkg-config libssl-dev valgrind git clang curl libssl-dev protobuf-compiler unzip python3-pip + + - name: Setup Rust toolchain + run: | + curl https://sh.rustup.rs -sSf | sh -s -- -y + source "$HOME/.cargo/env" + rustup show + + - name: Set PATH for cargo + run: | + echo "$HOME/.cargo/bin" >> $GITHUB_PATH + echo "SCCACHE_DIR=${HOME}/.cache/sccache" >> $GITHUB_ENV + + - name: SCCache + run: | + # We altered the path to avoid old actions to overwrite it + if [ ! -f ~/.cargo/bin/sccache ]; then + cargo install sccache \ + --git https://github.com/purestake/sccache.git \ + --rev $CARGO_SCCACHE_COMMIT \ + --force --no-default-features --features=dist-client + fi + + if [[ -z `pgrep sccache` ]]; then + chmod +x ~/.cargo/bin/sccache + sccache --start-server + fi + sccache -s + echo "RUSTC_WRAPPER=${HOME}/.cargo/bin/sccache" >> $GITHUB_ENV + + - name: Run Header Generation Benchmarks on IAI + run: | + cargo uninstall --locked cargo-codspeed | true + which valgrind + sudo dpkg -S `which valgrind` + valgrind --version + mkdir -p ~/.cache/iai/ + cargo bench -p da-runtime --bench header_kate_commitment_iai | tee ~/.cache/iai/header_gen_bench_iai.txt || true + find ./runtime/target/iai -type f + + - name: Header Generation Regression Checks on IAI + uses: fmiguelgarcia/github-action-benchmark@v1 + with: + # What benchmark tool the output.txt came from + tool: 'rustIai' + # Where the output from the benchmark tool is stored + output-file-path: ~/.cache/iai/header_gen_bench_iai.txt + # Where the previous data file is stored + external-data-json-path: ~/.cache/iai/benchmark-data-iai.json + save-data-file: true + # Workflow will fail when an alert happens at 15% degradation + fail-on-alert: true + alert-threshold: '115%' + # Upload the updated cache file for the next job by actions/cache + github-token: ${{ secrets.GITHUB_TOKEN }} + # Enable alert commit comment + comment-on-alert: true + # Mention @rhysd in the commit comment + alert-comment-cc-users: '@prabal-banerjee,@jakubcech,@vthunder,@kroos47,@Leouarz,@markopoloparadox' + comment-always: true + summary-always: true + + benchmarks_cri: + runs-on: [self-hosted, reference] + env: + SKIP_WASM_BUILD: true + RUST_BACKTRACE: full + steps: + - uses: actions/checkout@v2 + + - uses: actions/cache@v3 + with: + path: | + ~/.cache/ + ~/.cargo/bin/sccache* + key: ${{ runner.OS }}-cache-cri-${{ env.CARGO_SCCACHE_COMMIT }}-v1 + + - name: Install system dependencies + run: | + sudo apt-get update + sudo apt-get install -y build-essential pkg-config libssl-dev valgrind git clang curl libssl-dev protobuf-compiler unzip python3-pip + + - name: Setup Rust toolchain + run: | + curl https://sh.rustup.rs -sSf | sh -s -- -y + source "$HOME/.cargo/env" + rustup show + + - name: Set PATH for cargo + run: | + echo "$HOME/.cargo/bin" >> $GITHUB_PATH + echo "SCCACHE_DIR=${HOME}/.cache/sccache" >> $GITHUB_ENV + + - name: SCCache + run: | + # We altered the path to avoid old actions to overwrite it + if [ ! -f ~/.cargo/bin/sccache ]; then + cargo install sccache \ + --git https://github.com/purestake/sccache.git \ + --rev $CARGO_SCCACHE_COMMIT \ + --force --no-default-features --features=dist-client + fi + + if [[ -z `pgrep sccache` ]]; then + chmod +x ~/.cargo/bin/sccache + sccache --start-server + fi + sccache -s + echo "RUSTC_WRAPPER=${HOME}/.cargo/bin/sccache" >> $GITHUB_ENV + + - name: Run Header Generation Benchmarks on Criterion + run: | + mkdir -p ~/.cache/cri/ + cargo bench -p da-runtime --bench header_kate_commitment_cri -- --color never --noplot --output-format bencher | tee ~/.cache/cri/header_gen_bench_cri.txt || true + + - name: Header Generation Regression Checks on Criterion + uses: fmiguelgarcia/github-action-benchmark@v1 + with: + # What benchmark tool the output.txt came from + tool: 'cargo' + # Where the output from the benchmark tool is stored + output-file-path: ~/.cache/cri/header_gen_bench_cri.txt + # Where the previous data file is stored + external-data-json-path: ~/.cache/cri/benchmark-data-cri.json + save-data-file: true + # Workflow will fail when an alert happens at 15% degradation + fail-on-alert: true + alert-threshold: '115%' + # Upload the updated cache file for the next job by actions/cache + github-token: ${{ secrets.GITHUB_TOKEN }} + # Enable alert commit comment + comment-on-alert: true + # Mention @rhysd in the commit comment + alert-comment-cc-users: '@prabal-banerjee,@jakubcech,@vthunder,@kroos47,@Leouarz,@markopoloparadox' + comment-always: true + summary-always: true + + - name: Display SCCache Stats + run: sccache --show-stats + diff --git a/.github/workflows/default.yml b/.github/workflows/default.yml index adcc5ceb3..9283ebb91 100644 --- a/.github/workflows/default.yml +++ b/.github/workflows/default.yml @@ -1,4 +1,4 @@ -name: Lint and Unit Tests +name: Lint and Features check on: push: branches: @@ -12,8 +12,6 @@ on: env: CARGO_SCCACHE_COMMIT: bed5571c - SCCACHE_DIR: /home/runner/.cache/cargo-sccache-bed5571c - SCCACHE_BIN: /home/runner/.cache/cargo-sccache-bed5571c/bin/sccache jobs: lint: @@ -56,13 +54,16 @@ jobs: - uses: actions/cache@v3 with: - path: ${{ env.SCCACHE_DIR }} + path: | + ~/.cache/ + ~/.cargo/bin/sccache* key: ${{ runner.OS }}-sccache-bin-${{ env.CARGO_SCCACHE_COMMIT }}-v1 - - name: Install Protoc - uses: arduino/setup-protoc@v1 - with: - version: "3.x" + - name: Install system dependencies + run: | + sudo apt-get update + sudo apt-get install -y build-essential pkg-config libssl-dev valgrind git clang curl libssl-dev protobuf-compiler unzip python3-pip + - name: Setup Rust toolchain run: | @@ -70,20 +71,27 @@ jobs: source "$HOME/.cargo/env" rustup show + - name: Set PATH for cargo + run: | + echo "$HOME/.cargo/bin" >> $GITHUB_PATH + echo "SCCACHE_DIR=${HOME}/.cache/sccache" >> $GITHUB_ENV + - name: SCCache run: | # We altered the path to avoid old actions to overwrite it - if [ ! -f $SCCACHE_BIN ]; then - cargo install sccache --git https://github.com/purestake/sccache.git --rev $CARGO_SCCACHE_COMMIT --force --no-default-features --features=dist-client --root $SCCACHE_DIR + if [ ! -f ~/.cargo/bin/sccache ]; then + cargo install sccache \ + --git https://github.com/purestake/sccache.git \ + --rev $CARGO_SCCACHE_COMMIT \ + --force --no-default-features --features=dist-client fi - ls -la $SCCACHE_BIN - ps aux | grep sccache + if [[ -z `pgrep sccache` ]]; then - chmod +x $SCCACHE_BIN - $SCCACHE_BIN --start-server + chmod +x ~/.cargo/bin/sccache + sccache --start-server fi - $SCCACHE_BIN -s - echo "RUSTC_WRAPPER=$SCCACHE_BIN" >> $GITHUB_ENV + sccache -s + echo "RUSTC_WRAPPER=${HOME}/.cargo/bin/sccache" >> $GITHUB_ENV - name: Build node run: cargo build --release -p data-avail @@ -95,38 +103,25 @@ jobs: path: target/release/data-avail - name: Display SCCache Stats - run: ${{ env.SCCACHE_BIN }} --show-stats + run: sccache --show-stats - - name: Check other features - run: cargo check --release --workspace --features "runtime-benchmarks try-runtime" -p data-avail - - unit_tests: + check_features: runs-on: ubuntu-latest needs: [build] steps: - uses: actions/checkout@v2 - - name: Free Disk Space (Ubuntu) - uses: jlumbroso/free-disk-space@main - with: - tool-cache: true - - - name: Install build-essential - run: | - sudo apt update - sudo apt install -y build-essential - sudo apt install -y git clang curl libssl-dev protobuf-compiler - - # Restore cache from `build` - uses: actions/cache/restore@v3 with: - path: ${{ env.SCCACHE_DIR }} - key: ${{ runner.OS }}-sccache-bin-${{ env.CARGO_SCCACHE_COMMIT }}-v1 + path: | + ~/.cache/ + ~/.cargo/bin/sccache* + key: ${{ runner.OS }}-cache-bin-${{ env.CARGO_SCCACHE_COMMIT }}-v1 - - name: Install Protoc - uses: arduino/setup-protoc@v1 - with: - version: "3.x" + - name: Install system dependencies + run: | + sudo apt-get update + sudo apt-get install -y build-essential pkg-config libssl-dev valgrind git clang curl libssl-dev protobuf-compiler unzip python3-pip - name: Setup Rust toolchain run: | @@ -134,32 +129,29 @@ jobs: source "$HOME/.cargo/env" rustup show + - name: Set PATH for cargo + run: | + echo "$HOME/.cargo/bin" >> $GITHUB_PATH + echo "SCCACHE_DIR=${HOME}/.cache/sccache" >> $GITHUB_ENV + - name: SCCache run: | # We altered the path to avoid old actions to overwrite it - if [ ! -f $SCCACHE_BIN ]; then - cargo install sccache --git https://github.com/purestake/sccache.git --rev $CARGO_SCCACHE_COMMIT --force --no-default-features --features=dist-client --root $SCCACHE_DIR + if [ ! -f ~/.cargo/bin/sccache ]; then + cargo install sccache \ + --git https://github.com/purestake/sccache.git \ + --rev $CARGO_SCCACHE_COMMIT \ + --force --no-default-features --features=dist-client fi - ls -la $SCCACHE_BIN - ps aux | grep sccache + if [[ -z `pgrep sccache` ]]; then - chmod +x $SCCACHE_BIN - $SCCACHE_BIN --start-server + chmod +x ~/.cargo/bin/sccache + sccache --start-server fi - $SCCACHE_BIN -s - echo "RUSTC_WRAPPER=$SCCACHE_BIN" >> $GITHUB_ENV + sccache -s + echo "RUSTC_WRAPPER=${HOME}/.cargo/bin/sccache" >> $GITHUB_ENV - - name: Run tests - run: | - env - cargo test --release --workspace - cargo test --release --manifest-path avail-subxt/Cargo.toml + - name: Check other features env: - RUSTFLAGS: "-C instrument-coverage" - LLVM_PROFILE_FILE: "profile-%p-%m.profraw" - - - name: Display SCCache Stats - run: ${{ env.SCCACHE_BIN }} --show-stats - - - name: Cleanup - run: find . -name \*.profraw -type f -exec rm -f {} + + SKIP_WASM_BUILD: true + run: cargo check --release --workspace --features "runtime-benchmarks try-runtime" -p data-avail diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 7bf23b715..4af6deef6 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -103,7 +103,7 @@ jobs: with: name: data-avail - - name: Run E2E SubXt tests + - name: Run Kate RPC E2E tests run: | chmod uog+x data-avail ./data-avail --dev & @@ -153,7 +153,7 @@ jobs: with: name: data-avail - - name: Run E2E SubXt tests + - name: Run SubXt E2E tests run: | chmod uog+x data-avail ./data-avail --dev & diff --git a/.github/workflows/releaser.yml b/.github/workflows/releaser.yml index bee90d740..ad3abf613 100644 --- a/.github/workflows/releaser.yml +++ b/.github/workflows/releaser.yml @@ -5,6 +5,7 @@ on: - '**' tags: - '*' + workflow_dispatch: jobs: binary_linux_amd64: diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml new file mode 100644 index 000000000..ec6916df7 --- /dev/null +++ b/.github/workflows/unit_tests.yml @@ -0,0 +1,157 @@ +name: Unit Tests +on: + push: + branches: + - main + - develop + pull_request: + branches: + - main + - develop + workflow_dispatch: + +env: + CARGO_SCCACHE_COMMIT: bed5571c + +jobs: + avail_unit_tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Free Disk Space (Ubuntu) + uses: jlumbroso/free-disk-space@main + with: + tool-cache: true + + - name: Install build-essential + run: | + sudo apt update + sudo apt install -y build-essential + sudo apt install -y git clang curl libssl-dev protobuf-compiler + + # Restore cache from `build` + - uses: actions/cache/restore@v3 + with: + path: | + ~/.cache/ + ~/.cargo/bin/sccache* + key: ${{ runner.OS }}-sccache-bin-${{ env.CARGO_SCCACHE_COMMIT }}-v1 + + - name: Install system dependencies + run: | + sudo apt-get update + sudo apt-get install -y build-essential pkg-config libssl-dev valgrind git clang curl libssl-dev protobuf-compiler unzip python3-pip + + - name: Setup Rust toolchain + run: | + curl https://sh.rustup.rs -sSf | sh -s -- -y + source "$HOME/.cargo/env" + rustup show + + - name: Set PATH for cargo + run: | + echo "$HOME/.cargo/bin" >> $GITHUB_PATH + echo "SCCACHE_DIR=${HOME}/.cache/sccache" >> $GITHUB_ENV + + - name: SCCache + run: | + # We altered the path to avoid old actions to overwrite it + if [ ! -f ~/.cargo/bin/sccache ]; then + cargo install sccache \ + --git https://github.com/purestake/sccache.git \ + --rev $CARGO_SCCACHE_COMMIT \ + --force --no-default-features --features=dist-client + fi + + if [[ -z `pgrep sccache` ]]; then + chmod +x ~/.cargo/bin/sccache + sccache --start-server + fi + sccache -s + echo "RUSTC_WRAPPER=${HOME}/.cargo/bin/sccache" >> $GITHUB_ENV + + - name: Run tests + run: | + env + cargo test --release --workspace + env: + RUSTFLAGS: "-C instrument-coverage" + LLVM_PROFILE_FILE: "profile-%p-%m.profraw" + + - name: Display SCCache Stats + run: sccache --show-stats + + - name: Cleanup + run: find . -name \*.profraw -type f -exec rm -f {} + + + subxt_unit_tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Free Disk Space (Ubuntu) + uses: jlumbroso/free-disk-space@main + with: + tool-cache: true + + - name: Install build-essential + run: | + sudo apt update + sudo apt install -y build-essential + sudo apt install -y git clang curl libssl-dev protobuf-compiler + + # Restore cache from `build` + - uses: actions/cache/restore@v3 + with: + path: | + ~/.cache/ + ~/.cargo/bin/sccache* + key: ${{ runner.OS }}-sccache-bin-${{ env.CARGO_SCCACHE_COMMIT }}-v1 + + - name: Install system dependencies + run: | + sudo apt-get update + sudo apt-get install -y build-essential pkg-config libssl-dev valgrind git clang curl libssl-dev protobuf-compiler unzip python3-pip + + - name: Setup Rust toolchain + run: | + curl https://sh.rustup.rs -sSf | sh -s -- -y + source "$HOME/.cargo/env" + rustup show + + - name: Set PATH for cargo + run: | + echo "$HOME/.cargo/bin" >> $GITHUB_PATH + echo "SCCACHE_DIR=${HOME}/.cache/sccache" >> $GITHUB_ENV + + - name: SCCache + run: | + # We altered the path to avoid old actions to overwrite it + if [ ! -f ~/.cargo/bin/sccache ]; then + cargo install sccache \ + --git https://github.com/purestake/sccache.git \ + --rev $CARGO_SCCACHE_COMMIT \ + --force --no-default-features --features=dist-client + fi + + if [[ -z `pgrep sccache` ]]; then + chmod +x ~/.cargo/bin/sccache + sccache --start-server + fi + sccache -s + echo "RUSTC_WRAPPER=${HOME}/.cargo/bin/sccache" >> $GITHUB_ENV + + - name: Run tests + run: | + env + cargo test --release --manifest-path avail-subxt/Cargo.toml + env: + RUSTFLAGS: "-C instrument-coverage" + LLVM_PROFILE_FILE: "profile-%p-%m.profraw" + + - name: Display SCCache Stats + run: sccache --show-stats + + - name: Cleanup + run: find . -name \*.profraw -type f -exec rm -f {} + diff --git a/.github/workflows/run-benchmarks.yml b/.github/workflows/weights.yml similarity index 95% rename from .github/workflows/run-benchmarks.yml rename to .github/workflows/weights.yml index a710f4075..1810cf16e 100644 --- a/.github/workflows/run-benchmarks.yml +++ b/.github/workflows/weights.yml @@ -1,4 +1,4 @@ -name: Run benchmarks +name: Run benchmarks for weights on: workflow_dispatch: @@ -6,10 +6,12 @@ on: extra: description: Run extra benchmark (commitment / dataroot) required: false + type: number default: 0 ourpallets: description: Benchmark only our pallet required: false + type: number default: 0 jobs: diff --git a/Cargo.lock b/Cargo.lock index a3d31c192..a98d3da28 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1234,18 +1234,6 @@ dependencies = [ "libloading", ] -[[package]] -name = "clap" -version = "3.2.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" -dependencies = [ - "bitflags 1.3.2", - "clap_lex 0.2.4", - "indexmap 1.9.3", - "textwrap", -] - [[package]] name = "clap" version = "4.4.7" @@ -1264,8 +1252,9 @@ checksum = "c77ed9a32a62e6ca27175d00d29d05ca32e396ea1eb5fb01d8256b669cec7663" dependencies = [ "anstream", "anstyle", - "clap_lex 0.6.0", + "clap_lex", "strsim", + "terminal_size", ] [[package]] @@ -1274,7 +1263,7 @@ version = "4.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bffe91f06a11b4b9420f62103854e90867812cd5d01557f853c5ee8e791b12ae" dependencies = [ - "clap 4.4.7", + "clap", ] [[package]] @@ -1289,15 +1278,6 @@ dependencies = [ "syn 2.0.38", ] -[[package]] -name = "clap_lex" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" -dependencies = [ - "os_str_bytes", -] - [[package]] name = "clap_lex" version = "0.6.0" @@ -1314,6 +1294,28 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "codspeed" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "918b13a0f1a32460ab3bd5debd56b5a27a7071fa5ff5dfeb3a5cf291a85b174b" +dependencies = [ + "colored", + "libc", + "serde_json", +] + +[[package]] +name = "codspeed-criterion-compat" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c683c7fef2b873fbbdf4062782914c652309951244bf0bd362fe608b7d6f901c" +dependencies = [ + "codspeed", + "colored", + "criterion", +] + [[package]] name = "coins-bip32" version = "0.7.0" @@ -1377,6 +1379,17 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" +[[package]] +name = "colored" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2674ec482fbc38012cf31e6c42ba0177b431a0cb6f15fe40efa5aab1bda516f6" +dependencies = [ + "is-terminal", + "lazy_static", + "windows-sys 0.48.0", +] + [[package]] name = "comfy-table" version = "7.1.0" @@ -1397,6 +1410,12 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "condtype" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf0a07a401f374238ab8e2f11a104d2851bf9ce711ec69804834de8af45c7af" + [[package]] name = "console" version = "0.15.7" @@ -1609,9 +1628,9 @@ dependencies = [ [[package]] name = "crc-catalog" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cace84e55f07e7301bae1c519df89cdad8cc3cd868413d3fdbdeca9ff3db484" +checksum = "4939f9ed1444bd8c896d37f3090012fa6e7834fe84ef8c9daa166109515732f9" [[package]] name = "crc32fast" @@ -1624,19 +1643,19 @@ dependencies = [ [[package]] name = "criterion" -version = "0.4.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7c76e09c1aae2bc52b3d2f29e13c6572553b30c4aa1b8a49fd70de6412654cb" +checksum = "f2b12d017a929603d80db1831cd3a24082f8137ce19c69e6447f54f5fc8d692f" dependencies = [ "anes", - "atty", "cast", "ciborium", - "clap 3.2.25", + "clap", "criterion-plot", + "is-terminal", "itertools 0.10.5", - "lazy_static", "num-traits", + "once_cell", "oorandom", "plotters", "rayon", @@ -1825,9 +1844,9 @@ dependencies = [ [[package]] name = "curve25519-dalek-derive" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83fdaf97f4804dcebfa5862639bc9ce4121e82140bec2a987ac5140294865b5b" +checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", @@ -1908,7 +1927,10 @@ name = "da-runtime" version = "7.0.0" dependencies = [ "avail-core", + "codspeed-criterion-compat", + "criterion", "da-control", + "divan", "env_logger 0.9.3", "frame-benchmarking", "frame-election-provider-support", @@ -1920,6 +1942,8 @@ dependencies = [ "frame-try-runtime", "hex", "hex-literal", + "iai", + "iai-callgrind", "kate", "log", "nomad-da-bridge", @@ -2028,7 +2052,7 @@ dependencies = [ "async-trait", "avail-base", "avail-core", - "clap 4.4.7", + "clap", "clap_complete", "da-control", "da-runtime", @@ -2361,6 +2385,30 @@ dependencies = [ "syn 2.0.38", ] +[[package]] +name = "divan" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fab20f5802e0b897093184f5dc5d23447fa715604f238dc798f6da188b230019" +dependencies = [ + "clap", + "condtype", + "divan-macros", + "linkme", + "regex-lite", +] + +[[package]] +name = "divan-macros" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c5d6354551e0b5c451a948814fc47fe745a14eac7835c087d60162661019db4" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.38", +] + [[package]] name = "downcast" version = "0.11.0" @@ -2388,9 +2436,9 @@ dependencies = [ [[package]] name = "dusk-bytes" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4aae12696d965c95ce5b79bc5612575e8aeac958c9e037b74ffa9e73e1cd8c7" +checksum = "d5d209b92f0741edf1d99369bd4c1a1ef2fd0a85e885220f9e3fb0df3c61337f" dependencies = [ "derive-hex", ] @@ -3022,7 +3070,7 @@ dependencies = [ "Inflector", "array-bytes", "chrono", - "clap 4.4.7", + "clap", "comfy-table", "frame-benchmarking", "frame-support", @@ -3911,6 +3959,44 @@ dependencies = [ "webpki-roots 0.25.2", ] +[[package]] +name = "iai" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71a816c97c42258aa5834d07590b718b4c9a598944cd39a52dc25b351185d678" + +[[package]] +name = "iai-callgrind" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2679de583a9f5232b45b1f3a31b5e2f739bccfee9b7902488aca8f8c2c5482d1" +dependencies = [ + "bincode", + "iai-callgrind-macros", + "iai-callgrind-runner", +] + +[[package]] +name = "iai-callgrind-macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af5af66b85e350097b8c0f6329c6347d3323d010443475741c29a1a167f116fb" +dependencies = [ + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.38", +] + +[[package]] +name = "iai-callgrind-runner" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12cc1093f263249d7c541c53849dac74f4ae756cd31e3cac1a12204efcec68bd" +dependencies = [ + "serde", +] + [[package]] name = "iana-time-zone" version = "0.1.58" @@ -4041,9 +4127,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.0.2" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" +checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" dependencies = [ "equivalent", "hashbrown 0.14.2", @@ -4189,9 +4275,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.64" +version = "0.3.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a" +checksum = "54c0c35952f67de54bb584e9fd912b3023117cbafc0a77d8f3dee1fb5f572fe8" dependencies = [ "wasm-bindgen", ] @@ -5044,6 +5130,26 @@ dependencies = [ "linked-hash-map", ] +[[package]] +name = "linkme" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ed2ee9464ff9707af8e9ad834cffa4802f072caad90639c583dd3c62e6e608" +dependencies = [ + "linkme-impl", +] + +[[package]] +name = "linkme-impl" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba125974b109d512fccbc6c0244e7580143e460895dfd6ea7f8bbb692fd94396" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.38", +] + [[package]] name = "linregress" version = "0.5.3" @@ -5946,12 +6052,6 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" -[[package]] -name = "os_str_bytes" -version = "6.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" - [[package]] name = "p256" version = "0.11.1" @@ -6857,7 +6957,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1d3afd2628e69da2be385eb6f2fd57c8ac7977ceeff6dc166ff1657b0e386a9" dependencies = [ "fixedbitset", - "indexmap 2.0.2", + "indexmap 2.1.0", ] [[package]] @@ -6926,9 +7026,9 @@ checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" [[package]] name = "platforms" -version = "3.1.2" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4503fa043bf02cee09a9582e9554b4c6403b2ef55e4612e96561d294419429f8" +checksum = "14e6ab3f592e6fb464fc9712d8d6e6912de6473954635fd76a589d832cffcbb0" [[package]] name = "plotters" @@ -7607,6 +7707,12 @@ dependencies = [ "regex-syntax 0.8.2", ] +[[package]] +name = "regex-lite" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30b661b2f27137bdbc16f00eda72866a92bb28af1753ffbd56744fb6e2e9cd8e" + [[package]] name = "regex-syntax" version = "0.6.29" @@ -8097,7 +8203,7 @@ source = "git+https://github.com/paritytech/substrate.git/?branch=polkadot-v1.0. dependencies = [ "array-bytes", "chrono", - "clap 4.4.7", + "clap", "fdlimit", "futures", "libp2p-identity", @@ -8825,7 +8931,7 @@ name = "sc-storage-monitor" version = "0.1.0" source = "git+https://github.com/paritytech/substrate.git/?branch=polkadot-v1.0.0#948fbd2fd1233dc26dbb9f9bbc1d2cca2c03945d" dependencies = [ - "clap 4.4.7", + "clap", "fs4", "log", "sc-client-db", @@ -10562,6 +10668,16 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "terminal_size" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21bebf2b7c9e0a515f6e0f8c51dc0f8e4696391e6f1ff30379559f8365fb0df7" +dependencies = [ + "rustix 0.38.21", + "windows-sys 0.48.0", +] + [[package]] name = "termtree" version = "0.4.1" @@ -10581,12 +10697,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "textwrap" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" - [[package]] name = "thiserror" version = "1.0.50" @@ -10858,7 +10968,7 @@ version = "0.19.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" dependencies = [ - "indexmap 2.0.2", + "indexmap 2.1.0", "serde", "serde_spanned", "toml_datetime", @@ -11079,7 +11189,7 @@ version = "0.10.0-dev" source = "git+https://github.com/paritytech/substrate.git/?branch=polkadot-v1.0.0#948fbd2fd1233dc26dbb9f9bbc1d2cca2c03945d" dependencies = [ "async-trait", - "clap 4.4.7", + "clap", "frame-remote-externalities", "frame-try-runtime", "hex", @@ -11370,9 +11480,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.87" +version = "0.2.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" +checksum = "7daec296f25a1bae309c0cd5c29c4b260e510e6d813c286b19eaadf409d40fce" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -11380,9 +11490,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.87" +version = "0.2.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" +checksum = "e397f4664c0e4e428e8313a469aaa58310d302159845980fd23b0f22a847f217" dependencies = [ "bumpalo", "log", @@ -11395,9 +11505,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.37" +version = "0.4.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c02dbc21516f9f1f04f187958890d7e6026df8d16540b7ad9492bc34a67cea03" +checksum = "9afec9963e3d0994cac82455b2b3502b81a7f40f9a0d32181f7528d9f4b43e02" dependencies = [ "cfg-if", "js-sys", @@ -11407,9 +11517,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.87" +version = "0.2.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" +checksum = "5961017b3b08ad5f3fe39f1e79877f8ee7c23c5e5fd5eb80de95abc41f1f16b2" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -11417,9 +11527,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.87" +version = "0.2.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" +checksum = "c5353b8dab669f5e10f5bd76df26a9360c748f054f862ff5f3f8aae0c7fb3907" dependencies = [ "proc-macro2", "quote", @@ -11430,9 +11540,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.87" +version = "0.2.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" +checksum = "0d046c5d029ba91a1ed14da14dca44b68bf2f124cfbaf741c54151fdb3e0750b" [[package]] name = "wasm-instrument" @@ -11705,9 +11815,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.64" +version = "0.3.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b" +checksum = "5db499c5f66323272151db0e666cd34f78617522fb0c1604d31a27c50c206a85" dependencies = [ "js-sys", "wasm-bindgen", @@ -12279,18 +12389,18 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.7.20" +version = "0.7.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd66a62464e3ffd4e37bd09950c2b9dd6c4f8767380fabba0d523f9a775bc85a" +checksum = "686b7e407015242119c33dab17b8f61ba6843534de936d94368856528eae4dcc" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.20" +version = "0.7.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "255c4596d41e6916ced49cfafea18727b24d67878fa180ddfd69b9df34fd1726" +checksum = "020f3dfe25dfc38dfea49ce62d5d45ecdd7f0d8a724fa63eb36b6eba4ec76806" dependencies = [ "proc-macro2", "quote", diff --git a/README.md b/README.md index 566c8125d..281b0cf2c 100644 --- a/README.md +++ b/README.md @@ -136,4 +136,5 @@ For additional documentation check our [wiki page](https://github.com/availproje There you can learn how to: - Run Avail Node together with Avail Light Clients - Build Avail Node for different Linux flavours -- Find out what node synchronization options are available \ No newline at end of file +- Find out what node synchronization options are available +- Running Avail Benchmarks \ No newline at end of file diff --git a/pallets/system/Cargo.toml b/pallets/system/Cargo.toml index 0c9848e61..f90f3a2ea 100644 --- a/pallets/system/Cargo.toml +++ b/pallets/system/Cargo.toml @@ -44,7 +44,7 @@ once_cell = { version = "1.18", optional = true } [dev-dependencies] hex-literal = "0.3.1" test-case = "1.2.3" -criterion = "0.4.0" +criterion = "0.5.1" sp-externalities = "0.19.0" [features] diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index a8cbeea65..66fa66ecc 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -116,11 +116,33 @@ serde_json = "1.0" sp-keyring = "24.0.0" env_logger = "0.9.1" pallet-staking-reward-fn = "4.0.0-dev" +iai = "0.1.1" +iai-callgrind = { version = "0.7.3" } +criterion = "0.5.1" +codspeed-criterion-compat = "2.2.0" +divan = "0.1.2" + +[[bench]] +name = "header_kate_commitment_iai_callgrind" +harness = false + +[[bench]] +name = "header_kate_commitment_iai" +harness = false + +[[bench]] +name = "header_kate_commitment_cri" +harness = false + +[[bench]] +name = "header_kate_commitment_divan" +harness = false [features] default = [ "std" ] with-tracing = [ "frame-executive/with-tracing" ] fast-runtime = [] +codspeed = [] header_commitment_corruption = [ "frame-system/header_commitment_corruption" ] std = [ "avail-core/std", diff --git a/runtime/benches/header_kate_commitment.rs b/runtime/benches/header_kate_commitment.rs new file mode 100644 index 000000000..f62e27bc8 --- /dev/null +++ b/runtime/benches/header_kate_commitment.rs @@ -0,0 +1,40 @@ +use avail_core::{AppExtrinsic, BlockLengthColumns, BLOCK_CHUNK_SIZE, NORMAL_DISPATCH_RATIO}; +use da_control::Config as DAConfig; +use da_runtime::Runtime; +use frame_support::traits::Get as _; +use frame_system::{header_builder::hosted_header_builder, limits::BlockLength}; +use sp_core::H256; +use sp_std::iter::repeat; + +#[allow(dead_code)] +fn make_txs(cols: BlockLengthColumns) -> Vec { + let data_length: u32 = ::MaxAppDataLength::get(); + let rows = ::MaxBlockRows::get().0; + + let mut nb_tx = 4; // Value set depending on MaxAppDataLength (512 kb) to reach 2 mb + let max_tx: u32 = + rows * cols.0 * (BLOCK_CHUNK_SIZE.get().checked_sub(2).unwrap()) / data_length; + if nb_tx > max_tx { + nb_tx = max_tx; + } + + let data: Vec = repeat(b'X') + .take(usize::try_from(data_length).unwrap()) + .collect::>(); + vec![AppExtrinsic::from(data); nb_tx as usize] +} + +#[allow(dead_code)] +fn block_length(cols: BlockLengthColumns) -> BlockLength { + let rows = ::MaxBlockRows::get(); + BlockLength::with_normal_ratio(rows, cols, BLOCK_CHUNK_SIZE, NORMAL_DISPATCH_RATIO).unwrap() +} + +#[allow(dead_code)] +fn commitment_builder_with(txs: Vec, block_length: BlockLength) { + let seed = [0u8; 32]; + let root = H256::zero(); + let block_number: u32 = 0; + + let _ = hosted_header_builder::build(txs, root, block_length, block_number, seed); +} diff --git a/runtime/benches/header_kate_commitment_cri.rs b/runtime/benches/header_kate_commitment_cri.rs new file mode 100644 index 000000000..c2da4496d --- /dev/null +++ b/runtime/benches/header_kate_commitment_cri.rs @@ -0,0 +1,39 @@ +use core::time::Duration; + +#[cfg(feature = "codspeed")] +use codspeed_criterion_compat::{ + criterion_group, criterion_main, BenchmarkId, Criterion, Throughput, +}; +#[cfg(not(feature = "codspeed"))] +use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; + +include!("header_kate_commitment.rs"); + +fn commitment_builder(c: &mut Criterion) { + let mut group = c.benchmark_group("commitment_builder"); + for columns in [32, 64, 128, 256].iter() { + let block_columns = BlockLengthColumns(*columns); + let block_length = block_length(block_columns); + let txs = make_txs(block_columns); + + group.throughput(Throughput::Elements(*columns as u64)); + group.bench_with_input( + BenchmarkId::from_parameter(block_columns), + &txs, + |b, txs| { + b.iter_batched( + || (txs.clone(), block_length.clone()), + |(txs, block_len)| commitment_builder_with(txs, block_len), + criterion::BatchSize::SmallInput, + ); + }, + ); + } + group.finish(); +} + +criterion_group!( + name = benches; + config = Criterion::default().sample_size(10).measurement_time( Duration::from_secs(60) ); + targets = commitment_builder); +criterion_main!(benches); diff --git a/runtime/benches/header_kate_commitment_divan.rs b/runtime/benches/header_kate_commitment_divan.rs new file mode 100644 index 000000000..494e3e215 --- /dev/null +++ b/runtime/benches/header_kate_commitment_divan.rs @@ -0,0 +1,25 @@ +include!("header_kate_commitment.rs"); +use divan; + +fn main() { + divan::main(); +} + +mod commitment_builder { + use super::*; + + fn setup(cols: BlockLengthColumns) -> (Vec, BlockLength) { + let txs = make_txs(cols); + let block_length = block_length(cols); + (txs, block_length) + } + + #[divan::bench(max_time = 120.0, consts = [ 32, 64, 128, 256 ])] + fn columns_count(bencher: divan::Bencher) { + bencher + .with_inputs(|| setup(BlockLengthColumns(N))) + .bench_values(|input| { + commitment_builder_with(input.0, input.1); + }) + } +} diff --git a/runtime/benches/header_kate_commitment_iai.rs b/runtime/benches/header_kate_commitment_iai.rs new file mode 100644 index 000000000..198c6dfdd --- /dev/null +++ b/runtime/benches/header_kate_commitment_iai.rs @@ -0,0 +1,25 @@ +include!("header_kate_commitment.rs"); + +fn commitment_builder(cols: BlockLengthColumns) { + let txs = make_txs(cols); + let block_length = block_length(cols); + + commitment_builder_with(txs, block_length); +} + +fn commitment_builder_32() { + commitment_builder(BlockLengthColumns(32)); +} + +fn commitment_builder_64() { + commitment_builder(BlockLengthColumns(64)); +} + +fn commitment_builder_128() { + commitment_builder(BlockLengthColumns(128)); +} +fn commitment_builder_256() { + commitment_builder(BlockLengthColumns(256)); +} + +iai::main! {commitment_builder_32, commitment_builder_64, commitment_builder_128, commitment_builder_256 } diff --git a/runtime/benches/header_kate_commitment_iai_callgrind.rs b/runtime/benches/header_kate_commitment_iai_callgrind.rs new file mode 100644 index 000000000..1b9b17052 --- /dev/null +++ b/runtime/benches/header_kate_commitment_iai_callgrind.rs @@ -0,0 +1,25 @@ +include!("header_kate_commitment.rs"); +use iai_callgrind::{black_box, library_benchmark, library_benchmark_group, main}; + +fn setup(cols: u32) -> (Vec, BlockLength) { + let txs = make_txs(BlockLengthColumns(cols)); + let block_length = block_length(BlockLengthColumns(cols)); + + (txs, block_length) +} + +#[library_benchmark] +#[bench::columns_32(setup(32))] +#[bench::columns_64(setup(64))] +#[bench::columns_128(setup(128))] +#[bench::columns_256(setup(256))] +fn commitment_builder(input: (Vec, BlockLength)) { + black_box(commitment_builder_with(input.0, input.1)); +} + +library_benchmark_group!( + name = commitment_builder_group; + benchmarks = commitment_builder +); + +main!(library_benchmark_groups = commitment_builder_group,);