Skip to content

Improve Benchmarking#2798

Open
JohnReedV wants to merge 46 commits into
devnet-readyfrom
apply-benchmark-to-only-bad-benches
Open

Improve Benchmarking#2798
JohnReedV wants to merge 46 commits into
devnet-readyfrom
apply-benchmark-to-only-bad-benches

Conversation

@JohnReedV

@JohnReedV JohnReedV commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Description

This PR

  • Modifies the benchmark flow so that only extrinsics that have drifted passed the threshold or have incorrect read/writes are updated rather than replacing the entire file and creating conflicts everywhere.

  • Adds a lint to check for extrinsics with missing benchmarks. This can be hidden with
    #[allow(unknown_lints, benchmarked_weight_not_plugged)]

  • Adds 48 missing benchmarks

  • Fixes a bug where benchmarks could fail on noisy internal component drift even when the actual benchmark-level weight was still within the configured threshold.

  • Adds block_step to the benchmark flow so the on_initialize weight is generated instead of hardcoded. The benchmark simulates the current worst case with 2 epochs in a block.

  • Updates the drift check to include proof size and to compare the actual benchmark-level weight instead of failing on noisy internal component drift.

@JohnReedV JohnReedV added the skip-cargo-audit This PR fails cargo audit but needs to be merged anyway label Jun 25, 2026
@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

🛡️ AI Review — Skeptic (security review)

VERDICT: VULNERABLE

Baseline scrutiny: established OpenTensor-associated contributor with repo write permission and substantial subtensor history; branch apply-benchmark-to-only-bad-benches -> devnet-ready.

The PR does not modify .github/ai-review/* or .github/copilot-instructions.md. Manifest edits only enable features on existing workspace dependencies; no new external dependency or Cargo.lock change is introduced.

Findings

Sev File Finding
HIGH pallets/subtensor/src/benchmarks.rs:3080 Benchmark the full-subnet registration path inline

Prior-comment reconciliation

  • 2caec2f2: not addressed — The benchmark still sets MaxAllowedUids to 4096 but does not populate the subnet to that size before calling register_limit, so it continues to measure append instead of prune/replace.

Conclusion

The PR appears legitimate, but the prior register_limit underweighting issue remains. Production registration can take the full-subnet prune/replace path while this benchmark still measures an empty-subnet append path.


📜 Previous run (superseded)
Sev File Finding Status
HIGH pallets/subtensor/src/benchmarks.rs:3080 Benchmark the full-subnet registration path ➡️ Carried forward to current findings
The benchmark still sets MaxAllowedUids to 4096 but does not populate the subnet to that size before calling register_limit, so it continues to measure append instead of prune/replace.

🔍 AI Review — Auditor (domain review)

VERDICT: 👎

Gittensor UNKNOWN; author has repo write permission, @opentensor profile context, and substantial recent subtensor history, so calibrated as established-contributor domain review.

PR body is substantive and matches the benchmark/tooling scope, so I would leave it unchanged.

Validation performed: bash -n scripts/benchmark_action.sh passed, and git diff --check origin/devnet-ready...HEAD passed. I did not run cargo tests because the blocking issue is visible from the benchmark setup and dispatch path.

Findings

Sev File Finding
HIGH pallets/subtensor/src/benchmarks.rs:3080 Benchmark the full-subnet registration path inline

Prior-comment reconciliation

  • 21660033: addressed — No conflict markers remain in pallets/proxy/src/weights.rs, and git diff --check origin/devnet-ready...HEAD passes.
  • ece3dc4d: addressed — No conflict markers remain in pallets/utility/src/weights.rs, and git diff --check origin/devnet-ready...HEAD passes.
  • 2cfa55a3: addressed — The WeightInfo matcher still requires a method-name boundary and retains regression coverage for prefix false positives such as swap_coldkey vs swap_coldkey_announced.

Conclusion

Blocking on the register_limit benchmark: the PR plugs this dispatch into generated weights, but the benchmark measures only the cheap append path while production can take the full-subnet replacement path. That can leave the generated weight materially below the worst-case execution cost.

@github-actions

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: SAFE Auditor: 👍

@github-actions

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: SAFE Auditor: 👍

@github-actions

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: SAFE Auditor: 👍

@github-actions

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: SAFE Auditor: 👍

@github-actions

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: SAFE Auditor: 👍

@JohnReedV JohnReedV changed the title Apply Benchmark patch only where its needed Improve Benchmarking Jun 26, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review — see the sticky summary comment for the verdict and the inline comments below for specific findings.

Comment thread pallets/proxy/src/weights.rs Outdated
Comment thread pallets/utility/src/weights.rs Outdated
@github-actions

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: SAFE Auditor: 👎

@github-actions

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: SAFE Auditor: 👍

@github-actions

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: SAFE Auditor: 👍

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review — see the sticky summary comment for the verdict and the inline comments below for specific findings.

Comment thread pallets/subtensor/src/benchmarks.rs
@github-actions

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: SAFE Auditor: 👎

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review — see the sticky summary comment for the verdict and the inline comments below for specific findings.

Comment thread pallets/subtensor/src/benchmarks.rs
@github-actions

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: VULNERABLE

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review — see the sticky summary comment for the verdict and the inline comments below for specific findings.

Comment thread pallets/subtensor/src/benchmarks.rs
@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: VULNERABLE

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review — see the sticky summary comment for the verdict and the inline comments below for specific findings.

let hotkey: T::AccountId = account("register_limit_hot", 0, 1);

Subtensor::<T>::init_new_network(netuid, 1);
Subtensor::<T>::set_max_allowed_uids(netuid, 4096);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[HIGH] Benchmark the full-subnet registration path

register_limit now supplies the production dispatch weight, but this benchmark only initializes an empty subnet, sets MaxAllowedUids to 4096, and then registers one neuron. That measures the cheap current_subnetwork_n < max_allowed append path. In production, once the subnet is full, do_register_limit -> do_register -> register_neuron takes the prune/replace path, including replace_neuron and clear_neuron, which clears existing weights/bonds and iterates stored weight rows. A signed caller can hit that path, so the generated weight can undercharge the expensive registration case. Populate the subnet to MaxAllowedUids with a prune candidate before the extrinsic call, or otherwise benchmark the worst-case full-subnet replacement path.

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: VULNERABLE

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review — see the sticky summary comment for the verdict and the inline comments below for specific findings.

let hotkey: T::AccountId = account("register_limit_hot", 0, 1);

Subtensor::<T>::init_new_network(netuid, 1);
Subtensor::<T>::set_max_allowed_uids(netuid, 4096);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[HIGH] Benchmark the full-subnet registration path

This still sets MaxAllowedUids to 4096 but does not populate the subnet before measuring register_limit. In production, do_register_limit delegates into do_register, and register_neuron only appends while SubnetworkN < MaxAllowedUids; once full, it calls get_neuron_to_prune and replace_neuron, which clears/rebuilds substantially more storage. The benchmark therefore keeps producing an append-path weight for an extrinsic that users can invoke on the heavier full-subnet prune/replace path. Seed the subnet to MaxAllowedUids with a pruneable candidate before the measured call, or benchmark the worst reachable path explicitly.

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: VULNERABLE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-cargo-audit This PR fails cargo audit but needs to be merged anyway

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant