Skip to content

fix: sum emission across mechanisms instead of weighting it - #3038

Open
kyron1112567 wants to merge 1 commit into
RaoFoundation:mainfrom
kyron1112567:fix/mechanism-emission-aggregation
Open

fix: sum emission across mechanisms instead of weighting it#3038
kyron1112567 wants to merge 1 commit into
RaoFoundation:mainfrom
kyron1112567:fix/mechanism-emission-aggregation

Conversation

@kyron1112567

Copy link
Copy Markdown

Fixes #2194.

Problem

epoch_with_mechanisms merges each mechanism's EpochTerms, but aggregates two dimensionally different kinds of field the same way:

acc_terms.validator_emission = acc_terms.validator_emission.saturating_add(terms.validator_emission);
acc_terms.server_emission    = acc_terms.server_emission.saturating_add(terms.server_emission);
...
acc_terms.emission = Self::weighted_acc_alpha(acc_terms.emission, terms.emission, sub_weight);

The fields weighted alongside emissionconsensus, dividend, validator_trust, stake_weight — are normalized ratios, where a weighted sum is correct. emission is an absolute alpha amount: per mechanism it equals server_emission + validator_emission, the two fields summed immediately above it. Weighting it reports a fraction of what the hotkey was actually paid.

persist_netuid_epoch_terms writes that value into Emission, which is what the metagraph reports per UID. On an even N-mechanism split it reads ~1/N of the real figure.

This was first reported in #2194 (Nov 2025) and independently confirmed by the owner of a subnet running mechanisms on mainnet. The issue was closed on 2026-07-31 with no linked commit or PR; the defect is unchanged on main.

Not just display

get_neuron_to_prune reads Emission and selects the lowest value. On an uneven split the weighting can invert relative order between mechanism-specialized neurons:

Subnet emits 1000, split 25/75. Neuron A earns 100 in mech0, neuron B earns 50 in mech1.
Actual: A=100, B=50 — B is the lower earner.
Reported: A=25, B=37.5 — A is pruned instead.

So on multi-mechanism subnets with a non-even split this can deregister the higher earner. That is a behaviour change, hence the spec_version bump.

Payout-neutral

epoch_with_mechanisms returns (hotkey, terms.server_emission, terms.validator_emission) and never returns terms.emission. Those two were already summed and are untouched here, so no hotkey's alpha changes. This matches @dougsillars' original observation that miners were being paid correctly and only the reported value was wrong.

Change

  • Sum emission across mechanisms instead of weighting it, in both the and_modify and or_insert_with arms.
  • Drop weighted_acc_alpha, now unused.
  • spec_version 442 → 443.

Tests

Added epoch_with_mechanisms_persisted_emission_matches_paid_emission: asserts persisted Emission per UID equals server_emission + validator_emission for that hotkey, and that the per-UID total accounts for the whole epoch emission. It uses an uneven 25/75 split with each miner favoured by a different mechanism, so the weighting cannot cancel out.

Against the unfixed aggregation it fails as expected:

assert_abs_diff_eq!(reported, credited, epsilon = 8)
    left  = 312505722   // Emission storage
    right = 500000000   // server_emission + validator_emission

Also updated the emission assertion in epoch_with_mechanisms_persists_and_aggregates_all_terms, which encoded the previous behaviour.

Locally: cargo fmt --check --all clean, cargo clippy -p pallet-subtensor --all-targets -- -D warnings clean, cargo test -p pallet-subtensor --lib 1397 passed / 0 failed.

Emission is an absolute alpha amount, not a normalized ratio, so aggregating
it as a weighted sum reported roughly 1/N of what a hotkey on an N-mechanism
subnet was actually paid. Sum it like server_emission and validator_emission,
which come from the same per-mechanism split.

Emission also orders pruning candidates, so with an uneven split this could
rank a higher earner below a lower one.

Bump spec_version to 443.
@vercel

vercel Bot commented Aug 4, 2026

Copy link
Copy Markdown

@kyron1112567 is attempting to deploy a commit to the RaoFoundation Team on Vercel.

A member of the Team first needs to authorize it.

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.

metagraph emission is incorrect for miners in subnets with subsubnets/mechanisms.

1 participant