Fix collateral-baseline zeroing that recycled emissions (v1.0.9)#443
Merged
Conversation
The in-process event watcher recorded a miner's collateral as 0 whenever it applied a fee/slash delta with no prior baseline: _apply_collateral_delta did prior + delta where _latest_collateral returned 0 for an unseen miner, and the result clipped to 0. The #409/#423 capacity / can_fund crown gate then read that 0 and dropped the miner from crown entirely, so honest active best-rate miners earned nothing and the pool recycled. - _apply_collateral_delta: skip when there is no known baseline (return None from _latest_collateral) instead of fabricating a 0. - reconcile_collateral_from_contract: resync active miners' collateral to on-chain truth; run at startup (heals the warm-restart path) and once per scoring round (corrects drift). Writes at the current block only, preserving the per-block capacity property. - scoring gate: fail open on unknown collateral (absent != zero) in both the replay and the live snapshot — the contract auto-deactivates anyone below min_collateral, so an active miner always holds enough. - diagnose_non_earner: direction-aware (tao->btc lower-wins) and collateral- aware, so it reports insufficient_collateral / unknown_collateral instead of mislabeling a better-rate miner as 'outbid'. Tests cover the no-baseline regression, reconcile (heal/skip/idempotent/rpc), fail-open vs known-zero, and the diagnosis reasons.
LandynDev
approved these changes
Jun 1, 2026
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.
Problem
Subnet 7 emissions were recycling ~90–100% to
RECYCLE_UID. Root cause confirmed on the live validator (sqlite + logs): the in-process event watcher records a miner's collateral as 0 whenever it applies a fee/slash delta with no prior baseline.On
SwapCompleted/SwapTimedOut,_apply_collateral_delta(block, miner, -fee/-slash)computesprior + delta, where_latest_collateralreturned 0 for a miner with no collateral event, and_record_collateral_eventclips negatives to 0. Smoking gun: UID 65's only collateral row was0 @ block 8311293— the exact block of itsSwapCompleted #2073— while axon-preflight logs showed ~0.48 TAO on-chain throughout.The
#409/#423capacity /can_fundcrown gate then reads that 0 (capacity_factor→ 0,can_fund→ false) and drops the miner from crown entirely → 0 emission. 8 of 14 tracked miners had latest collateral = 0, so crown only reached the few correctly-tracked miners and otherwise recycled. Scoring traces:window=[8312102,8312402] recycled=1.0,[8312402,8312702] recycled=0.90.Secondary: the scoring-trace diagnostic mislabeled these miners as
outbid(diagnose_non_earnernever checked collateral and wasn't direction-aware — it printed UID 65's better lower-wins rate279.3 vs best=280as a loss).Changes
event_watcher.py):_apply_collateral_deltaskips when there is no known baseline (_latest_collateralnow returnsOptional[int],None= unknown) instead of fabricating a 0.event_watcher.py, wired inforward.py+neurons/validator.py):reconcile_collateral_from_contractresyncs active miners' collateral to on-chain truth at startup (heals the warm-restart path, which does no contract reads → fixes the corrupted rows on redeploy) and once per scoring round (corrects drift). Writes at the current block only, preserving the#409per-block / no-post-window-top-up property.scoring.py):can_fundand capacity distinguish absent collateral (unknown → fail open: pass / capacity 1.0) from present-0 (genuinely withdrawn → excluded), in both the replay and the live snapshot. Safe because the contract auto-deactivates anyone belowmin_collateral, so an active miner always holds ≥0.1 TAO.scoring_trace.py):diagnose_non_earneris direction-aware (tao→btc lower-wins) and collateral-aware → reportsinsufficient_collateral/unknown_collateral/competitive_but_unfilledinstead of a blanketoutbid.Tests
pytest tests/— 657 passed. New/updated coverage:test_zero_collateral_zeros_rewardupdated to seed a real present-0 event, since the oldcollaterals={'hk_a':0}setup produced an absent series that now correctly fails open);diagnose_non_earnerreasons.Verification after deploy
On the validator: confirm the 8 zeroed hotkeys (incl.
5Hb1Lxqm…) repopulate instate.db,V1 scoringrecycleddrops below 0.90, active best-rate miners' per-uid line showscap>0/nonzero reward, and leaderboard crownShare rises over subsequent rounds.