Skip to content

fix(validator): realign persisted scores to metagraph size on load_state#1607

Open
RealDiligent wants to merge 4 commits into
entrius:testfrom
RealDiligent:fix/critical-issue-state-metagraph-align
Open

fix(validator): realign persisted scores to metagraph size on load_state#1607
RealDiligent wants to merge 4 commits into
entrius:testfrom
RealDiligent:fix/critical-issue-state-metagraph-align

Conversation

@RealDiligent

Copy link
Copy Markdown

Fixes #1606

Summary

Fixes validator crashes and misaligned weight emission after a subnet resize followed by validator restart.

Root cause

load_state() restored scores/hotkeys from state.npz without validating length against the current metagraph.n. resync_metagraph() only handled growth at runtime and could index past the live metagraph on shrink.

Fix approach

  • Add _align_scores_to_metagraph() to resize persisted scores, zero replaced hotkeys, and match metagraph.n.
  • Call it from load_state() and resync_metagraph().

Impact

Validators survive routine subnet resizes across restarts instead of crashing or emitting wrong weights.

Risk / tradeoffs

  • New UIDs after growth start at score 0 until scored; this matches existing runtime growth behavior.
  • Shrunk subnets drop scores for removed UIDs; those slots no longer exist on-chain.

Test plan

  • test_align_scores_grows_with_metagraph
  • test_align_scores_shrinks_with_metagraph
  • test_align_scores_zeros_replaced_hotkey
  • test_load_state_realigns_persisted_scores_to_current_metagraph
  • CI Tests + Lint workflows

RealDiligent and others added 3 commits July 9, 2026 06:57
load_state() restored scores/hotkeys from state.npz without resizing to the
current metagraph.n, causing IndexError or misaligned on-chain weights after
subnet growth or shrink. Realign persisted scores on load and consolidate
metagraph resize handling in resync_metagraph().

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@RealDiligent

Copy link
Copy Markdown
Author

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(validator): load_state desyncs scores after metagraph resize on restart

1 participant