Skip to content

refactor(validator): dedupe metagraph guards in PAT axon handlers#1573

Closed
ebios-star wants to merge 2 commits into
entrius:mainfrom
ebios-star:refactor/dedupe-pat-handler-metagraph-guards
Closed

refactor(validator): dedupe metagraph guards in PAT axon handlers#1573
ebios-star wants to merge 2 commits into
entrius:mainfrom
ebios-star:refactor/dedupe-pat-handler-metagraph-guards

Conversation

@ebios-star

Copy link
Copy Markdown
Contributor

Summary

The four PAT axon handlers in gittensor/validator/pat_handler.py come 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 — same hotkey → uid → S[uid] stake lookup, 0.0 when unregistered

This 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) -> float

Each 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

  • No public API change — the four async handler signatures are untouched; they're still what neurons/validator.py binds via partial(fn, self) and what the axon awaits.
  • No new base-class methods, no import reordering, no threaded params.
  • Behavior is identical; both helpers are plain sync functions the async handlers delegate to.
  • Full suite green (969 passed), including tests/validator/test_pat_handler.py (27 passed) which covers both blacklist branches. ruff check / ruff format --check clean.

Happy to adjust naming or scope. Thanks!

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>
@xiao-xiao-mao xiao-xiao-mao Bot added the refactor Code restructuring without behavior change label Jul 3, 2026
@anderdc

anderdc commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

PRs should target test branch

@anderdc anderdc closed this Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Code restructuring without behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants