Skip to content

Add rank-pinned emission gate bar (EmissionBarRank) as alternative to q-mass quantile - #3014

Open
unarbos wants to merge 4 commits into
mainfrom
feat/emission-bar-rank
Open

Add rank-pinned emission gate bar (EmissionBarRank) as alternative to q-mass quantile#3014
unarbos wants to merge 4 commits into
mainfrom
feat/emission-bar-rank

Conversation

@unarbos

@unarbos unarbos commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds EmissionBarRank (u16, default 64): the emission gate bar theta is pinned to the Nth-largest positive demand share instead of being derived from the EmissionBarQuantile q-mass crossing. Setting 0 restores quantile mode.
  • Activates immediately at upgrade: the default of 64 plus a one-shot migration (migrate_reset_emission_gate_bar) that kills the stale quantile-derived bar means the rank-64 bar applies from the first recompute after the runtime upgrade — no 360-block cadence delay, no separate sudo call.
  • Adds sudo_set_emission_bar_rank (call index 102) in admin-utils, with weights and benchmark. The setter kills EmissionGateBar so a changed rank takes effect on the next block, same as the quantile setter.
  • Wires the integration surface: all three emission gate setters (quantile, rank, exponent) added to the RootConfigCalls proxy group (the first two were missed in v440 and have been failing call-group coverage on every PR since), and the Python SDK wire layer regenerated for spec 441.

Motivation

A fixed q approximates a "top N" policy but decays as the demand distribution shifts:

  • q = 0.75 was tuned to land the bar at rank 32; on the current Finney distribution it crosses at rank 28. The gate concentrates emissions, which concentrates price shares, which makes the same q cross earlier — the eligible set ratchets tighter without anyone deciding that.
  • Deep in the tail the cumulative share grows ~0.003 per rank, so the valid q band for a target rank is razor-thin (e.g. rank 64 requires q in (0.9464, 0.9497] today) and would need manual retuning every few weeks.

Rank mode expresses "the top N subnets carry the gate midpoint" directly and self-adjusts. Everything downstream is untouched: Hill gate shape, h, the 360-block recompute cadence, and the underflow fallback.

Expected effect at N=64, h=3 against live Finney state: theta = 0.00339, gate passes 0.927 at rank 32, 0.500 at rank 64, 0.087 at rank 80; post-gate emission mass top4 = 32.5%, top32 = 84.9%, top64 = 98.5%. Compared to today's rank-28 bar, this keeps concentration at the top while giving the 33-64 band a real gradient to climb.

If fewer than N subnets have positive demand, theta falls back to the smallest positive share so emissions are never stranded.

Test plan

  • Rank-mode coverage in tests/subnet_emissions.rs: default-64 guard, Nth-largest selection, zero-share exclusion, ties at the bar, fewer-than-N fallback (the everyone-passes path), setter kill-and-recompute mid-interval
  • Migration test (test_migrate_reset_emission_gate_bar): stale bar killed, idempotent on second run
  • Full pallet-subtensor suite green (1332+ tests); quantile-mode tests pin EmissionBarRank = 0 explicitly
  • proxy_filters runtime tests green including all_call_groups_cover_runtime_call_metadata
  • SDK checks green: codegen.check --coverage, --names, pytest (984 passed)
  • cargo check -p pallet-subtensor -p pallet-admin-utils --features runtime-benchmarks

A fixed EmissionBarQuantile drifts as the demand distribution shifts: q=0.75
was tuned to land the bar at rank 32 but already crosses at rank 28, and deep
in the tail the valid q band for a target rank is only ~0.003 wide. When the
policy intent is "top N subnets", express it directly: EmissionBarRank (N > 0)
pins theta to the Nth-largest positive demand share, self-adjusting as the
distribution moves. Default 0 keeps quantile mode; no behavior change until
root sets the rank via sudo_set_emission_bar_rank.

Co-authored-by: Cursor <cursoragent@cursor.com>
@vercel

vercel Bot commented Jul 29, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
subtensor Ready Ready Preview, Comment Jul 29, 2026 1:47pm

Request Review

@github-actions

github-actions Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

🛡️ AI Review — Skeptic (security review)

VERDICT: SAFE

MEDIUM scrutiny: 4-month-old account with repository write access and extensive substantive merged history; disclosed Cursor/review-bot commits; no Gittensor association found; feat/emission-bar-rank -> main.

