fix(subnets): count WeightsSet setters by uid, not by an absent hotkey - #9309
Merged
Conversation
/subnets/{netuid}/event-summary credited WeightsSet -- usually the
highest-volume kind on the subnet -- with 0 distinct participants beside a
five-figure event count. Measured live on netuid 64 at the route's default 30d
window: 9,830 events, hotkey_count 0, against a real 15 (17 at 90d).
The per-kind actor count grouped on `hotkey` alone. The WeightsSet chain event
emits [netuid, uid] and carries NO hotkey -- the column is NULL on all
50,890,747 rows in the export -- so the `hotkey IS NOT NULL` filter dropped
every row, the kind never appeared in that read, and the merge filled the gap
with 0.
Counts the same hotkey-or-uid identity the retired Postgres route counted, for
the reason that route stated: "WeightsSet ingestion can omit hotkey". The
weight-setter leaderboards already resolve the identity this way. netuid is
fixed by the WHERE here, so a bare uid is unambiguous; the retired query spelled
the (netuid, uid) pair only because it was not subnet-scoped. The prefixes keep
the two namespaces from colliding, and a row carrying neither key collapses to a
NULL actor that the outer filter drops -- matching COUNT(DISTINCT)'s own NULL
handling, which is what the previous per-column filter was there to reproduce.
coldkey_count deliberately keeps the plain distinct. A WeightsSet has no
delegating account, so there is nothing to fall back to and its zero there is
genuine, not a gap.
Zero was being published as a measured value on the busiest row of the card --
the same confident-zero failure this lane has been removing. The reader's own
header warned against publishing "9,832 WeightsSet events from 0 hotkeys"; it
guarded that against a failed query but not against the identity itself.
Verified by executing the reader's own emitted SQL against the live engine
rather than only its fake one: WeightsSet resolves to 15 at 30d and 17 at 90d,
and every other kind is byte-identical to what production already serves, so
the change is strictly additive. The tests that pinned the old behaviour
asserted the implementation rather than the route's contract, and are corrected
here; confirmed they bite by restoring the hotkey-only grouping.
Closes #9308
Refs #9146
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
metagraphed-data-api | a4bc8de | Aug 03 2026, 08:54 PM |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
metagraphed-registry-sync-api | a4bc8de | Aug 03 2026, 08:54 PM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
/subnets/{netuid}/event-summarycredited WeightsSet — usually the highest-volume kind on the subnet — with 0 distinct participants beside a five-figure event count. Measured live on netuid 64 at the route's default 30d window:{"event_kind":"WeightsSet","event_count":9830,"hotkey_count":0,"coldkey_count":0}The real distinct-setter count is 15 (17 at 90d). Every other kind on the card was already correct.
Cause
The per-kind actor count grouped on
hotkeyalone. The WeightsSet chain event emits[netuid, uid]and carries no hotkey — the column is NULL on all 50,890,747 rows in the export — sohotkey IS NOT NULLdropped every row, the kind never appeared in that read, and the merge filled the gap with0.The retired Postgres route counted a composite hotkey-or-uid identity for exactly this reason, and said so: "the distinct-actor count uses the same hotkey-or-(netuid,uid) identity as the weight-setters routes (WeightsSet ingestion can omit hotkey)". So this was a fidelity regression against prior behaviour, not a gap in the source data.
netuidis fixed by theWHEREhere, so a bare uid is unambiguous — the retired query spelled the pair only because it was not subnet-scoped. A row carrying neither key collapses to a NULL actor that the outer filter drops, reproducingCOUNT(DISTINCT)'s own NULL handling, which is what the previous per-column filter existed to do.coldkey_countdeliberately keeps the plain distinct. A WeightsSet has no delegating account, so there is nothing to fall back to and its zero there is genuine.Why this one mattered
Zero was published as a measured value on the busiest row of the card — the same confident-zero failure this lane has been removing (#9285, #9289). The reader's own header warns against publishing "9,832 WeightsSet events from 0 hotkeys"; it guarded that against a failed query, but not against the identity itself producing it.
Verification
Against the live engine, using the SQL the reader actually emits — not a hand-written approximation and not only its fake engine:
Every other kind (StakeAdded 65, StakeRemoved 82, AutoStakeAdded 6, StakeMoved 30, StakeTransferred 16, StakeSwapped 18, SetChildrenScheduled 19, NeuronRegistered 25, AxonServed 1) matches what the route already serves, so the change is strictly additive — it fixes one kind and perturbs nothing else.
Note on the tests
The tests pinning the old behaviour asserted the implementation rather than the route's contract — one literally read
assert.equal(byKind.WeightsSet.hotkey_count, 0, "WeightsSet carries no hotkey, so 0"). They passed at 100% coverage while the card published a wrong number. Corrected here to assert the contract, with a dedicated test for the fallback; confirmed they bite by restoring the hotkey-only grouping (6 tests fail).Checks
typecheck,lint, prettier: clean.contract-drift,no-hand-written-mjs,module-state-resets,private-boundary: pass. No contract change.Closes #9308
Refs #9146