Skip to content

Persist scoring window and voted swaps across validator restarts#17

Open
bitloi wants to merge 3 commits intoentrius:testfrom
bitloi:fix/scoring-window-persistence
Open

Persist scoring window and voted swaps across validator restarts#17
bitloi wants to merge 3 commits intoentrius:testfrom
bitloi:fix/scoring-window-persistence

Conversation

@bitloi
Copy link
Copy Markdown

@bitloi bitloi commented Apr 7, 2026

Closes #16

Summary

  • Add ScoringWindowStore for atomic JSON persistence of the scoring window and voted set, following the existing tmp-file-then-rename pattern used by SwapFulfiller._save_sent_cache.
  • Wire persistence into SwapTracker load on initialize(), persist on swap resolution, window pruning, and mark_voted().
  • Remove duplicate _resolved_block helper by sharing a single resolved_block() from the store module.
  • Create store in validator init with cache path at <neuron.full_path>/scoring_window.json.

Design

Persistence hooks at every state mutation point only. The store is optional (None disables persistence) so existing tests and standalone usage remain unaffected. On cold start, stale voted IDs are pruned against the active swap set to prevent unbounded growth.

Test plan

  • ruff check allways/validator/scoring_store.py allways/validator/swap_tracker.py neurons/validator.py passes
  • python3 -m pytest tests/test_rate.py tests/test_chains.py -q --tb=short passes
  • python3 -m pytest tests/test_scoring_store.py -q --tb=short passes (local)
  • Roundtrip serialization preserves window and voted IDs
  • Corrupt/missing cache file falls back to empty state
  • Stale voted IDs pruned on restart when no active swaps exist
  • Window entries older than SCORING_WINDOW_BLOCKS pruned on load

@bitloi
Copy link
Copy Markdown
Author

bitloi commented Apr 7, 2026

@LandynDev @anderdc Ready for review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Validator restart loses scoring window and can wipe miner weights

1 participant