Static analysis found rank selection bounded by the existing share set, without panic-prone indexing or unchecked arithmetic. The setter remains root-authorized, migration accounting is bounded, the runtime version is bumped, and no dependency, CI, or AI-review trust-boundary files changed.

Findings

No findings.

Conclusion

No malicious behavior or security vulnerability was identified in the current PR delta.


🔍 AI Review — Auditor (domain review)

VERDICT: 👍

UNKNOWN Gittensor association; established contributor with repository write access and extensive merged history.

The prior coverage gap is addressed by dedicated tests for rank selection, zero-share exclusion, ties, fewer-than-N fallback, default configuration, setter-triggered recomputation, and migration idempotence. The required spec_version bump to 441 is present.

PR #3013 targets the same rank-64 policy through a fixed quantile. This PR is the better candidate; recommend closing #3013 because rank selection directly expresses the policy and adapts to distribution changes.

Targeted tests could not be rerun because rustup attempted to write beneath the read-only runner home; static inspection confirms the added tests exercise the previously uncovered branch.

Findings

No findings.

Prior-comment reconciliation

  • faec2dfa: addressed — Dedicated rank-mode and administrative-setter behavior tests now exercise the new default-enabled economic path and its relevant boundaries.

Conclusion

The implementation matches its description and now has appropriate boundary and migration coverage. No substantive issues remain.


📜 Previous run (superseded)
Sev File Finding Status
HIGH pallets/subtensor/src/coinbase/subnet_emissions.rs:431 Add tests for the new economic rank path ✅ Addressed
Dedicated rank-mode and administrative-setter behavior tests now exercise the new default-enabled economic path and its relevant boundaries.

@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.

if cumulative >= q {
break;
let rank = EmissionBarRank::<T>::get();
let theta = if rank > 0 {

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] Add tests for the new economic rank path

This introduces a new emission-selection formula without dedicated tests. Existing gate tests only exercise the unchanged quantile path. Add coverage proving the selected theta for rank 1 and an interior rank, the fallback when rank exceeds the number of positive shares, zero-share handling, ties at the boundary, rank 0 compatibility, and that the root setter stores the rank and invalidates EmissionGateBar. Economic logic requires explicit boundary coverage.

@github-actions

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: SAFE Auditor: 👎

Rank mode activates at upgrade: theta pins to the 64th-largest demand share
instead of the q=0.75 quantile crossing (rank 28 on the current distribution
and drifting tighter as emissions concentrate price shares). Tests that
assert quantile gate math now pin EmissionBarRank to 0 explicitly.

Co-authored-by: Cursor <cursoragent@cursor.com>

@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.

if cumulative >= q {
break;
let rank = EmissionBarRank::<T>::get();
let theta = if rank > 0 {

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] Add tests for the new economic rank path

This remains untested: the added test changes all explicitly set EmissionBarRank to 0, so none execute this branch even though rank 64 is now the runtime default. Add focused coverage proving selection at rank 1 and an interior rank, fallback when rank exceeds the positive-share count, exclusion of zero shares, and recomputation after sudo_set_emission_bar_rank clears the cached bar. This changes emission allocation at upgrade and requires boundary tests.

@github-actions

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: SAFE Auditor: 👎

…indings

- migrate_reset_emission_gate_bar kills the stale quantile theta so the
  rank-64 bar applies from the first recompute after the upgrade instead
  of waiting out the 360-block cadence
- cover the rank path: default-64 guard, Nth-largest selection, zero-share
  exclusion, ties at the bar, fewer-than-N fallback (the live mainnet
  shape), and setter kill-and-recompute mid-interval
- add the three emission gate setters (quantile, rank, exponent) to the
  RootConfigCalls proxy group; the first two were missed in v440 and have
  been failing call-group coverage on every PR since
- regenerate SDK wire layer for spec 441 with sudo_set_emission_bar_rank
  and the EmissionBarRank storage item; mark the gate setters raw-only

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: SAFE Auditor: 👍

@unarbos unarbos mentioned this pull request Jul 29, 2026
1 task
@gzaentz

gzaentz commented Jul 29, 2026

Copy link
Copy Markdown

Like this overall, think having buybacks capped at unburned miner emissions is better implementation for similiar effect

@gzaentz

gzaentz commented Jul 29, 2026

Copy link
Copy Markdown

here updated PR for capping chainbuys at unburned miner emissions - #3017 (comment)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants