Skip to content

fix(validator): align event watcher busy state with reservations and TTL#327

Open
thomascolden585-svg wants to merge 1 commit into
entrius:testfrom
thomascolden585-svg:fix/326-miner-reserved-busy-delta
Open

fix(validator): align event watcher busy state with reservations and TTL#327
thomascolden585-svg wants to merge 1 commit into
entrius:testfrom
thomascolden585-svg:fix/326-miner-reserved-busy-delta

Conversation

@thomascolden585-svg
Copy link
Copy Markdown

@thomascolden585-svg thomascolden585-svg commented May 14, 2026

Summary

Closes ##326

Aligns ContractEventWatcher busy tracking with on-chain reservations as well as swaps: MinerReserved / ReservationCancelled, bootstrap from get_miner_reserved_until when there is no active swap row, and a synthetic busy -1 at reserved_until + 1 because the contract clears expired reservations lazily with no event.

Crown-time replay now treats a reserved miner (including reservation-only episodes with no SwapInitiated) as busy through the correct block range, so crown credit flows to the next eligible miner until the reservation lapses or is cancelled.

Changes

  • allways/validator/event_watcher.py
    • Handle MinerReserved, ReservationCancelled, and SwapInitiated transitions so reservation busy and swap busy do not double-count.
    • Bootstrap busy state from active reservations (TTL from contract or RESERVATION_TTL_BLOCKS), with bootstrapped_reserved_miners so replay does not apply a second +1.
    • _apply_reservation_expiry_synthetics during sync_to to emit the missing busy -1 at reservation expiry.
    • Extend reserved_until on TimeoutExtensionFinalized when the miner is in reservation-only busy state.
  • tests/test_event_watcher.py: unit tests for reservation busy, cancel, swap handoff, and bootstrap replay.
  • tests/test_scoring_v1.py: integration-style crown replay test where the best-rate miner is reserved without a swap and the runner-up receives crown share until expiry.

How to test

uv sync
uv run pytest tests/test_event_watcher.py tests/test_scoring_v1.py -q

(Full suite: uv run pytest tests/)

Checklist

  • Branch is up to date with target base
  • Tests pass (uv run pytest tests/)
  • Lint clean where touched (uv run ruff check allways/ neurons/)

Related

@xiao-xiao-mao xiao-xiao-mao Bot added the bug Something isn't working label May 14, 2026
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.

1 participant