Extract _walk_replay_events for shared crown derivation#320
Closed
LandynDev wants to merge 2 commits into
Closed
Conversation
Miner-dashboard groundwork: split the aggregate replay into a generator (_walk_replay_events) and two thin wrappers — replay_crown_time_window (validator scoring, unchanged numbers) and replay_crown_time_window_iter (per-block display path used by the alw-utils sync utility). Both consumers now share the qualification rule and state machine. Also opens ValidatorStateStore for read-only callers via a readonly URI mode + a get_rate_events_since_id tail-by-id accessor.
4 tasks
Collaborator
Author
|
Closing — going with Option A: porting the crown-derivation logic into the alw-utils sync utility instead, so the validator's consensus code stays untouched. The dashboard accepts the drift cost (display-only, not consensus-critical). Tracking in alw-utils#56. |
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.
Problem → Solution
Problem — dashboard sync needs per-block crown derivation, but the logic lives inside an aggregation loop
replay_crown_time_windowreturns{hotkey: blocks}totals. The dashboard's per-block grid needs(block, holders, rate)per block, and re-implementing the qualification rule in two places guarantees drift._walk_replay_events— a generator yielding one record per uniform-state interval(start, end, holders, best_rate). Both the validator aggregate (replay_crown_time_window) and the new display path (replay_crown_time_window_iter) are thin wrappers around it. Single source of truth for the qualification rule (active, not busy, has rate > 0, lower-rate-wins-when-reversed).Problem — external readers can't open the validator's SQLite without risking a write
state.dbfrom another process.ValidatorStateStore(readonly=True)opens via SQLite URI mode (file:...?mode=ro), skips DDL +journal_mode=WAL, surfaces writes asOperationalError. Plusget_rate_events_since_id(cursor)so readers can tail the autoincrement log.Validator behaviour unchanged
The refactor is a pure rearrangement: existing
replay_crown_time_windowcallsites inscore_and_reward_minerskeep producing identical numbers. Aggregating the iter wrapper's records also reproduces the totals — covered bytests/validator/test_scoring_iter.py::TestIterAggregateParity.Test plan
pytest tests/test_scoring_v1.py tests/validator/test_scoring_iter.py— 58/58 passing locally (47 existing + 11 new)ruff check allways/validator/scoring.py allways/validator/state_store.py tests/validator/— cleanSUM(credit)over the iter path equalsreplay_crown_time_windowtotalsRelated PRs
Part of the miner-dashboard rollout — merge in dependency order: