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

@RealDiligent RealDiligent commented Jul 8, 2026

Copy link
Copy Markdown

Fixes #1606

Summary

Realigns persisted validator scores/hotkeys to the live metagraph on load_state() and resync_metagraph(), preventing IndexError crashes and misaligned on-chain weights after subnet resize + restart.

Root cause

load_state() restored raw state.npz arrays without validating len(scores) == metagraph.n. Runtime resync_metagraph() only padded on growth and never truncated on shrink.

Fix approach

  • Add _align_scores_to_metagraph() to resize scores, preserve overlapping prefix, and zero slots where persisted hotkey != current metagraph hotkey
  • Call from load_state() and resync_metagraph()
  • Set self.hotkeys from live metagraph after load (not stale persisted list)

Impact

Validators survive routine subnet resize/restart without crashing or emitting misaligned weights.

Risk / tradeoffs

  • Replaced hotkeys lose prior scores (intended — same as runtime resync behavior)
  • No change to scoring logic beyond state alignment

Test plan

@RealDiligent

Copy link
Copy Markdown
Author

@RealDiligent RealDiligent force-pushed the fix/critical-issue-state-metagraph-align branch from d28d21f to 5cefb4b Compare July 15, 2026 06:14
RealDiligent and others added 4 commits July 15, 2026 14:19
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>
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