Record zero-rate opt-outs in crown-time accounting#381
Merged
Conversation
A miner posting rate 0 means "no longer offering this direction," but refresh_miner_rates skipped r<=0 before persisting anything, so the stale positive rate stayed latest and kept earning crown credit. Persist a terminating zero event when a previously-offered direction drops to 0. Read the persisted latest rate so a zero posted during validator downtime reconciles on the next poll, and only record once.
91b560b to
1b699ad
Compare
anderdc
approved these changes
May 26, 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.
Closes #379.
Problem
A miner posting rate
0for a direction means "no longer offered" (#37 semantics, enforced by therate > 0filter incrown_holders_at_instant). Butrefresh_miner_ratescontinued onr <= 0before writing a rate event, so the opt-out never reached the persistedrate_eventsstream. Scoring'sget_latest_rate_beforekept returning the stale positive rate, and the leaving miner kept its crown — displacing miners still offering the direction.Fix
When a direction with a previously-positive rate drops to
0, persist a terminating0.0rate event. The check reads the persisted latest rate (viaget_latest_rate_before) rather than only the in-memorylast_known_rates, so:latest is None) records nothing — unchanged behavior;poll_commitmentsruns beforescore_and_reward_minersin the same forward step);Single-function change in
allways/validator/forward.py. No schema, API, UI, or contract changes — the existing prune logic already preserves the latest row per(hotkey, direction)as an anchor, so the zero survives as the terminator.Tests
test_poll_commitments.py: positive→zero records the opt-out; recorded once not per-poll; positive→zero→positive re-enables; zero-during-downtime reconciles against the persisted rate.test_scoring_v1.py: replay regression mirroring the issue —{hk_a: 500, hk_b: 500}after opt-out instead of{hk_a: 1000}.Full suite: 563 passed.
ruff format+ruff checkclean.