From 0433c4d218ceb0dedd195a0a6049b144a9edf845 Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Tue, 22 Apr 2025 10:51:05 -0700 Subject: [PATCH 01/45] Update benchmark_all.sh --- scripts/benchmark_all.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/benchmark_all.sh b/scripts/benchmark_all.sh index cfdd1e9672..96b4b7c841 100755 --- a/scripts/benchmark_all.sh +++ b/scripts/benchmark_all.sh @@ -10,6 +10,8 @@ pallets=( RUNTIME_WASM=./target/production/wbuild/node-subtensor-runtime/node_subtensor_runtime.compact.compressed.wasm +mkdir -p bench_results + cargo build \ --profile production \ -p node-subtensor \ @@ -28,5 +30,8 @@ for pallet in "${pallets[@]}"; do --pallet "$pallet" \ --extrinsic "*" \ --steps 50 \ - --repeat 5 + --repeat 5 \ + | tee bench_results/"$pallet".txt done + +echo "All benchmarks complete. Outputs in bench_results/." \ No newline at end of file From 06bae130cf3e58fbe205d73f18646671a9ca7aa7 Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Tue, 22 Apr 2025 10:51:12 -0700 Subject: [PATCH 02/45] Create run-benchmarks.yml --- .github/workflows/run-benchmarks.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .github/workflows/run-benchmarks.yml diff --git a/.github/workflows/run-benchmarks.yml b/.github/workflows/run-benchmarks.yml new file mode 100644 index 0000000000..92d61748ff --- /dev/null +++ b/.github/workflows/run-benchmarks.yml @@ -0,0 +1,14 @@ + - name: Run benchmarks (via your script) + run: | + chmod +x scripts/benchmark_all.sh + mkdir -p bench_results + # run your script, redirecting its full output + ./scripts/benchmark_all.sh > bench_results/all.txt + + - name: Validate benchmark weights + run: | + if ! git diff --exit-code -- bench_results; then + echo "::error ::Benchmark weights have changed!" + echo "::error ::Please review and commit updated bench_results/ files." + exit 1 + fi From acc47b80576e4585ef415da847e7d8293bd27a59 Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Tue, 22 Apr 2025 11:52:47 -0700 Subject: [PATCH 03/45] revert benchmark_all change --- scripts/benchmark_all.sh | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/scripts/benchmark_all.sh b/scripts/benchmark_all.sh index 96b4b7c841..22d23483f3 100755 --- a/scripts/benchmark_all.sh +++ b/scripts/benchmark_all.sh @@ -10,8 +10,6 @@ pallets=( RUNTIME_WASM=./target/production/wbuild/node-subtensor-runtime/node_subtensor_runtime.compact.compressed.wasm -mkdir -p bench_results - cargo build \ --profile production \ -p node-subtensor \ @@ -30,8 +28,5 @@ for pallet in "${pallets[@]}"; do --pallet "$pallet" \ --extrinsic "*" \ --steps 50 \ - --repeat 5 \ - | tee bench_results/"$pallet".txt -done - -echo "All benchmarks complete. Outputs in bench_results/." \ No newline at end of file + --repeat 5 +done \ No newline at end of file From 0d7206313c18d639fe7a68309c740b6a2dd9cc1a Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Tue, 22 Apr 2025 20:05:25 -0700 Subject: [PATCH 04/45] Create benchmark_action.sh --- scripts/benchmark_action.sh | 112 ++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100755 scripts/benchmark_action.sh diff --git a/scripts/benchmark_action.sh b/scripts/benchmark_action.sh new file mode 100755 index 0000000000..e285fdeee7 --- /dev/null +++ b/scripts/benchmark_action.sh @@ -0,0 +1,112 @@ +#!/usr/bin/env bash +set -euo pipefail + +THRESHOLD=10 +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +DISPATCH="$SCRIPT_DIR/../pallets/subtensor/src/macros/dispatches.rs" +RUNTIME_WASM="./target/production/wbuild/node-subtensor-runtime/node_subtensor_runtime.compact.compressed.wasm" + +if [[ ! -f "$DISPATCH" ]]; then + echo "❌ ERROR: dispatches.rs not found at $DISPATCH" + exit 1 +fi + +echo "Building runtime-benchmarks…" +cargo build --profile production -p node-subtensor --features runtime-benchmarks + +echo +echo "──────────────────────────────────────────" +echo " Running pallet_subtensor benchmarks…" +echo "──────────────────────────────────────────" + +TMP="$(mktemp)"; trap 'rm -f "$TMP"' EXIT + +./target/production/node-subtensor benchmark pallet \ + --runtime "$RUNTIME_WASM" \ + --genesis-builder=runtime \ + --genesis-builder-preset=benchmark \ + --wasm-execution=compiled \ + --pallet pallet_subtensor \ + --extrinsic "*" \ + --steps 50 \ + --repeat 5 \ +| tee "$TMP" + +fail=0 +declare -a failures +extr="" + +while IFS= read -r line; do + # detect a new benchmark block + if [[ $line =~ Extrinsic:\ \"benchmark_([[:alnum:]_]+)\" ]]; then + extr="${BASH_REMATCH[1]}" + continue + fi + + # only process the first "Time ~=" line per extrinsic + if [[ $line =~ Time\ ~=\ *([0-9]+(\.[0-9]+)?) ]]; then + [[ -z "$extr" ]] && continue + + meas_us="${BASH_REMATCH[1]}" + + # convert microseconds → picoseconds + meas_ps=$(awk -v u="$meas_us" 'BEGIN { printf("%.0f", u * 1000000) }') + + # extract the hard-coded ps literal for this extrinsic + code_w=$( + awk -v extr="$extr" ' + /^\s*#\[pallet::call_index\([0-9]+\)\]/ { w=""; next } + /Weight::from_parts/ { + lw=$0 + sub(/.*Weight::from_parts\(\s*/, "", lw) + sub(/[^0-9_].*$/, "", lw) + gsub(/_/, "", lw) + w=lw + next + } + $0 ~ ("pub fn[[:space:]]+" extr "[[:space:]]*\\(") { + print w + exit + } + ' "$DISPATCH" + ) + + if [[ -z "$code_w" ]]; then + echo "::error ::[${extr}] ❌ could not extract code-weight" + failures+=("[${extr}] missing code-weight") + fail=1 + extr="" + continue + fi + + # compute drift percentage + drift=$(awk -v a="$meas_ps" -v b="$code_w" 'BEGIN { printf("%.1f", (a-b)/b*100) }') + abs_drift=$(awk -v d="$drift" 'BEGIN { if (d<0) d=-d; printf("%.1f", d) }') + + # flag if outside threshold + too_big=$(awk -v d="$abs_drift" -v t="$THRESHOLD" 'BEGIN { print (d>t) ? 1 : 0 }') + + if [[ "$too_big" -eq 1 ]]; then + echo "::error ::[${extr}] code=${code_w}, meas_ps=${meas_ps}, drift=${drift}% (>±${THRESHOLD}%)" + failures+=("[${extr}] code=${code_w}, meas_ps=${meas_ps}, drift=${drift}%") + fail=1 + else + echo "[ok] ${extr}: drift ${drift}% (code=${code_w}, meas_ps=${meas_ps})" + fi + + # clear extr so we only handle one Time~= per block + extr="" + fi +done < "$TMP" + +echo +if (( fail )); then + echo "❌ Benchmark regressions detected:" + for e in "${failures[@]}"; do + echo " • $e" + done + exit 1 +else + echo "✅ All benchmarks within ±${THRESHOLD}%." + exit 0 +fi From ba16a0e890e0b890ebd8d56d5efd2174297508cc Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Tue, 22 Apr 2025 20:05:32 -0700 Subject: [PATCH 05/45] Update run-benchmarks.yml --- .github/workflows/run-benchmarks.yml | 49 +++++++++++++++++++++------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/.github/workflows/run-benchmarks.yml b/.github/workflows/run-benchmarks.yml index 92d61748ff..98d335fa5f 100644 --- a/.github/workflows/run-benchmarks.yml +++ b/.github/workflows/run-benchmarks.yml @@ -1,14 +1,41 @@ - - name: Run benchmarks (via your script) +# .github/workflows/benchmark-weights.yml +name: Benchmark Weights + +on: + pull_request: + workflow_dispatch: + +concurrency: + group: benchmark-weights-${{ github.ref }} + cancel-in-progress: true + +jobs: + benchmark-weights: + runs-on: SubtensorCI + steps: + - uses: actions/checkout@v4 + + - name: Install system dependencies run: | - chmod +x scripts/benchmark_all.sh - mkdir -p bench_results - # run your script, redirecting its full output - ./scripts/benchmark_all.sh > bench_results/all.txt + sudo apt-get update + sudo apt-get install -y clang curl libssl-dev llvm libudev-dev protobuf-compiler - - name: Validate benchmark weights + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + + - name: Cache Rust build + uses: Swatinem/rust-cache@v2 + with: + key: bench-${{ hashFiles('**/Cargo.lock') }} + + - name: Build node with benchmarks run: | - if ! git diff --exit-code -- bench_results; then - echo "::error ::Benchmark weights have changed!" - echo "::error ::Please review and commit updated bench_results/ files." - exit 1 - fi + cargo build --profile production -p node-subtensor --features runtime-benchmarks + + - name: Run & validate benchmarks + run: | + chmod +x scripts/benchmark_all.sh + ./scripts/benchmark_all.sh From 8c81059e5e894470ef4f69cc9c7fc90e909f135d Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Tue, 22 Apr 2025 20:22:37 -0700 Subject: [PATCH 06/45] benchmarks --- .github/workflows/run-benchmarks.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/run-benchmarks.yml b/.github/workflows/run-benchmarks.yml index 98d335fa5f..0101264a60 100644 --- a/.github/workflows/run-benchmarks.yml +++ b/.github/workflows/run-benchmarks.yml @@ -1,12 +1,12 @@ -# .github/workflows/benchmark-weights.yml -name: Benchmark Weights +# .github/workflows/benchmarks.yml +name: Benchmarks on: pull_request: workflow_dispatch: concurrency: - group: benchmark-weights-${{ github.ref }} + group: benchmarks-${{ github.ref }} cancel-in-progress: true jobs: From d02d955f808d9369a00825e137c45c4473c2c49d Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Tue, 22 Apr 2025 20:25:46 -0700 Subject: [PATCH 07/45] rename action to run-benchmarks --- .github/workflows/run-benchmarks.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/run-benchmarks.yml b/.github/workflows/run-benchmarks.yml index 0101264a60..3171aabaed 100644 --- a/.github/workflows/run-benchmarks.yml +++ b/.github/workflows/run-benchmarks.yml @@ -1,16 +1,16 @@ # .github/workflows/benchmarks.yml -name: Benchmarks +name: Run-Benchmarks on: pull_request: workflow_dispatch: concurrency: - group: benchmarks-${{ github.ref }} + group: run-benchmarks-${{ github.ref }} cancel-in-progress: true jobs: - benchmark-weights: + run-benchmarks: runs-on: SubtensorCI steps: - uses: actions/checkout@v4 From 23e3ce38bf4353a3b8c469bc436a2fd702791792 Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Tue, 22 Apr 2025 20:55:36 -0700 Subject: [PATCH 08/45] benchmark_action --- .github/workflows/run-benchmarks.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/run-benchmarks.yml b/.github/workflows/run-benchmarks.yml index 3171aabaed..aac74ae0cc 100644 --- a/.github/workflows/run-benchmarks.yml +++ b/.github/workflows/run-benchmarks.yml @@ -37,5 +37,5 @@ jobs: - name: Run & validate benchmarks run: | - chmod +x scripts/benchmark_all.sh - ./scripts/benchmark_all.sh + chmod +x scripts/benchmark_action.sh + ./scripts/benchmark_action.sh From 64d5af24b9bb72a3734c9659dce736f38b8190ee Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Tue, 22 Apr 2025 21:38:45 -0700 Subject: [PATCH 09/45] update set_weights weight --- pallets/subtensor/src/macros/dispatches.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index 4ea03c957b..7bd4aebe39 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -77,7 +77,7 @@ mod dispatches { /// * 'MaxWeightExceeded': /// - Attempting to set weights with max value exceeding limit. #[pallet::call_index(0)] - #[pallet::weight((Weight::from_parts(22_060_000_000, 0) + #[pallet::weight((Weight::from_parts(20_730_000_000, 0) .saturating_add(T::DbWeight::get().reads(4106)) .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))] pub fn set_weights( From d39a8d33fc79832d58e0a5cd1aa14a46b1be7bb1 Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Wed, 23 Apr 2025 08:21:56 -0700 Subject: [PATCH 10/45] remove zero weights --- pallets/subtensor/src/macros/dispatches.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index 7bd4aebe39..99da0b52b1 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -620,7 +620,7 @@ mod dispatches { /// #[pallet::call_index(3)] #[pallet::weight((Weight::from_parts(111_000_000, 0) - .saturating_add(Weight::from_parts(0, 43991)) + .saturating_add(Weight::from_parts(111_100_000, 43991)) .saturating_add(T::DbWeight::get().reads(10)) .saturating_add(T::DbWeight::get().writes(7)), DispatchClass::Normal, Pays::No))] pub fn remove_stake( @@ -906,7 +906,7 @@ mod dispatches { /// Attempt to adjust the senate membership to include a hotkey #[pallet::call_index(63)] - #[pallet::weight((Weight::from_parts(0, 0) + #[pallet::weight((Weight::from_parts(111_100_000, 0) .saturating_add(T::DbWeight::get().reads(0)) .saturating_add(T::DbWeight::get().writes(0)), DispatchClass::Normal, Pays::Yes))] pub fn adjust_senate(origin: OriginFor, hotkey: T::AccountId) -> DispatchResult { @@ -956,7 +956,7 @@ mod dispatches { /// Weight is calculated based on the number of database reads and writes. #[pallet::call_index(71)] #[pallet::weight((Weight::from_parts(127_713_000, 0) - .saturating_add(Weight::from_parts(0, 11645)) + .saturating_add(Weight::from_parts(111_100_000, 11645)) .saturating_add(T::DbWeight::get().reads(18)) .saturating_add(T::DbWeight::get().writes(12)), DispatchClass::Operational, Pays::No))] pub fn swap_coldkey( @@ -1119,7 +1119,7 @@ mod dispatches { /// ## Complexity /// - O(1). #[pallet::call_index(51)] - #[pallet::weight((Weight::from_parts(0, 0), DispatchClass::Operational, Pays::No))] + #[pallet::weight((Weight::from_parts(111_100_000, 0), DispatchClass::Operational, Pays::No))] pub fn sudo( origin: OriginFor, call: Box, @@ -1166,8 +1166,7 @@ mod dispatches { /// User vote on a proposal #[pallet::call_index(55)] - #[pallet::weight((Weight::from_parts(0, 0) - .saturating_add(Weight::from_parts(0, 0)) + #[pallet::weight((Weight::from_parts(111_100_000, 0) .saturating_add(T::DbWeight::get().reads(0)) .saturating_add(T::DbWeight::get().writes(0)), DispatchClass::Operational))] pub fn vote( @@ -1818,7 +1817,7 @@ mod dispatches { /// #[pallet::call_index(89)] #[pallet::weight((Weight::from_parts(111_000_000, 0) - .saturating_add(Weight::from_parts(0, 43991)) + .saturating_add(Weight::from_parts(111_100_000, 43991)) .saturating_add(T::DbWeight::get().reads(10)) .saturating_add(T::DbWeight::get().writes(7)), DispatchClass::Normal, Pays::No))] pub fn remove_stake_limit( From 721500055b401460f68bdb19104a205cb9b1cbcf Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Wed, 23 Apr 2025 09:04:22 -0700 Subject: [PATCH 11/45] remove zero weights --- pallets/subtensor/src/macros/dispatches.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index 99da0b52b1..029ae8a461 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -498,7 +498,9 @@ mod dispatches { /// - The delegate is setting a take which is not lower than the previous. /// #[pallet::call_index(65)] - #[pallet::weight((0, DispatchClass::Normal, Pays::No))] + #[pallet::weight((Weight::from_parts(79_000_000, 0) + .saturating_add(T::DbWeight::get().reads(6)) + .saturating_add(T::DbWeight::get().writes(3)), DispatchClass::Normal, Pays::No))] pub fn decrease_take( origin: OriginFor, hotkey: T::AccountId, @@ -538,7 +540,9 @@ mod dispatches { /// - The delegate is setting a take which is not greater than the previous. /// #[pallet::call_index(66)] - #[pallet::weight((0, DispatchClass::Normal, Pays::No))] + #[pallet::weight((Weight::from_parts(79_000_000, 0) + .saturating_add(T::DbWeight::get().reads(6)) + .saturating_add(T::DbWeight::get().writes(3)), DispatchClass::Normal, Pays::No))] pub fn increase_take( origin: OriginFor, hotkey: T::AccountId, From 61115be8ecf85e45f4d825d9e7daf60745f10377 Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Wed, 23 Apr 2025 09:20:55 -0700 Subject: [PATCH 12/45] update weights based on CI results --- pallets/subtensor/src/macros/dispatches.rs | 64 +++++++++++----------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index 029ae8a461..2a9aacd7b5 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -120,7 +120,7 @@ mod dispatches { /// - On failure for each failed item in the batch. /// #[pallet::call_index(80)] - #[pallet::weight((Weight::from_parts(22_060_000_000, 0) + #[pallet::weight((Weight::from_parts(105_100_000, 0) .saturating_add(T::DbWeight::get().reads(4106)) .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))] pub fn batch_set_weights( @@ -186,7 +186,7 @@ mod dispatches { /// - On failure for each failed item in the batch. /// #[pallet::call_index(100)] - #[pallet::weight((Weight::from_parts(46_000_000, 0) + #[pallet::weight((Weight::from_parts(89_380_000, 0) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))] pub fn batch_commit_weights( @@ -279,7 +279,7 @@ mod dispatches { /// - Attempting to commit when the user has more than the allowed limit of unrevealed commits. /// #[pallet::call_index(99)] - #[pallet::weight((Weight::from_parts(46_000_000, 0) + #[pallet::weight((Weight::from_parts(73_720_000, 0) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Normal, Pays::No))] pub fn commit_crv3_weights( @@ -413,7 +413,7 @@ mod dispatches { /// - Attempting to set weights with max value exceeding limit. /// #[pallet::call_index(8)] - #[pallet::weight((Weight::from_parts(10_151_000_000, 0) + #[pallet::weight((Weight::from_parts(4_068_000, 0) .saturating_add(T::DbWeight::get().reads(4104)) .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))] pub fn set_tao_weights( @@ -454,7 +454,7 @@ mod dispatches { /// - The hotkey we are delegating is not owned by the calling coldket. /// #[pallet::call_index(1)] - #[pallet::weight((Weight::from_parts(79_000_000, 0) + #[pallet::weight((Weight::from_parts(4_428_000, 0) .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(3)), DispatchClass::Normal, Pays::No))] pub fn become_delegate(_origin: OriginFor, _hotkey: T::AccountId) -> DispatchResult { @@ -582,7 +582,7 @@ mod dispatches { /// - Errors stemming from transaction pallet. /// #[pallet::call_index(2)] - #[pallet::weight((Weight::from_parts(124_000_000, 0) + #[pallet::weight((Weight::from_parts(151_000_000, 0) .saturating_add(T::DbWeight::get().reads(10)) .saturating_add(T::DbWeight::get().writes(7)), DispatchClass::Normal, Pays::No))] pub fn add_stake( @@ -623,8 +623,7 @@ mod dispatches { /// - Thrown if there is not enough stake on the hotkey to withdwraw this amount. /// #[pallet::call_index(3)] - #[pallet::weight((Weight::from_parts(111_000_000, 0) - .saturating_add(Weight::from_parts(111_100_000, 43991)) + #[pallet::weight((Weight::from_parts(196_800_000, 0) .saturating_add(T::DbWeight::get().reads(10)) .saturating_add(T::DbWeight::get().writes(7)), DispatchClass::Normal, Pays::No))] pub fn remove_stake( @@ -688,7 +687,7 @@ mod dispatches { /// - Attempting to set prometheus information withing the rate limit min. /// #[pallet::call_index(4)] - #[pallet::weight((Weight::from_parts(46_000_000, 0) + #[pallet::weight((Weight::from_parts(35_670_000, 0) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Normal, Pays::No))] pub fn serve_axon( @@ -772,7 +771,7 @@ mod dispatches { /// - Attempting to set prometheus information withing the rate limit min. /// #[pallet::call_index(40)] - #[pallet::weight((Weight::from_parts(46_000_000, 0) + #[pallet::weight((Weight::from_parts(33_890_000, 0) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Normal, Pays::No))] pub fn serve_axon_tls( @@ -822,7 +821,7 @@ mod dispatches { /// - The ip type v4 or v6. /// #[pallet::call_index(5)] - #[pallet::weight((Weight::from_parts(45_000_000, 0) + #[pallet::weight((Weight::from_parts(31_170_000, 0) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Normal, Pays::No))] pub fn serve_prometheus( @@ -910,7 +909,7 @@ mod dispatches { /// Attempt to adjust the senate membership to include a hotkey #[pallet::call_index(63)] - #[pallet::weight((Weight::from_parts(111_100_000, 0) + #[pallet::weight((Weight::from_parts(68_100_000, 0) .saturating_add(T::DbWeight::get().reads(0)) .saturating_add(T::DbWeight::get().writes(0)), DispatchClass::Normal, Pays::Yes))] pub fn adjust_senate(origin: OriginFor, hotkey: T::AccountId) -> DispatchResult { @@ -919,7 +918,7 @@ mod dispatches { /// User register a new subnetwork via burning token #[pallet::call_index(7)] - #[pallet::weight((Weight::from_parts(177_000_000, 0) + #[pallet::weight((Weight::from_parts(219_400_000, 0) .saturating_add(T::DbWeight::get().reads(26)) .saturating_add(T::DbWeight::get().writes(24)), DispatchClass::Normal, Pays::No))] pub fn burned_register( @@ -932,7 +931,7 @@ mod dispatches { /// The extrinsic for user to change its hotkey #[pallet::call_index(70)] - #[pallet::weight((Weight::from_parts(1_940_000_000, 0) + #[pallet::weight((Weight::from_parts(240_600_000, 0) .saturating_add(T::DbWeight::get().reads(272)) .saturating_add(T::DbWeight::get().writes(527)), DispatchClass::Operational, Pays::No))] pub fn swap_hotkey( @@ -1007,7 +1006,7 @@ mod dispatches { /// #[pallet::call_index(75)] #[pallet::weight(( - Weight::from_parts(34_000, 0) + Weight::from_parts(49_470_000, 0) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, @@ -1040,7 +1039,7 @@ mod dispatches { /// #[pallet::call_index(69)] #[pallet::weight(( - Weight::from_parts(6_000, 0) + Weight::from_parts(6_873_000, 0) .saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Operational, Pays::No @@ -1185,7 +1184,7 @@ mod dispatches { /// User register a new subnetwork #[pallet::call_index(59)] - #[pallet::weight((Weight::from_parts(157_000_000, 0) + #[pallet::weight((Weight::from_parts(260_500_000, 0) .saturating_add(T::DbWeight::get().reads(16)) .saturating_add(T::DbWeight::get().writes(30)), DispatchClass::Operational, Pays::No))] pub fn register_network(origin: OriginFor, hotkey: T::AccountId) -> DispatchResult { @@ -1452,7 +1451,7 @@ mod dispatches { /// - The ip type v4 or v6. /// #[pallet::call_index(68)] - #[pallet::weight((Weight::from_parts(45_000_000, 0) + #[pallet::weight((Weight::from_parts(32_340_000, 0) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Normal, Pays::Yes))] pub fn set_identity( @@ -1494,7 +1493,7 @@ mod dispatches { /// * `subnet_contact` (Vec): /// - The contact information for the subnet. #[pallet::call_index(78)] - #[pallet::weight((Weight::from_parts(45_000_000, 0) + #[pallet::weight((Weight::from_parts(23_080_000, 0) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Normal, Pays::Yes))] pub fn set_subnet_identity( @@ -1523,7 +1522,7 @@ mod dispatches { /// User register a new subnetwork #[pallet::call_index(79)] - #[pallet::weight((Weight::from_parts(157_000_000, 0) + #[pallet::weight((Weight::from_parts(239_700_000, 0) .saturating_add(T::DbWeight::get().reads(16)) .saturating_add(T::DbWeight::get().writes(30)), DispatchClass::Operational, Pays::No))] pub fn register_network_with_identity( @@ -1560,7 +1559,7 @@ mod dispatches { /// * `TxRateLimitExceeded`: /// - Thrown if key has hit transaction rate limit #[pallet::call_index(83)] - #[pallet::weight((Weight::from_parts(3_000_000, 0).saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Operational, Pays::No))] + #[pallet::weight((Weight::from_parts(36_200_000, 0).saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Operational, Pays::No))] pub fn unstake_all(origin: OriginFor, hotkey: T::AccountId) -> DispatchResult { Self::do_unstake_all(origin, hotkey) } @@ -1591,7 +1590,7 @@ mod dispatches { /// * `TxRateLimitExceeded`: /// - Thrown if key has hit transaction rate limit #[pallet::call_index(84)] - #[pallet::weight((Weight::from_parts(3_000_000, 0).saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Operational, Pays::No))] + #[pallet::weight((Weight::from_parts(68_730_000, 0).saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Operational, Pays::No))] pub fn unstake_all_alpha(origin: OriginFor, hotkey: T::AccountId) -> DispatchResult { Self::do_unstake_all_alpha(origin, hotkey) } @@ -1618,7 +1617,7 @@ mod dispatches { /// - The alpha stake amount to move. /// #[pallet::call_index(85)] - #[pallet::weight((Weight::from_parts(3_000_000, 0).saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Operational, Pays::No))] + #[pallet::weight((Weight::from_parts(196_600_000, 0).saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Operational, Pays::No))] pub fn move_stake( origin: T::RuntimeOrigin, origin_hotkey: T::AccountId, @@ -1659,7 +1658,7 @@ mod dispatches { /// # Events /// May emit a `StakeTransferred` event on success. #[pallet::call_index(86)] - #[pallet::weight((Weight::from_parts(3_000_000, 0).saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Operational, Pays::No))] + #[pallet::weight((Weight::from_parts(207_300_000, 0).saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Operational, Pays::No))] pub fn transfer_stake( origin: T::RuntimeOrigin, destination_coldkey: T::AccountId, @@ -1699,7 +1698,7 @@ mod dispatches { /// May emit a `StakeSwapped` event on success. #[pallet::call_index(87)] #[pallet::weight(( - Weight::from_parts(3_000_000, 0).saturating_add(T::DbWeight::get().writes(1)), + Weight::from_parts(190_100_000, 0).saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Operational, Pays::No ))] @@ -1759,7 +1758,7 @@ mod dispatches { /// - Errors stemming from transaction pallet. /// #[pallet::call_index(88)] - #[pallet::weight((Weight::from_parts(124_000_000, 0) + #[pallet::weight((Weight::from_parts(91_010_000, 0) .saturating_add(T::DbWeight::get().reads(10)) .saturating_add(T::DbWeight::get().writes(7)), DispatchClass::Normal, Pays::No))] pub fn add_stake_limit( @@ -1820,8 +1819,7 @@ mod dispatches { /// - Thrown if there is not enough stake on the hotkey to withdwraw this amount. /// #[pallet::call_index(89)] - #[pallet::weight((Weight::from_parts(111_000_000, 0) - .saturating_add(Weight::from_parts(111_100_000, 43991)) + #[pallet::weight((Weight::from_parts(172_100_000, 0) .saturating_add(T::DbWeight::get().reads(10)) .saturating_add(T::DbWeight::get().writes(7)), DispatchClass::Normal, Pays::No))] pub fn remove_stake_limit( @@ -1865,7 +1863,7 @@ mod dispatches { /// May emit a `StakeSwapped` event on success. #[pallet::call_index(90)] #[pallet::weight(( - Weight::from_parts(3_000_000, 0).saturating_add(T::DbWeight::get().writes(1)), + Weight::from_parts(162_400_000, 0).saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Operational, Pays::No ))] @@ -1899,7 +1897,7 @@ mod dispatches { /// Will charge based on the weight even if the hotkey is already associated with a coldkey. #[pallet::call_index(91)] #[pallet::weight(( - Weight::from_parts(3_000_000, 0).saturating_add(T::DbWeight::get().reads_writes(3, 3)), + Weight::from_parts(32_560_000, 0).saturating_add(T::DbWeight::get().reads_writes(3, 3)), DispatchClass::Operational, Pays::Yes ))] @@ -1924,7 +1922,7 @@ mod dispatches { /// Emits a `FirstEmissionBlockNumberSet` event on success. #[pallet::call_index(92)] #[pallet::weight(( - Weight::from_parts(3_000_000, 0).saturating_add(T::DbWeight::get().reads_writes(6, 1)), + Weight::from_parts(35_770_000, 0).saturating_add(T::DbWeight::get().reads_writes(6, 1)), DispatchClass::Operational, Pays::Yes ))] @@ -1989,7 +1987,7 @@ mod dispatches { /// Emits a `TokensRecycled` event on success. #[pallet::call_index(101)] #[pallet::weight(( - Weight::from_parts(3_000_000, 0).saturating_add(T::DbWeight::get().reads_writes(3, 2)), + Weight::from_parts(99_260_000, 0).saturating_add(T::DbWeight::get().reads_writes(3, 2)), DispatchClass::Operational, Pays::Yes ))] @@ -2014,7 +2012,7 @@ mod dispatches { /// Emits a `TokensBurned` event on success. #[pallet::call_index(102)] #[pallet::weight(( - Weight::from_parts(2_000_000, 0).saturating_add(T::DbWeight::get().reads_writes(2, 1)), + Weight::from_parts(98_010_000, 0).saturating_add(T::DbWeight::get().reads_writes(2, 1)), DispatchClass::Operational, Pays::Yes ))] From d76810393572e66d562c7cf0cfd5283b37d0dfc7 Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Wed, 23 Apr 2025 09:53:28 -0700 Subject: [PATCH 13/45] Update weights --- pallets/subtensor/src/macros/dispatches.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index 2a9aacd7b5..67f3402a5c 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -498,7 +498,7 @@ mod dispatches { /// - The delegate is setting a take which is not lower than the previous. /// #[pallet::call_index(65)] - #[pallet::weight((Weight::from_parts(79_000_000, 0) + #[pallet::weight((Weight::from_parts(37_380_000, 0) .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(3)), DispatchClass::Normal, Pays::No))] pub fn decrease_take( @@ -540,7 +540,7 @@ mod dispatches { /// - The delegate is setting a take which is not greater than the previous. /// #[pallet::call_index(66)] - #[pallet::weight((Weight::from_parts(79_000_000, 0) + #[pallet::weight((Weight::from_parts(44_630_000, 0) .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(3)), DispatchClass::Normal, Pays::No))] pub fn increase_take( @@ -900,7 +900,7 @@ mod dispatches { /// Register the hotkey to root network #[pallet::call_index(62)] - #[pallet::weight((Weight::from_parts(164_000_000, 0) + #[pallet::weight((Weight::from_parts(145_500_000, 0) .saturating_add(T::DbWeight::get().reads(23)) .saturating_add(T::DbWeight::get().writes(20)), DispatchClass::Normal, Pays::No))] pub fn root_register(origin: OriginFor, hotkey: T::AccountId) -> DispatchResult { From e909c18356353fbf878f3bfc87235d48d30363b9 Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Wed, 23 Apr 2025 10:31:00 -0700 Subject: [PATCH 14/45] bump CI From 5b0c215eb0754f57fb4dd5620d780adbf04cd226 Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Wed, 23 Apr 2025 11:02:23 -0700 Subject: [PATCH 15/45] fix action --- .github/workflows/run-benchmarks.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/run-benchmarks.yml b/.github/workflows/run-benchmarks.yml index aac74ae0cc..c3b280d3d2 100644 --- a/.github/workflows/run-benchmarks.yml +++ b/.github/workflows/run-benchmarks.yml @@ -13,7 +13,11 @@ jobs: run-benchmarks: runs-on: SubtensorCI steps: - - uses: actions/checkout@v4 + - name: Checkout PR branch, not merged commit + uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + fetch-depth: 0 - name: Install system dependencies run: | From fae4d1410b823e4d24ef8cc17817a5dd1bc12157 Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Wed, 23 Apr 2025 11:09:28 -0700 Subject: [PATCH 16/45] Update run-benchmarks.yml --- .github/workflows/run-benchmarks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-benchmarks.yml b/.github/workflows/run-benchmarks.yml index c3b280d3d2..9983151a91 100644 --- a/.github/workflows/run-benchmarks.yml +++ b/.github/workflows/run-benchmarks.yml @@ -13,7 +13,7 @@ jobs: run-benchmarks: runs-on: SubtensorCI steps: - - name: Checkout PR branch, not merged commit + - name: Checkout PR branch uses: actions/checkout@v4 with: ref: ${{ github.head_ref }} From 2051da8c4b3bc9f58bc8a33f5d5b3fb402971d35 Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Wed, 23 Apr 2025 11:37:18 -0700 Subject: [PATCH 17/45] update weight --- pallets/subtensor/src/macros/dispatches.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index 67f3402a5c..a11d4affc1 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -1987,7 +1987,7 @@ mod dispatches { /// Emits a `TokensRecycled` event on success. #[pallet::call_index(101)] #[pallet::weight(( - Weight::from_parts(99_260_000, 0).saturating_add(T::DbWeight::get().reads_writes(3, 2)), + Weight::from_parts(115_300_000, 0).saturating_add(T::DbWeight::get().reads_writes(3, 2)), DispatchClass::Operational, Pays::Yes ))] From 5ca27286722e60e58e51501cbcaf126514682fd0 Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Wed, 23 Apr 2025 11:37:31 -0700 Subject: [PATCH 18/45] update benchmark action logs --- scripts/benchmark_action.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/benchmark_action.sh b/scripts/benchmark_action.sh index e285fdeee7..f34b23edde 100755 --- a/scripts/benchmark_action.sh +++ b/scripts/benchmark_action.sh @@ -87,11 +87,11 @@ while IFS= read -r line; do too_big=$(awk -v d="$abs_drift" -v t="$THRESHOLD" 'BEGIN { print (d>t) ? 1 : 0 }') if [[ "$too_big" -eq 1 ]]; then - echo "::error ::[${extr}] code=${code_w}, meas_ps=${meas_ps}, drift=${drift}% (>±${THRESHOLD}%)" - failures+=("[${extr}] code=${code_w}, meas_ps=${meas_ps}, drift=${drift}%") + echo "::error ::[${extr}] code=${code_w}, measured=${meas_ps}, drift=${drift}%" + failures+=("[${extr}] code=${code_w}, measured=${meas_ps}, drift=${drift}%") fail=1 else - echo "[ok] ${extr}: drift ${drift}% (code=${code_w}, meas_ps=${meas_ps})" + echo "[ok] ${extr}: drift ${drift}% (code=${code_w}, measured=${meas_ps})" fi # clear extr so we only handle one Time~= per block @@ -101,7 +101,7 @@ done < "$TMP" echo if (( fail )); then - echo "❌ Benchmark regressions detected:" + echo "❌ Benchmark drift detected:" for e in "${failures[@]}"; do echo " • $e" done From 46b8efd1a9aff4a095afe3adfdbaf2c9ec2c15c9 Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Wed, 23 Apr 2025 12:11:24 -0700 Subject: [PATCH 19/45] update weight --- pallets/subtensor/src/macros/dispatches.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index a11d4affc1..9846fee4f9 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -1987,7 +1987,7 @@ mod dispatches { /// Emits a `TokensRecycled` event on success. #[pallet::call_index(101)] #[pallet::weight(( - Weight::from_parts(115_300_000, 0).saturating_add(T::DbWeight::get().reads_writes(3, 2)), + Weight::from_parts(101_000_000, 0).saturating_add(T::DbWeight::get().reads_writes(3, 2)), DispatchClass::Operational, Pays::Yes ))] From d6a4bc2802c1425cd90422bb79029d08f07b88fa Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Wed, 23 Apr 2025 13:39:24 -0700 Subject: [PATCH 20/45] update reads/writes --- pallets/subtensor/src/macros/dispatches.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index 9846fee4f9..0c491dcc96 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -884,8 +884,8 @@ mod dispatches { /// #[pallet::call_index(6)] #[pallet::weight((Weight::from_parts(192_000_000, 0) - .saturating_add(T::DbWeight::get().reads(24)) - .saturating_add(T::DbWeight::get().writes(22)), DispatchClass::Normal, Pays::No))] + .saturating_add(T::DbWeight::get().reads(26)) + .saturating_add(T::DbWeight::get().writes(23)), DispatchClass::Normal, Pays::No))] pub fn register( origin: OriginFor, netuid: u16, From d6d45851dd3b26a92082e458698a186e945279ca Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Wed, 23 Apr 2025 13:39:44 -0700 Subject: [PATCH 21/45] check reads/writes in benchmark_action --- scripts/benchmark_action.sh | 96 ++++++++++++++++++------------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/scripts/benchmark_action.sh b/scripts/benchmark_action.sh index f34b23edde..7d749e98a6 100755 --- a/scripts/benchmark_action.sh +++ b/scripts/benchmark_action.sh @@ -19,8 +19,8 @@ echo "──────────────────────── echo " Running pallet_subtensor benchmarks…" echo "──────────────────────────────────────────" -TMP="$(mktemp)"; trap 'rm -f "$TMP"' EXIT - +TMP="$(mktemp)" +trap 'rm -f "$TMP"' EXIT ./target/production/node-subtensor benchmark pallet \ --runtime "$RUNTIME_WASM" \ --genesis-builder=runtime \ @@ -32,81 +32,81 @@ TMP="$(mktemp)"; trap 'rm -f "$TMP"' EXIT --repeat 5 \ | tee "$TMP" +declare -a summary_lines=() +declare -a failures=() fail=0 -declare -a failures extr="" while IFS= read -r line; do - # detect a new benchmark block + # Detect new extrinsic if [[ $line =~ Extrinsic:\ \"benchmark_([[:alnum:]_]+)\" ]]; then extr="${BASH_REMATCH[1]}" continue fi - # only process the first "Time ~=" line per extrinsic + # Capture first timing line if [[ $line =~ Time\ ~=\ *([0-9]+(\.[0-9]+)?) ]]; then [[ -z "$extr" ]] && continue meas_us="${BASH_REMATCH[1]}" + meas_ps=$(awk -v u="$meas_us" 'BEGIN{printf("%.0f", u * 1000000)}') - # convert microseconds → picoseconds - meas_ps=$(awk -v u="$meas_us" 'BEGIN { printf("%.0f", u * 1000000) }') + # Grab Reads/Writes + meas_reads="" meas_writes="" + while IFS= read -r sub; do + [[ $sub =~ Reads[[:space:]]*=[[:space:]]*([0-9]+) ]] && meas_reads="${BASH_REMATCH[1]}" && continue + [[ $sub =~ Writes[[:space:]]*=[[:space:]]*([0-9]+) ]] && meas_writes="${BASH_REMATCH[1]}" && break + done - # extract the hard-coded ps literal for this extrinsic - code_w=$( + # Extract code values from dispatches.rs + code_record=$( awk -v extr="$extr" ' - /^\s*#\[pallet::call_index\([0-9]+\)\]/ { w=""; next } - /Weight::from_parts/ { - lw=$0 - sub(/.*Weight::from_parts\(\s*/, "", lw) - sub(/[^0-9_].*$/, "", lw) - gsub(/_/, "", lw) - w=lw - next - } - $0 ~ ("pub fn[[:space:]]+" extr "[[:space:]]*\\(") { - print w - exit - } + /^\s*#\[pallet::call_index\(/ { next } + /Weight::from_parts/ { lw=$0; sub(/.*Weight::from_parts\(\s*/, "", lw); sub(/[^0-9_].*$/, "", lw); gsub(/_/, "", lw); w=lw; next } + /reads_writes\(/ { lw=$0; sub(/.*reads_writes\(/, "", lw); sub(/\).*/, "", lw); split(lw,io,/,/); gsub(/^[ \t]+|[ \t]+$/, "", io[1]); gsub(/^[ \t]+|[ \t]+$/, "", io[2]); r=io[1]; wri=io[2]; next } + /\.reads\(/ { lw=$0; sub(/.*\.reads\(/, "", lw); sub(/\).*/, "", lw); r=lw; next } + /\.writes\(/ { lw=$0; sub(/.*\.writes\(/, "", lw); sub(/\).*/, "", lw); wri=lw; next } + $0 ~ ("pub fn[[:space:]]+" extr "[[:space:]]*\\(") { print w, r, wri; exit } ' "$DISPATCH" ) + read code_w code_reads code_writes <<<"$code_record" + + # Calculate drift + drift=$(awk -v a="$meas_ps" -v b="$code_w" 'BEGIN{printf("%.1f", (a-b)/b*100)}') + + # Store formatted summary + summary_lines+=("$(printf "%-30s | reads code=%3s meas=%3s | writes code=%3s meas=%3s | weight code=%12s meas=%12s | drift %6s%%" \ + "$extr" "$code_reads" "$meas_reads" "$code_writes" "$meas_writes" "$code_w" "$meas_ps" "$drift")") + + # Validation checks + [[ -z "$code_w" ]] && failures+=("[${extr}] missing code weight") && fail=1 + [[ -z "$meas_reads" ]] && failures+=("[${extr}] missing measured reads") && fail=1 + [[ -z "$meas_writes" ]] && failures+=("[${extr}] missing measured writes") && fail=1 + (( meas_reads != code_reads )) && failures+=("[${extr}] reads mismatch code=${code_reads}, meas=${meas_reads}") && fail=1 + (( meas_writes != code_writes )) && failures+=("[${extr}] writes mismatch code=${code_writes}, meas=${meas_writes}") && fail=1 + [[ "$code_w" == "0" ]] && failures+=("[${extr}] zero code weight") && fail=1 + abs_drift=$(awk -v d="$drift" 'BEGIN{if(d<0)d=-d;printf("%.1f",d)}') + (( $(awk -v d="$abs_drift" -v t="$THRESHOLD" 'BEGIN{print d>t}') )) && failures+=("[${extr}] drift ${drift}%") && fail=1 - if [[ -z "$code_w" ]]; then - echo "::error ::[${extr}] ❌ could not extract code-weight" - failures+=("[${extr}] missing code-weight") - fail=1 - extr="" - continue - fi - - # compute drift percentage - drift=$(awk -v a="$meas_ps" -v b="$code_w" 'BEGIN { printf("%.1f", (a-b)/b*100) }') - abs_drift=$(awk -v d="$drift" 'BEGIN { if (d<0) d=-d; printf("%.1f", d) }') - - # flag if outside threshold - too_big=$(awk -v d="$abs_drift" -v t="$THRESHOLD" 'BEGIN { print (d>t) ? 1 : 0 }') - - if [[ "$too_big" -eq 1 ]]; then - echo "::error ::[${extr}] code=${code_w}, measured=${meas_ps}, drift=${drift}%" - failures+=("[${extr}] code=${code_w}, measured=${meas_ps}, drift=${drift}%") - fail=1 - else - echo "[ok] ${extr}: drift ${drift}% (code=${code_w}, measured=${meas_ps})" - fi - - # clear extr so we only handle one Time~= per block extr="" fi done < "$TMP" echo +echo "Benchmark Summary:" +for l in "${summary_lines[@]}"; do + echo "$l" +done + if (( fail )); then - echo "❌ Benchmark drift detected:" + echo + echo "❌ Detected issues:" for e in "${failures[@]}"; do echo " • $e" done exit 1 else - echo "✅ All benchmarks within ±${THRESHOLD}%." + echo + echo "✅ All benchmarks within ±${THRESHOLD}% drift." exit 0 fi From e41ce59db44b62bc41fc867cf9c238c936dc1c44 Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Wed, 23 Apr 2025 13:41:05 -0700 Subject: [PATCH 22/45] update logs --- scripts/benchmark_action.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/benchmark_action.sh b/scripts/benchmark_action.sh index 7d749e98a6..7598e8bf32 100755 --- a/scripts/benchmark_action.sh +++ b/scripts/benchmark_action.sh @@ -75,15 +75,15 @@ while IFS= read -r line; do drift=$(awk -v a="$meas_ps" -v b="$code_w" 'BEGIN{printf("%.1f", (a-b)/b*100)}') # Store formatted summary - summary_lines+=("$(printf "%-30s | reads code=%3s meas=%3s | writes code=%3s meas=%3s | weight code=%12s meas=%12s | drift %6s%%" \ + summary_lines+=("$(printf "%-30s | reads code=%3s measured=%3s | writes code=%3s measured=%3s | weight code=%12s measured=%12s | drift %6s%%" \ "$extr" "$code_reads" "$meas_reads" "$code_writes" "$meas_writes" "$code_w" "$meas_ps" "$drift")") # Validation checks [[ -z "$code_w" ]] && failures+=("[${extr}] missing code weight") && fail=1 [[ -z "$meas_reads" ]] && failures+=("[${extr}] missing measured reads") && fail=1 [[ -z "$meas_writes" ]] && failures+=("[${extr}] missing measured writes") && fail=1 - (( meas_reads != code_reads )) && failures+=("[${extr}] reads mismatch code=${code_reads}, meas=${meas_reads}") && fail=1 - (( meas_writes != code_writes )) && failures+=("[${extr}] writes mismatch code=${code_writes}, meas=${meas_writes}") && fail=1 + (( meas_reads != code_reads )) && failures+=("[${extr}] reads mismatch code=${code_reads}, measured=${meas_reads}") && fail=1 + (( meas_writes != code_writes )) && failures+=("[${extr}] writes mismatch code=${code_writes}, measured=${meas_writes}") && fail=1 [[ "$code_w" == "0" ]] && failures+=("[${extr}] zero code weight") && fail=1 abs_drift=$(awk -v d="$drift" 'BEGIN{if(d<0)d=-d;printf("%.1f",d)}') (( $(awk -v d="$abs_drift" -v t="$THRESHOLD" 'BEGIN{print d>t}') )) && failures+=("[${extr}] drift ${drift}%") && fail=1 From 9d00e29d41d07c1fde6a28dc9db481c343c365d3 Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Wed, 23 Apr 2025 14:33:00 -0700 Subject: [PATCH 23/45] better script checking and logs --- scripts/benchmark_action.sh | 53 ++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/scripts/benchmark_action.sh b/scripts/benchmark_action.sh index 7598e8bf32..4d7f4bfc26 100755 --- a/scripts/benchmark_action.sh +++ b/scripts/benchmark_action.sh @@ -1,11 +1,15 @@ #!/usr/bin/env bash set -euo pipefail +# Max allowed drift (%) THRESHOLD=10 + +# Resolve script paths SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" DISPATCH="$SCRIPT_DIR/../pallets/subtensor/src/macros/dispatches.rs" RUNTIME_WASM="./target/production/wbuild/node-subtensor-runtime/node_subtensor_runtime.compact.compressed.wasm" +# Sanity check if [[ ! -f "$DISPATCH" ]]; then echo "❌ ERROR: dispatches.rs not found at $DISPATCH" exit 1 @@ -19,8 +23,7 @@ echo "──────────────────────── echo " Running pallet_subtensor benchmarks…" echo "──────────────────────────────────────────" -TMP="$(mktemp)" -trap 'rm -f "$TMP"' EXIT +TMP="$(mktemp)"; trap "rm -f \"$TMP\" \"$THRESHOLD\"" EXIT ./target/production/node-subtensor benchmark pallet \ --runtime "$RUNTIME_WASM" \ --genesis-builder=runtime \ @@ -38,55 +41,61 @@ fail=0 extr="" while IFS= read -r line; do - # Detect new extrinsic + # detect new extrinsic if [[ $line =~ Extrinsic:\ \"benchmark_([[:alnum:]_]+)\" ]]; then extr="${BASH_REMATCH[1]}" continue fi - # Capture first timing line + # first timing line if [[ $line =~ Time\ ~=\ *([0-9]+(\.[0-9]+)?) ]]; then [[ -z "$extr" ]] && continue meas_us="${BASH_REMATCH[1]}" meas_ps=$(awk -v u="$meas_us" 'BEGIN{printf("%.0f", u * 1000000)}') - # Grab Reads/Writes + # grab reads & writes meas_reads="" meas_writes="" while IFS= read -r sub; do [[ $sub =~ Reads[[:space:]]*=[[:space:]]*([0-9]+) ]] && meas_reads="${BASH_REMATCH[1]}" && continue [[ $sub =~ Writes[[:space:]]*=[[:space:]]*([0-9]+) ]] && meas_writes="${BASH_REMATCH[1]}" && break done - # Extract code values from dispatches.rs + # extract code-side values code_record=$( awk -v extr="$extr" ' - /^\s*#\[pallet::call_index\(/ { next } - /Weight::from_parts/ { lw=$0; sub(/.*Weight::from_parts\(\s*/, "", lw); sub(/[^0-9_].*$/, "", lw); gsub(/_/, "", lw); w=lw; next } - /reads_writes\(/ { lw=$0; sub(/.*reads_writes\(/, "", lw); sub(/\).*/, "", lw); split(lw,io,/,/); gsub(/^[ \t]+|[ \t]+$/, "", io[1]); gsub(/^[ \t]+|[ \t]+$/, "", io[2]); r=io[1]; wri=io[2]; next } - /\.reads\(/ { lw=$0; sub(/.*\.reads\(/, "", lw); sub(/\).*/, "", lw); r=lw; next } - /\.writes\(/ { lw=$0; sub(/.*\.writes\(/, "", lw); sub(/\).*/, "", lw); wri=lw; next } - $0 ~ ("pub fn[[:space:]]+" extr "[[:space:]]*\\(") { print w, r, wri; exit } + /^\s*#\[pallet::call_index\(/ { next } + /Weight::from_parts/ { lw=$0; sub(/.*Weight::from_parts\(\s*/, "", lw); sub(/[^0-9_].*$/, "", lw); gsub(/_/, "", lw); w=lw; next } + /reads_writes\(/ { lw=$0; sub(/.*reads_writes\(/, "", lw); sub(/\).*/, "", lw); split(lw,io,/,/); gsub(/^[ \t]+|[ \t]+$/, "", io[1]); gsub(/^[ \t]+|[ \t]+$/, "", io[2]); r=io[1]; wri=io[2]; next } + /\.reads\(/ { lw=$0; sub(/.*\.reads\(/, "", lw); sub(/\).*/, "", lw); r=lw; next } + /\.writes\(/ { lw=$0; sub(/.*\.writes\(/, "", lw); sub(/\).*/, "", lw); wri=lw; next } + $0 ~ ("pub fn[[:space:]]+" extr "\\(") { print w, r, wri; exit } ' "$DISPATCH" ) read code_w code_reads code_writes <<<"$code_record" - # Calculate drift + # compute drift % drift=$(awk -v a="$meas_ps" -v b="$code_w" 'BEGIN{printf("%.1f", (a-b)/b*100)}') - # Store formatted summary + # build formatted summary line summary_lines+=("$(printf "%-30s | reads code=%3s measured=%3s | writes code=%3s measured=%3s | weight code=%12s measured=%12s | drift %6s%%" \ "$extr" "$code_reads" "$meas_reads" "$code_writes" "$meas_writes" "$code_w" "$meas_ps" "$drift")") - # Validation checks - [[ -z "$code_w" ]] && failures+=("[${extr}] missing code weight") && fail=1 - [[ -z "$meas_reads" ]] && failures+=("[${extr}] missing measured reads") && fail=1 - [[ -z "$meas_writes" ]] && failures+=("[${extr}] missing measured writes") && fail=1 - (( meas_reads != code_reads )) && failures+=("[${extr}] reads mismatch code=${code_reads}, measured=${meas_reads}") && fail=1 + # validations + [[ -z "$code_w" ]] && failures+=("[${extr}] missing code weight") && fail=1 + [[ -z "$meas_reads" ]] && failures+=("[${extr}] missing measured reads") && fail=1 + [[ -z "$meas_writes" ]] && failures+=("[${extr}] missing measured writes") && fail=1 + (( meas_reads != code_reads )) && failures+=("[${extr}] reads mismatch code=${code_reads}, measured=${meas_reads}") && fail=1 (( meas_writes != code_writes )) && failures+=("[${extr}] writes mismatch code=${code_writes}, measured=${meas_writes}") && fail=1 - [[ "$code_w" == "0" ]] && failures+=("[${extr}] zero code weight") && fail=1 - abs_drift=$(awk -v d="$drift" 'BEGIN{if(d<0)d=-d;printf("%.1f",d)}') - (( $(awk -v d="$abs_drift" -v t="$THRESHOLD" 'BEGIN{print d>t}') )) && failures+=("[${extr}] drift ${drift}%") && fail=1 + [[ "$code_w" == "0" ]] && failures+=("[${extr}] zero code weight") && fail=1 + + # drift check: strip sign & decimals, then compare integer part + abs_drift=${drift#-} + drift_int=${abs_drift%%.*} + if (( drift_int > THRESHOLD )); then + failures+=("[${extr}] weight code=${code_w}, measured=${meas_ps}, drift=${drift}%") + fail=1 + fi extr="" fi From 9c0c309701131d5c3cbaab018659bb06056aadfe Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Wed, 23 Apr 2025 14:35:21 -0700 Subject: [PATCH 24/45] update some reads/writes --- pallets/subtensor/src/macros/dispatches.rs | 25 +++++++++++----------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index 0c491dcc96..9254e3f42e 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -78,7 +78,7 @@ mod dispatches { /// - Attempting to set weights with max value exceeding limit. #[pallet::call_index(0)] #[pallet::weight((Weight::from_parts(20_730_000_000, 0) - .saturating_add(T::DbWeight::get().reads(4106)) + .saturating_add(T::DbWeight::get().reads(4111)) .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))] pub fn set_weights( origin: OriginFor, @@ -455,8 +455,8 @@ mod dispatches { /// #[pallet::call_index(1)] #[pallet::weight((Weight::from_parts(4_428_000, 0) - .saturating_add(T::DbWeight::get().reads(6)) - .saturating_add(T::DbWeight::get().writes(3)), DispatchClass::Normal, Pays::No))] + .saturating_add(T::DbWeight::get().reads(0)) + .saturating_add(T::DbWeight::get().writes(0)), DispatchClass::Normal, Pays::No))] pub fn become_delegate(_origin: OriginFor, _hotkey: T::AccountId) -> DispatchResult { // DEPRECATED // Self::do_become_delegate(origin, hotkey, Self::get_default_delegate_take()) @@ -583,8 +583,8 @@ mod dispatches { /// #[pallet::call_index(2)] #[pallet::weight((Weight::from_parts(151_000_000, 0) - .saturating_add(T::DbWeight::get().reads(10)) - .saturating_add(T::DbWeight::get().writes(7)), DispatchClass::Normal, Pays::No))] + .saturating_add(T::DbWeight::get().reads(14)) + .saturating_add(T::DbWeight::get().writes(10)), DispatchClass::Normal, Pays::No))] pub fn add_stake( origin: OriginFor, hotkey: T::AccountId, @@ -624,8 +624,8 @@ mod dispatches { /// #[pallet::call_index(3)] #[pallet::weight((Weight::from_parts(196_800_000, 0) - .saturating_add(T::DbWeight::get().reads(10)) - .saturating_add(T::DbWeight::get().writes(7)), DispatchClass::Normal, Pays::No))] + .saturating_add(T::DbWeight::get().reads(19)) + .saturating_add(T::DbWeight::get().writes(10)), DispatchClass::Normal, Pays::No))] pub fn remove_stake( origin: OriginFor, hotkey: T::AccountId, @@ -919,8 +919,8 @@ mod dispatches { /// User register a new subnetwork via burning token #[pallet::call_index(7)] #[pallet::weight((Weight::from_parts(219_400_000, 0) - .saturating_add(T::DbWeight::get().reads(26)) - .saturating_add(T::DbWeight::get().writes(24)), DispatchClass::Normal, Pays::No))] + .saturating_add(T::DbWeight::get().reads(34)) + .saturating_add(T::DbWeight::get().writes(29)), DispatchClass::Normal, Pays::No))] pub fn burned_register( origin: OriginFor, netuid: u16, @@ -1040,7 +1040,8 @@ mod dispatches { #[pallet::call_index(69)] #[pallet::weight(( Weight::from_parts(6_873_000, 0) - .saturating_add(T::DbWeight::get().writes(1)), + .saturating_add(T::DbWeight::get().reads(0)) + .saturating_add(T::DbWeight::get().writes(0)), DispatchClass::Operational, Pays::No ))] @@ -1185,8 +1186,8 @@ mod dispatches { /// User register a new subnetwork #[pallet::call_index(59)] #[pallet::weight((Weight::from_parts(260_500_000, 0) - .saturating_add(T::DbWeight::get().reads(16)) - .saturating_add(T::DbWeight::get().writes(30)), DispatchClass::Operational, Pays::No))] + .saturating_add(T::DbWeight::get().reads(33)) + .saturating_add(T::DbWeight::get().writes(52)), DispatchClass::Operational, Pays::No))] pub fn register_network(origin: OriginFor, hotkey: T::AccountId) -> DispatchResult { Self::do_register_network(origin, &hotkey, 1, None) } From 01f5b5b43fd54784e8fbf6fc24c26bf1ab7b742a Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Wed, 23 Apr 2025 14:52:21 -0700 Subject: [PATCH 25/45] update more reads/writes --- pallets/subtensor/src/macros/dispatches.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index 9254e3f42e..972eea317d 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -910,8 +910,8 @@ mod dispatches { /// Attempt to adjust the senate membership to include a hotkey #[pallet::call_index(63)] #[pallet::weight((Weight::from_parts(68_100_000, 0) - .saturating_add(T::DbWeight::get().reads(0)) - .saturating_add(T::DbWeight::get().writes(0)), DispatchClass::Normal, Pays::Yes))] + .saturating_add(T::DbWeight::get().reads(7)) + .saturating_add(T::DbWeight::get().writes(4)), DispatchClass::Normal, Pays::Yes))] pub fn adjust_senate(origin: OriginFor, hotkey: T::AccountId) -> DispatchResult { Self::do_adjust_senate(origin, hotkey) } @@ -1761,7 +1761,7 @@ mod dispatches { #[pallet::call_index(88)] #[pallet::weight((Weight::from_parts(91_010_000, 0) .saturating_add(T::DbWeight::get().reads(10)) - .saturating_add(T::DbWeight::get().writes(7)), DispatchClass::Normal, Pays::No))] + .saturating_add(T::DbWeight::get().writes(6)), DispatchClass::Normal, Pays::No))] pub fn add_stake_limit( origin: OriginFor, hotkey: T::AccountId, @@ -1923,7 +1923,7 @@ mod dispatches { /// Emits a `FirstEmissionBlockNumberSet` event on success. #[pallet::call_index(92)] #[pallet::weight(( - Weight::from_parts(35_770_000, 0).saturating_add(T::DbWeight::get().reads_writes(6, 1)), + Weight::from_parts(35_770_000, 0).saturating_add(T::DbWeight::get().reads_writes(4, 2)), DispatchClass::Operational, Pays::Yes ))] @@ -1988,7 +1988,7 @@ mod dispatches { /// Emits a `TokensRecycled` event on success. #[pallet::call_index(101)] #[pallet::weight(( - Weight::from_parts(101_000_000, 0).saturating_add(T::DbWeight::get().reads_writes(3, 2)), + Weight::from_parts(101_000_000, 0).saturating_add(T::DbWeight::get().reads_writes(7, 4)), DispatchClass::Operational, Pays::Yes ))] @@ -2013,7 +2013,7 @@ mod dispatches { /// Emits a `TokensBurned` event on success. #[pallet::call_index(102)] #[pallet::weight(( - Weight::from_parts(98_010_000, 0).saturating_add(T::DbWeight::get().reads_writes(2, 1)), + Weight::from_parts(98_010_000, 0).saturating_add(T::DbWeight::get().reads_writes(7, 3)), DispatchClass::Operational, Pays::Yes ))] From 4a4c3773bf850605ad9996b9cb5dabfc375e5247 Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Wed, 23 Apr 2025 14:55:29 -0700 Subject: [PATCH 26/45] script now checks reads_writes() too --- scripts/benchmark_action.sh | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/scripts/benchmark_action.sh b/scripts/benchmark_action.sh index 4d7f4bfc26..b2006afdbb 100755 --- a/scripts/benchmark_action.sh +++ b/scripts/benchmark_action.sh @@ -65,10 +65,29 @@ while IFS= read -r line; do code_record=$( awk -v extr="$extr" ' /^\s*#\[pallet::call_index\(/ { next } - /Weight::from_parts/ { lw=$0; sub(/.*Weight::from_parts\(\s*/, "", lw); sub(/[^0-9_].*$/, "", lw); gsub(/_/, "", lw); w=lw; next } - /reads_writes\(/ { lw=$0; sub(/.*reads_writes\(/, "", lw); sub(/\).*/, "", lw); split(lw,io,/,/); gsub(/^[ \t]+|[ \t]+$/, "", io[1]); gsub(/^[ \t]+|[ \t]+$/, "", io[2]); r=io[1]; wri=io[2]; next } - /\.reads\(/ { lw=$0; sub(/.*\.reads\(/, "", lw); sub(/\).*/, "", lw); r=lw; next } - /\.writes\(/ { lw=$0; sub(/.*\.writes\(/, "", lw); sub(/\).*/, "", lw); wri=lw; next } + /Weight::from_parts/ { + lw=$0; sub(/.*Weight::from_parts\(\s*/, "", lw); + sub(/[^0-9_].*$/, "", lw); gsub(/_/, "", lw); + w=lw + } + /reads_writes\(/ { + lw=$0; sub(/.*reads_writes\(/, "", lw); + sub(/\).*/, "", lw); + split(lw,io,/,/); + gsub(/^[ \t]+|[ \t]+$/, "", io[1]); + gsub(/^[ \t]+|[ \t]+$/, "", io[2]); + r=io[1]; wri=io[2]; next + } + /\.reads\(/ { + lw=$0; sub(/.*\.reads\(/, "", lw); + sub(/\).*/, "", lw); + r=lw; next + } + /\.writes\(/ { + lw=$0; sub(/.*\.writes\(/, "", lw); + sub(/\).*/, "", lw); + wri=lw; next + } $0 ~ ("pub fn[[:space:]]+" extr "\\(") { print w, r, wri; exit } ' "$DISPATCH" ) From 3e8dde3d8f5a00721df1818d6f7c966caf3f51ca Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Wed, 23 Apr 2025 15:29:49 -0700 Subject: [PATCH 27/45] add missing reads --- pallets/subtensor/src/macros/dispatches.rs | 26 +++++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index 972eea317d..aa33b1c2c7 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -1068,6 +1068,7 @@ mod dispatches { #[pallet::call_index(76)] #[pallet::weight(( Weight::from_parts(6_000, 0) + .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Operational, Pays::No @@ -1092,6 +1093,7 @@ mod dispatches { #[pallet::call_index(77)] #[pallet::weight(( Weight::from_parts(6_000, 0) + .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Operational, Pays::No @@ -1560,7 +1562,9 @@ mod dispatches { /// * `TxRateLimitExceeded`: /// - Thrown if key has hit transaction rate limit #[pallet::call_index(83)] - #[pallet::weight((Weight::from_parts(36_200_000, 0).saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Operational, Pays::No))] + #[pallet::weight((Weight::from_parts(36_200_000, 0) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Operational, Pays::No))] pub fn unstake_all(origin: OriginFor, hotkey: T::AccountId) -> DispatchResult { Self::do_unstake_all(origin, hotkey) } @@ -1591,7 +1595,9 @@ mod dispatches { /// * `TxRateLimitExceeded`: /// - Thrown if key has hit transaction rate limit #[pallet::call_index(84)] - #[pallet::weight((Weight::from_parts(68_730_000, 0).saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Operational, Pays::No))] + #[pallet::weight((Weight::from_parts(68_730_000, 0) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Operational, Pays::No))] pub fn unstake_all_alpha(origin: OriginFor, hotkey: T::AccountId) -> DispatchResult { Self::do_unstake_all_alpha(origin, hotkey) } @@ -1618,7 +1624,9 @@ mod dispatches { /// - The alpha stake amount to move. /// #[pallet::call_index(85)] - #[pallet::weight((Weight::from_parts(196_600_000, 0).saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Operational, Pays::No))] + #[pallet::weight((Weight::from_parts(196_600_000, 0) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Operational, Pays::No))] pub fn move_stake( origin: T::RuntimeOrigin, origin_hotkey: T::AccountId, @@ -1659,7 +1667,9 @@ mod dispatches { /// # Events /// May emit a `StakeTransferred` event on success. #[pallet::call_index(86)] - #[pallet::weight((Weight::from_parts(207_300_000, 0).saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Operational, Pays::No))] + #[pallet::weight((Weight::from_parts(207_300_000, 0) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Operational, Pays::No))] pub fn transfer_stake( origin: T::RuntimeOrigin, destination_coldkey: T::AccountId, @@ -1699,7 +1709,9 @@ mod dispatches { /// May emit a `StakeSwapped` event on success. #[pallet::call_index(87)] #[pallet::weight(( - Weight::from_parts(190_100_000, 0).saturating_add(T::DbWeight::get().writes(1)), + Weight::from_parts(190_100_000, 0) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Operational, Pays::No ))] @@ -1864,7 +1876,9 @@ mod dispatches { /// May emit a `StakeSwapped` event on success. #[pallet::call_index(90)] #[pallet::weight(( - Weight::from_parts(162_400_000, 0).saturating_add(T::DbWeight::get().writes(1)), + Weight::from_parts(162_400_000, 0) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Operational, Pays::No ))] From f03ec00ce567933cf39baedbb04315d287b11416 Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Wed, 23 Apr 2025 15:49:40 -0700 Subject: [PATCH 28/45] update reads/writes --- pallets/subtensor/src/macros/dispatches.rs | 60 +++++++++++----------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index aa33b1c2c7..f6051227ae 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -121,7 +121,7 @@ mod dispatches { /// #[pallet::call_index(80)] #[pallet::weight((Weight::from_parts(105_100_000, 0) - .saturating_add(T::DbWeight::get().reads(4106)) + .saturating_add(T::DbWeight::get().reads(14)) .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))] pub fn batch_set_weights( origin: OriginFor, @@ -187,7 +187,7 @@ mod dispatches { /// #[pallet::call_index(100)] #[pallet::weight((Weight::from_parts(89_380_000, 0) - .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().reads(8)) .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))] pub fn batch_commit_weights( origin: OriginFor, @@ -280,8 +280,8 @@ mod dispatches { /// #[pallet::call_index(99)] #[pallet::weight((Weight::from_parts(73_720_000, 0) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Normal, Pays::No))] + .saturating_add(T::DbWeight::get().reads(6)) + .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))] pub fn commit_crv3_weights( origin: T::RuntimeOrigin, netuid: u16, @@ -414,8 +414,8 @@ mod dispatches { /// #[pallet::call_index(8)] #[pallet::weight((Weight::from_parts(4_068_000, 0) - .saturating_add(T::DbWeight::get().reads(4104)) - .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))] + .saturating_add(T::DbWeight::get().reads(0)) + .saturating_add(T::DbWeight::get().writes(0)), DispatchClass::Normal, Pays::No))] pub fn set_tao_weights( _origin: OriginFor, _netuid: u16, @@ -499,8 +499,8 @@ mod dispatches { /// #[pallet::call_index(65)] #[pallet::weight((Weight::from_parts(37_380_000, 0) - .saturating_add(T::DbWeight::get().reads(6)) - .saturating_add(T::DbWeight::get().writes(3)), DispatchClass::Normal, Pays::No))] + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))] pub fn decrease_take( origin: OriginFor, hotkey: T::AccountId, @@ -541,8 +541,8 @@ mod dispatches { /// #[pallet::call_index(66)] #[pallet::weight((Weight::from_parts(44_630_000, 0) - .saturating_add(T::DbWeight::get().reads(6)) - .saturating_add(T::DbWeight::get().writes(3)), DispatchClass::Normal, Pays::No))] + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))] pub fn increase_take( origin: OriginFor, hotkey: T::AccountId, @@ -932,8 +932,8 @@ mod dispatches { /// The extrinsic for user to change its hotkey #[pallet::call_index(70)] #[pallet::weight((Weight::from_parts(240_600_000, 0) - .saturating_add(T::DbWeight::get().reads(272)) - .saturating_add(T::DbWeight::get().writes(527)), DispatchClass::Operational, Pays::No))] + .saturating_add(T::DbWeight::get().reads(31)) + .saturating_add(T::DbWeight::get().writes(23)), DispatchClass::Operational, Pays::No))] pub fn swap_hotkey( origin: OriginFor, hotkey: T::AccountId, @@ -1455,7 +1455,7 @@ mod dispatches { /// #[pallet::call_index(68)] #[pallet::weight((Weight::from_parts(32_340_000, 0) - .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Normal, Pays::Yes))] pub fn set_identity( origin: OriginFor, @@ -1497,7 +1497,7 @@ mod dispatches { /// - The contact information for the subnet. #[pallet::call_index(78)] #[pallet::weight((Weight::from_parts(23_080_000, 0) - .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Normal, Pays::Yes))] pub fn set_subnet_identity( origin: OriginFor, @@ -1526,8 +1526,8 @@ mod dispatches { /// User register a new subnetwork #[pallet::call_index(79)] #[pallet::weight((Weight::from_parts(239_700_000, 0) - .saturating_add(T::DbWeight::get().reads(16)) - .saturating_add(T::DbWeight::get().writes(30)), DispatchClass::Operational, Pays::No))] + .saturating_add(T::DbWeight::get().reads(32)) + .saturating_add(T::DbWeight::get().writes(51)), DispatchClass::Operational, Pays::No))] pub fn register_network_with_identity( origin: OriginFor, hotkey: T::AccountId, @@ -1563,8 +1563,8 @@ mod dispatches { /// - Thrown if key has hit transaction rate limit #[pallet::call_index(83)] #[pallet::weight((Weight::from_parts(36_200_000, 0) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Operational, Pays::No))] + .saturating_add(T::DbWeight::get().reads(6)) + .saturating_add(T::DbWeight::get().writes(0)), DispatchClass::Operational, Pays::No))] pub fn unstake_all(origin: OriginFor, hotkey: T::AccountId) -> DispatchResult { Self::do_unstake_all(origin, hotkey) } @@ -1596,8 +1596,8 @@ mod dispatches { /// - Thrown if key has hit transaction rate limit #[pallet::call_index(84)] #[pallet::weight((Weight::from_parts(68_730_000, 0) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Operational, Pays::No))] + .saturating_add(T::DbWeight::get().reads(12)) + .saturating_add(T::DbWeight::get().writes(6)), DispatchClass::Operational, Pays::No))] pub fn unstake_all_alpha(origin: OriginFor, hotkey: T::AccountId) -> DispatchResult { Self::do_unstake_all_alpha(origin, hotkey) } @@ -1625,8 +1625,8 @@ mod dispatches { /// #[pallet::call_index(85)] #[pallet::weight((Weight::from_parts(196_600_000, 0) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Operational, Pays::No))] + .saturating_add(T::DbWeight::get().reads(17)) + .saturating_add(T::DbWeight::get().writes(13)), DispatchClass::Operational, Pays::No))] pub fn move_stake( origin: T::RuntimeOrigin, origin_hotkey: T::AccountId, @@ -1668,8 +1668,8 @@ mod dispatches { /// May emit a `StakeTransferred` event on success. #[pallet::call_index(86)] #[pallet::weight((Weight::from_parts(207_300_000, 0) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Operational, Pays::No))] + .saturating_add(T::DbWeight::get().reads(16)) + .saturating_add(T::DbWeight::get().writes(13)), DispatchClass::Operational, Pays::No))] pub fn transfer_stake( origin: T::RuntimeOrigin, destination_coldkey: T::AccountId, @@ -1710,8 +1710,8 @@ mod dispatches { #[pallet::call_index(87)] #[pallet::weight(( Weight::from_parts(190_100_000, 0) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)), + .saturating_add(T::DbWeight::get().reads(13)) + .saturating_add(T::DbWeight::get().writes(9)), DispatchClass::Operational, Pays::No ))] @@ -1833,8 +1833,8 @@ mod dispatches { /// #[pallet::call_index(89)] #[pallet::weight((Weight::from_parts(172_100_000, 0) - .saturating_add(T::DbWeight::get().reads(10)) - .saturating_add(T::DbWeight::get().writes(7)), DispatchClass::Normal, Pays::No))] + .saturating_add(T::DbWeight::get().reads(17)) + .saturating_add(T::DbWeight::get().writes(9)), DispatchClass::Normal, Pays::No))] pub fn remove_stake_limit( origin: OriginFor, hotkey: T::AccountId, @@ -1877,8 +1877,8 @@ mod dispatches { #[pallet::call_index(90)] #[pallet::weight(( Weight::from_parts(162_400_000, 0) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)), + .saturating_add(T::DbWeight::get().reads(12)) + .saturating_add(T::DbWeight::get().writes(9)), DispatchClass::Operational, Pays::No ))] From e5db7519018f3c29644c0eaf4014676b385f86c8 Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Wed, 23 Apr 2025 16:22:43 -0700 Subject: [PATCH 29/45] add a write --- pallets/subtensor/src/macros/dispatches.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index f6051227ae..21ee4bc4d4 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -1041,7 +1041,7 @@ mod dispatches { #[pallet::weight(( Weight::from_parts(6_873_000, 0) .saturating_add(T::DbWeight::get().reads(0)) - .saturating_add(T::DbWeight::get().writes(0)), + .saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Operational, Pays::No ))] From 2862d48d54b38cd490b1563c7238eb6c1cc4d91b Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Wed, 23 Apr 2025 16:34:29 -0700 Subject: [PATCH 30/45] fix dispatch tests --- pallets/subtensor/src/tests/registration.rs | 2 +- pallets/subtensor/src/tests/serving.rs | 4 ++-- pallets/subtensor/src/tests/staking.rs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pallets/subtensor/src/tests/registration.rs b/pallets/subtensor/src/tests/registration.rs index 1ae16d95c0..498cce15b2 100644 --- a/pallets/subtensor/src/tests/registration.rs +++ b/pallets/subtensor/src/tests/registration.rs @@ -37,7 +37,7 @@ fn test_registration_subscribe_ok_dispatch_info_ok() { assert_eq!( call.get_dispatch_info(), DispatchInfo { - weight: frame_support::weights::Weight::from_parts(2_992_000_000, 0), + weight: frame_support::weights::Weight::from_parts(3_142_000_000, 0), class: DispatchClass::Normal, pays_fee: Pays::No } diff --git a/pallets/subtensor/src/tests/serving.rs b/pallets/subtensor/src/tests/serving.rs index 1d8202a242..251dde2078 100644 --- a/pallets/subtensor/src/tests/serving.rs +++ b/pallets/subtensor/src/tests/serving.rs @@ -53,7 +53,7 @@ fn test_serving_subscribe_ok_dispatch_info_ok() { assert_eq!( call.get_dispatch_info(), DispatchInfo { - weight: frame_support::weights::Weight::from_parts(246_000_000, 0), + weight: frame_support::weights::Weight::from_parts(235_670_000, 0), class: DispatchClass::Normal, pays_fee: Pays::No } @@ -355,7 +355,7 @@ fn test_prometheus_serving_subscribe_ok_dispatch_info_ok() { assert_eq!( call.get_dispatch_info(), DispatchInfo { - weight: frame_support::weights::Weight::from_parts(245_000_000, 0), + weight: frame_support::weights::Weight::from_parts(231_170_000, 0), class: DispatchClass::Normal, pays_fee: Pays::No } diff --git a/pallets/subtensor/src/tests/staking.rs b/pallets/subtensor/src/tests/staking.rs index a9fa11ba3a..da64a9466e 100644 --- a/pallets/subtensor/src/tests/staking.rs +++ b/pallets/subtensor/src/tests/staking.rs @@ -32,7 +32,7 @@ fn test_add_stake_dispatch_info_ok() { assert_eq!( call.get_dispatch_info(), DispatchInfo { - weight: frame_support::weights::Weight::from_parts(1_074_000_000, 0), + weight: frame_support::weights::Weight::from_parts(1_501_000_000, 0), class: DispatchClass::Normal, pays_fee: Pays::No } @@ -344,7 +344,7 @@ fn test_remove_stake_dispatch_info_ok() { assert_eq!( call.get_dispatch_info(), DispatchInfo { - weight: frame_support::weights::Weight::from_parts(1_061_000_000, 0) + weight: frame_support::weights::Weight::from_parts(1_671_800_000, 0) .add_proof_size(43991), class: DispatchClass::Normal, pays_fee: Pays::No From 3d18613b0a8bff9082592b9f277aa346ddb0d2de Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Wed, 23 Apr 2025 16:36:27 -0700 Subject: [PATCH 31/45] fix dispatch test --- pallets/subtensor/src/tests/staking.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/subtensor/src/tests/staking.rs b/pallets/subtensor/src/tests/staking.rs index da64a9466e..15bc0d5c75 100644 --- a/pallets/subtensor/src/tests/staking.rs +++ b/pallets/subtensor/src/tests/staking.rs @@ -345,7 +345,7 @@ fn test_remove_stake_dispatch_info_ok() { call.get_dispatch_info(), DispatchInfo { weight: frame_support::weights::Weight::from_parts(1_671_800_000, 0) - .add_proof_size(43991), + .add_proof_size(0), class: DispatchClass::Normal, pays_fee: Pays::No } From f5fc675348e8c3ab3ef06f3313627d513407a60a Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Wed, 23 Apr 2025 18:25:09 -0700 Subject: [PATCH 32/45] fix new benchmarks --- pallets/subtensor/src/benchmarks.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pallets/subtensor/src/benchmarks.rs b/pallets/subtensor/src/benchmarks.rs index 7433176398..b5ff1197e0 100644 --- a/pallets/subtensor/src/benchmarks.rs +++ b/pallets/subtensor/src/benchmarks.rs @@ -145,7 +145,7 @@ benchmarks! { let seed : u32 = 1; Subtensor::::init_new_network(netuid, tempo); - + SubtokenEnabled::::insert(netuid, true); Subtensor::::set_burn(netuid, 1); Subtensor::::set_network_registration_allowed( netuid, true ); @@ -175,6 +175,7 @@ benchmarks! { Subtensor::::init_new_network(netuid, tempo); Subtensor::::set_network_registration_allowed( netuid, true ); + SubtokenEnabled::::insert(netuid, true); Subtensor::::set_max_allowed_uids( netuid, 4096 ); assert_eq!(Subtensor::::get_max_allowed_uids(netuid), 4096); @@ -216,6 +217,7 @@ benchmarks! { Subtensor::::init_new_network(netuid, tempo); Subtensor::::set_network_registration_allowed( netuid, true ); + SubtokenEnabled::::insert(netuid, true); Subtensor::::set_max_allowed_uids( netuid, 4096 ); assert_eq!(Subtensor::::get_max_allowed_uids(netuid), 4096); @@ -247,6 +249,7 @@ benchmarks! { let seed : u32 = 1; Subtensor::::init_new_network(netuid, tempo); + SubtokenEnabled::::insert(netuid, true); Subtensor::::set_burn(netuid, 1); Subtensor::::set_network_registration_allowed( netuid, true ); Subtensor::::set_max_allowed_uids( netuid, 4096 ); From f352b042ae54b3b3388a6cd264fb4ba597bdc4ef Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Wed, 23 Apr 2025 18:57:19 -0700 Subject: [PATCH 33/45] update weights --- pallets/subtensor/src/macros/dispatches.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index 5ad0db7db2..0137448006 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -2090,7 +2090,7 @@ mod dispatches { /// - Errors stemming from transaction pallet. /// #[pallet::call_index(103)] - #[pallet::weight((Weight::from_parts(99_000_000, 5127) + #[pallet::weight((Weight::from_parts(162_000_000, 5127) .saturating_add(T::DbWeight::get().reads(14_u64)) .saturating_add(T::DbWeight::get().writes(12_u64)), DispatchClass::Normal, Pays::No))] pub fn add_stake_aggregate( @@ -2197,7 +2197,7 @@ mod dispatches { /// - Errors stemming from transaction pallet. /// #[pallet::call_index(105)] - #[pallet::weight((Weight::from_parts(99_000_000, 5127) + #[pallet::weight((Weight::from_parts(169_200_000, 5127) .saturating_add(T::DbWeight::get().reads(14_u64)) .saturating_add(T::DbWeight::get().writes(12_u64)), DispatchClass::Normal, Pays::No))] pub fn add_stake_limit_aggregate( @@ -2263,7 +2263,7 @@ mod dispatches { /// - Thrown if there is not enough stake on the hotkey to withdwraw this amount. /// #[pallet::call_index(106)] - #[pallet::weight((Weight::from_parts(129_000_000, 10163) + #[pallet::weight((Weight::from_parts(211_700_000, 10163) .saturating_add(T::DbWeight::get().reads(19_u64)) .saturating_add(T::DbWeight::get().writes(12_u64)), DispatchClass::Normal, Pays::No))] pub fn remove_stake_limit_aggregate( From b5f3bab44cf826e60654adc3b0f0dccd7227aa60 Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Wed, 23 Apr 2025 19:26:56 -0700 Subject: [PATCH 34/45] fix another weight --- pallets/subtensor/src/macros/dispatches.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index 0137448006..7bacdcc3bd 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -2140,7 +2140,7 @@ mod dispatches { /// - Thrown if there is not enough stake on the hotkey to withdwraw this amount. /// #[pallet::call_index(104)] - #[pallet::weight((Weight::from_parts(129_000_000, 10163) + #[pallet::weight((Weight::from_parts(213_300_000, 10163) .saturating_add(T::DbWeight::get().reads(19_u64)) .saturating_add(T::DbWeight::get().writes(12_u64)), DispatchClass::Normal, Pays::No))] pub fn remove_stake_aggregate( From 74ebb55386323ea08e9c6f642fe92ce5635d037c Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Wed, 23 Apr 2025 20:06:36 -0700 Subject: [PATCH 35/45] skip-validate-benchmarks --- .github/workflows/run-benchmarks.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/run-benchmarks.yml b/.github/workflows/run-benchmarks.yml index 9983151a91..71f69fcd75 100644 --- a/.github/workflows/run-benchmarks.yml +++ b/.github/workflows/run-benchmarks.yml @@ -1,5 +1,5 @@ # .github/workflows/benchmarks.yml -name: Run-Benchmarks +name: Validate-Benchmarks on: pull_request: @@ -10,7 +10,8 @@ concurrency: cancel-in-progress: true jobs: - run-benchmarks: + validate-benchmarks: + if: ${{ !contains(github.event.pull_request.labels.*.name, 'skip-validate-benchmarks') }} runs-on: SubtensorCI steps: - name: Checkout PR branch From 9cac728bfe70fc04622702787c89bc8ffce20ffa Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Wed, 23 Apr 2025 22:18:33 -0700 Subject: [PATCH 36/45] bump CI From 649ecc9ca6f60857f733308fd34d25c19092000f Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Wed, 23 Apr 2025 23:37:05 -0700 Subject: [PATCH 37/45] test CI --- pallets/subtensor/src/macros/dispatches.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index 7bacdcc3bd..44a39d42ee 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -2328,7 +2328,7 @@ mod dispatches { /// * `hotkey` (T::AccountId): /// - The associated hotkey account. #[pallet::call_index(108)] - #[pallet::weight((Weight::from_parts(3_000_000, 0).saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Operational, Pays::No))] + #[pallet::weight((Weight::from_parts(7, 0).saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Operational, Pays::No))] pub fn unstake_all_alpha_aggregate( origin: OriginFor, hotkey: T::AccountId, From 22d7b3b2a1d8cec8c2f438f14e251d8e831c1b0a Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Thu, 24 Apr 2025 00:05:37 -0700 Subject: [PATCH 38/45] Update dispatches.rs --- pallets/subtensor/src/macros/dispatches.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index 44a39d42ee..7bacdcc3bd 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -2328,7 +2328,7 @@ mod dispatches { /// * `hotkey` (T::AccountId): /// - The associated hotkey account. #[pallet::call_index(108)] - #[pallet::weight((Weight::from_parts(7, 0).saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Operational, Pays::No))] + #[pallet::weight((Weight::from_parts(3_000_000, 0).saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Operational, Pays::No))] pub fn unstake_all_alpha_aggregate( origin: OriginFor, hotkey: T::AccountId, From db946dd06a7f524280bc55496e5689d1e941dd1e Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Thu, 24 Apr 2025 00:08:17 -0700 Subject: [PATCH 39/45] test CI --- pallets/subtensor/src/macros/dispatches.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index 7bacdcc3bd..9b9c9cc85e 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -77,7 +77,7 @@ mod dispatches { /// * 'MaxWeightExceeded': /// - Attempting to set weights with max value exceeding limit. #[pallet::call_index(0)] - #[pallet::weight((Weight::from_parts(20_730_000_000, 0) + #[pallet::weight((Weight::from_parts(7, 0) .saturating_add(T::DbWeight::get().reads(4111)) .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))] pub fn set_weights( From 6c0f7b1494c59a6654c512b57c5e20c3a59efc2f Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Thu, 24 Apr 2025 00:08:38 -0700 Subject: [PATCH 40/45] revert --- pallets/subtensor/src/macros/dispatches.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index 9b9c9cc85e..7bacdcc3bd 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -77,7 +77,7 @@ mod dispatches { /// * 'MaxWeightExceeded': /// - Attempting to set weights with max value exceeding limit. #[pallet::call_index(0)] - #[pallet::weight((Weight::from_parts(7, 0) + #[pallet::weight((Weight::from_parts(20_730_000_000, 0) .saturating_add(T::DbWeight::get().reads(4111)) .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))] pub fn set_weights( From cd7e7f0499f9dd1cba7cc543dfff520358e94de9 Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Thu, 24 Apr 2025 07:59:26 -0700 Subject: [PATCH 41/45] bump CI From eca958399e9f6cc7ecd09543461e464ffe883e99 Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Thu, 24 Apr 2025 08:49:24 -0700 Subject: [PATCH 42/45] add retry logic --- scripts/benchmark_action.sh | 233 +++++++++++++++++++----------------- 1 file changed, 126 insertions(+), 107 deletions(-) diff --git a/scripts/benchmark_action.sh b/scripts/benchmark_action.sh index b2006afdbb..546cd1f80c 100755 --- a/scripts/benchmark_action.sh +++ b/scripts/benchmark_action.sh @@ -23,118 +23,137 @@ echo "──────────────────────── echo " Running pallet_subtensor benchmarks…" echo "──────────────────────────────────────────" -TMP="$(mktemp)"; trap "rm -f \"$TMP\" \"$THRESHOLD\"" EXIT -./target/production/node-subtensor benchmark pallet \ - --runtime "$RUNTIME_WASM" \ - --genesis-builder=runtime \ - --genesis-builder-preset=benchmark \ - --wasm-execution=compiled \ - --pallet pallet_subtensor \ - --extrinsic "*" \ - --steps 50 \ - --repeat 5 \ -| tee "$TMP" - -declare -a summary_lines=() -declare -a failures=() -fail=0 -extr="" - -while IFS= read -r line; do - # detect new extrinsic - if [[ $line =~ Extrinsic:\ \"benchmark_([[:alnum:]_]+)\" ]]; then - extr="${BASH_REMATCH[1]}" - continue - fi +MAX_RETRIES=3 +attempt=1 + +while (( attempt <= MAX_RETRIES )); do + echo + echo "Attempt #$attempt" + echo "──────────────────────────────────────────" + + # run benchmarks and capture output + TMP="$(mktemp)" + trap "rm -f \"$TMP\"" EXIT + ./target/production/node-subtensor benchmark pallet \ + --runtime "$RUNTIME_WASM" \ + --genesis-builder=runtime \ + --genesis-builder-preset=benchmark \ + --wasm-execution=compiled \ + --pallet pallet_subtensor \ + --extrinsic "*" \ + --steps 50 \ + --repeat 5 \ + | tee "$TMP" + + # reset counters + declare -a summary_lines=() + declare -a failures=() + fail=0 + extr="" + + # parse and validate + while IFS= read -r line; do + if [[ $line =~ Extrinsic:\ \"benchmark_([[:alnum:]_]+)\" ]]; then + extr="${BASH_REMATCH[1]}" + continue + fi - # first timing line - if [[ $line =~ Time\ ~=\ *([0-9]+(\.[0-9]+)?) ]]; then - [[ -z "$extr" ]] && continue + if [[ $line =~ Time\ ~=\ *([0-9]+(\.[0-9]+)?) ]]; then + [[ -z "$extr" ]] && continue + + meas_us="${BASH_REMATCH[1]}" + meas_ps=$(awk -v u="$meas_us" 'BEGIN{printf("%.0f", u * 1000000)}') + + # grab reads & writes + meas_reads="" meas_writes="" + while IFS= read -r sub; do + [[ $sub =~ Reads[[:space:]]*=[[:space:]]*([0-9]+) ]] && meas_reads="${BASH_REMATCH[1]}" && continue + [[ $sub =~ Writes[[:space:]]*=[[:space:]]*([0-9]+) ]] && meas_writes="${BASH_REMATCH[1]}" && break + done + + # extract code-side values + code_record=$( + awk -v extr="$extr" ' + /^\s*#\[pallet::call_index\(/ { next } + /Weight::from_parts/ { + lw=$0; sub(/.*Weight::from_parts\(\s*/, "", lw); + sub(/[^0-9_].*$/, "", lw); gsub(/_/, "", lw); + w=lw + } + /reads_writes\(/ { + lw=$0; sub(/.*reads_writes\(/, "", lw); + sub(/\).*/, "", lw); + split(lw,io,/,/); + gsub(/^[ \t]+|[ \t]+$/, "", io[1]); + gsub(/^[ \t]+|[ \t]+$/, "", io[2]); + r=io[1]; wri=io[2]; next + } + /\.reads\(/ { + lw=$0; sub(/.*\.reads\(/, "", lw); + sub(/\).*/, "", lw); + r=lw; next + } + /\.writes\(/ { + lw=$0; sub(/.*\.writes\(/, "", lw); + sub(/\).*/, "", lw); + wri=lw; next + } + $0 ~ ("pub fn[[:space:]]+" extr "\\(") { print w, r, wri; exit } + ' "$DISPATCH" + ) + read code_w code_reads code_writes <<<"$code_record" + + # compute drift % + drift=$(awk -v a="$meas_ps" -v b="$code_w" 'BEGIN{printf("%.1f", (a-b)/b*100)}') + + summary_lines+=("$(printf "%-30s | reads code=%3s measured=%3s | writes code=%3s measured=%3s | weight code=%12s measured=%12s | drift %6s%%" \ + "$extr" "$code_reads" "$meas_reads" "$code_writes" "$meas_writes" "$code_w" "$meas_ps" "$drift")") + + # validations + [[ -z "$code_w" ]] && failures+=("[${extr}] missing code weight") && fail=1 + [[ -z "$meas_reads" ]] && failures+=("[${extr}] missing measured reads") && fail=1 + [[ -z "$meas_writes" ]] && failures+=("[${extr}] missing measured writes") && fail=1 + (( meas_reads != code_reads )) && failures+=("[${extr}] reads mismatch code=${code_reads}, measured=${meas_reads}") && fail=1 + (( meas_writes != code_writes )) && failures+=("[${extr}] writes mismatch code=${code_writes}, measured=${meas_writes}") && fail=1 + [[ "$code_w" == "0" ]] && failures+=("[${extr}] zero code weight") && fail=1 + + abs_drift=${drift#-} + drift_int=${abs_drift%%.*} + if (( drift_int > THRESHOLD )); then + failures+=("[${extr}] weight code=${code_w}, measured=${meas_ps}, drift=${drift}%") + fail=1 + fi + + extr="" + fi + done < "$TMP" - meas_us="${BASH_REMATCH[1]}" - meas_ps=$(awk -v u="$meas_us" 'BEGIN{printf("%.0f", u * 1000000)}') + # summary output + echo + echo "Benchmark Summary for attempt #$attempt:" + for l in "${summary_lines[@]}"; do + echo " $l" + done - # grab reads & writes - meas_reads="" meas_writes="" - while IFS= read -r sub; do - [[ $sub =~ Reads[[:space:]]*=[[:space:]]*([0-9]+) ]] && meas_reads="${BASH_REMATCH[1]}" && continue - [[ $sub =~ Writes[[:space:]]*=[[:space:]]*([0-9]+) ]] && meas_writes="${BASH_REMATCH[1]}" && break + if (( fail )); then + echo + echo "❌ Issues detected on attempt #$attempt:" + for e in "${failures[@]}"; do + echo " • $e" done - # extract code-side values - code_record=$( - awk -v extr="$extr" ' - /^\s*#\[pallet::call_index\(/ { next } - /Weight::from_parts/ { - lw=$0; sub(/.*Weight::from_parts\(\s*/, "", lw); - sub(/[^0-9_].*$/, "", lw); gsub(/_/, "", lw); - w=lw - } - /reads_writes\(/ { - lw=$0; sub(/.*reads_writes\(/, "", lw); - sub(/\).*/, "", lw); - split(lw,io,/,/); - gsub(/^[ \t]+|[ \t]+$/, "", io[1]); - gsub(/^[ \t]+|[ \t]+$/, "", io[2]); - r=io[1]; wri=io[2]; next - } - /\.reads\(/ { - lw=$0; sub(/.*\.reads\(/, "", lw); - sub(/\).*/, "", lw); - r=lw; next - } - /\.writes\(/ { - lw=$0; sub(/.*\.writes\(/, "", lw); - sub(/\).*/, "", lw); - wri=lw; next - } - $0 ~ ("pub fn[[:space:]]+" extr "\\(") { print w, r, wri; exit } - ' "$DISPATCH" - ) - read code_w code_reads code_writes <<<"$code_record" - - # compute drift % - drift=$(awk -v a="$meas_ps" -v b="$code_w" 'BEGIN{printf("%.1f", (a-b)/b*100)}') - - # build formatted summary line - summary_lines+=("$(printf "%-30s | reads code=%3s measured=%3s | writes code=%3s measured=%3s | weight code=%12s measured=%12s | drift %6s%%" \ - "$extr" "$code_reads" "$meas_reads" "$code_writes" "$meas_writes" "$code_w" "$meas_ps" "$drift")") - - # validations - [[ -z "$code_w" ]] && failures+=("[${extr}] missing code weight") && fail=1 - [[ -z "$meas_reads" ]] && failures+=("[${extr}] missing measured reads") && fail=1 - [[ -z "$meas_writes" ]] && failures+=("[${extr}] missing measured writes") && fail=1 - (( meas_reads != code_reads )) && failures+=("[${extr}] reads mismatch code=${code_reads}, measured=${meas_reads}") && fail=1 - (( meas_writes != code_writes )) && failures+=("[${extr}] writes mismatch code=${code_writes}, measured=${meas_writes}") && fail=1 - [[ "$code_w" == "0" ]] && failures+=("[${extr}] zero code weight") && fail=1 - - # drift check: strip sign & decimals, then compare integer part - abs_drift=${drift#-} - drift_int=${abs_drift%%.*} - if (( drift_int > THRESHOLD )); then - failures+=("[${extr}] weight code=${code_w}, measured=${meas_ps}, drift=${drift}%") - fail=1 + if (( attempt < MAX_RETRIES )); then + echo "→ Retrying…" + (( attempt++ )) + continue + else + echo + echo "❌ Benchmarks failed after $MAX_RETRIES attempts." + exit 1 fi - - extr="" + else + echo + echo "✅ All benchmarks within ±${THRESHOLD}% drift." + exit 0 fi -done < "$TMP" - -echo -echo "Benchmark Summary:" -for l in "${summary_lines[@]}"; do - echo "$l" done - -if (( fail )); then - echo - echo "❌ Detected issues:" - for e in "${failures[@]}"; do - echo " • $e" - done - exit 1 -else - echo - echo "✅ All benchmarks within ±${THRESHOLD}% drift." - exit 0 -fi From f0cd9c6350e631946beb996dfae64845c9e5ffbc Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Thu, 24 Apr 2025 09:16:35 -0700 Subject: [PATCH 43/45] read all numbers correctly --- scripts/benchmark_action.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/benchmark_action.sh b/scripts/benchmark_action.sh index 546cd1f80c..acb7dfa2c5 100755 --- a/scripts/benchmark_action.sh +++ b/scripts/benchmark_action.sh @@ -51,7 +51,7 @@ while (( attempt <= MAX_RETRIES )); do fail=0 extr="" - # parse and validate + # parse output while IFS= read -r line; do if [[ $line =~ Extrinsic:\ \"benchmark_([[:alnum:]_]+)\" ]]; then extr="${BASH_REMATCH[1]}" @@ -103,6 +103,11 @@ while (( attempt <= MAX_RETRIES )); do ) read code_w code_reads code_writes <<<"$code_record" + # strip any non-digit (e.g. "_u64") so math works + code_w=${code_w//[!0-9]/} + code_reads=${code_reads//[!0-9]/} + code_writes=${code_writes//[!0-9]/} + # compute drift % drift=$(awk -v a="$meas_ps" -v b="$code_w" 'BEGIN{printf("%.1f", (a-b)/b*100)}') From cfc6cb85cda64808f9613fc59cf9d094c08d9ca3 Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Thu, 24 Apr 2025 10:13:30 -0700 Subject: [PATCH 44/45] fix number parsing bug --- scripts/benchmark_action.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/scripts/benchmark_action.sh b/scripts/benchmark_action.sh index acb7dfa2c5..9989f66c52 100755 --- a/scripts/benchmark_action.sh +++ b/scripts/benchmark_action.sh @@ -104,9 +104,12 @@ while (( attempt <= MAX_RETRIES )); do read code_w code_reads code_writes <<<"$code_record" # strip any non-digit (e.g. "_u64") so math works - code_w=${code_w//[!0-9]/} - code_reads=${code_reads//[!0-9]/} - code_writes=${code_writes//[!0-9]/} + code_w=${code_w//_/} + code_w=${code_w%%[^0-9]*} + code_reads=${code_reads//_/} + code_reads=${code_reads%%[^0-9]*} + code_writes=${code_writes//_/} + code_writes=${code_writes%%[^0-9]*} # compute drift % drift=$(awk -v a="$meas_ps" -v b="$code_w" 'BEGIN{printf("%.1f", (a-b)/b*100)}') From c1b24e51e995933f16ebcc2b8bd80c438becc2ed Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Thu, 24 Apr 2025 10:14:37 -0700 Subject: [PATCH 45/45] update some reads --- pallets/subtensor/src/macros/dispatches.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index 7bacdcc3bd..de22d64c88 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -2091,7 +2091,7 @@ mod dispatches { /// #[pallet::call_index(103)] #[pallet::weight((Weight::from_parts(162_000_000, 5127) - .saturating_add(T::DbWeight::get().reads(14_u64)) + .saturating_add(T::DbWeight::get().reads(15_u64)) .saturating_add(T::DbWeight::get().writes(12_u64)), DispatchClass::Normal, Pays::No))] pub fn add_stake_aggregate( origin: OriginFor, @@ -2141,7 +2141,7 @@ mod dispatches { /// #[pallet::call_index(104)] #[pallet::weight((Weight::from_parts(213_300_000, 10163) - .saturating_add(T::DbWeight::get().reads(19_u64)) + .saturating_add(T::DbWeight::get().reads(20_u64)) .saturating_add(T::DbWeight::get().writes(12_u64)), DispatchClass::Normal, Pays::No))] pub fn remove_stake_aggregate( origin: OriginFor,