refactor(validator): dedupe metagraph guards in PAT axon handlers#1573
Closed
ebios-star wants to merge 2 commits into
Closed
refactor(validator): dedupe metagraph guards in PAT axon handlers#1573ebios-star wants to merge 2 commits into
ebios-star wants to merge 2 commits into
Conversation
The broadcast/check handler pairs carried byte-for-byte identical bodies: blacklist_pat_broadcast/blacklist_pat_check shared the same unregistered-hotkey rejection, and priority_pat_broadcast/priority_pat_check shared the same stake lookup. Extract two small module-level helpers, _blacklist_if_unregistered and _stake_priority, so each rule lives in one place and the two handler pairs can't drift out of sync. Public handler signatures are unchanged; behavior is identical. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Collaborator
|
PRs should target test branch |
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.
Summary
The four PAT axon handlers in
gittensor/validator/pat_handler.pycome in two broadcast/check pairs that carried byte-for-byte identical bodies:blacklist_pat_broadcast/blacklist_pat_check— same unregistered-hotkey rejection (Hotkey {…}… not registered/Hotkey recognized)priority_pat_broadcast/priority_pat_check— samehotkey → uid → S[uid]stake lookup,0.0when unregisteredThis extracts two small module-level helpers so each rule lives in one place:
_blacklist_if_unregistered(validator, synapse) -> Tuple[bool, str]_stake_priority(validator, synapse) -> floatEach helper is now the single source of truth for its rule, so the broadcast and check handlers can't drift out of sync (same rejection string, same stake formula).
Why
The two blacklist handlers must return the identical rejection message/shape, and the two priority handlers must apply the identical stake formula — today that invariant is only held by copy-paste. Consolidating enforces it structurally.
Scope / safety
asynchandler signatures are untouched; they're still whatneurons/validator.pybinds viapartial(fn, self)and what the axon awaits.969 passed), includingtests/validator/test_pat_handler.py(27 passed) which covers both blacklist branches.ruff check/ruff format --checkclean.Happy to adjust naming or scope. Thanks!