Skip to content

Harden contract + simplify scoring: trust active flag#57

Merged
entrius merged 6 commits intotestfrom
feat/block-deactivate-mid-swap
Apr 17, 2026
Merged

Harden contract + simplify scoring: trust active flag#57
entrius merged 6 commits intotestfrom
feat/block-deactivate-mid-swap

Conversation

@LandynDev
Copy link
Copy Markdown
Collaborator

Summary

  • Add vote_deactivate validator-consensus method to the contract, gated on collateral < min_collateral — dormant escape hatch for the rare min-raise case, no permanent storage bloat.
  • Block self-deactivate() while mid-swap or reserved so miners can't dodge in-flight obligations.
  • Short-circuit scoring to full recycle when the contract is halted (single RPC check at entry, RPC failure falls through to normal scoring).
  • Delete per-block collateral tracking from event_watcher.py/scoring.py — the contract's active flag is now authoritative.
  • Delete per-block config-event tracking; halt is evaluated once at scoring entry.

Result: crown_holders_at_instant collapses to active ∧ rewardable ∧ ¬busy ∧ rate > 0. Validator state tracks only the active set, busy deltas, and swap outcomes.

Commit chain

  1. Add vote_deactivate validator-consensus escape hatch
  2. Block miner deactivation while mid-swap or reserved
  3. Short-circuit scoring to full recycle when contract is halted
  4. Drop collateral tracking from scoring; trust active flag
  5. Drop config-event tracking; halt checked at scoring entry

Plan: plans/scoring-simplification-and-contract-hardening.md

Escape-hatch operational flow

If the owner ever raises min_collateral, maintainers ship a one-shot remediation script that iterates metagraph hotkeys, reads active + collateral via contract, and calls vote_deactivate(miner) for each active-but-below-floor miner. Validators run the release, quorum forms, active flag re-syncs with reality. No ongoing cost in normal operation.

Test plan

  • cd allways/smart-contracts/ink && cargo check — passes
  • cd allways && python -m pytest -q — 279 passed
  • ruff check && ruff format --check — clean
  • Deploy to dev env, attempt alw miner deactivate while reserved → expect CurrentlyReserved
  • set_halted(true) → next scoring window logs V1 scoring: halted, recycled full pool
  • Full E2E suite against dev env: ./tests/run.sh --chains btc

Dormant method gated by collateral < min_collateral so validators can kick active miners who fall below a raised floor without adding permanent per-flip bookkeeping to the contract.
Self-service deactivate() now rejects when the miner has an active swap or a live reservation so miners cannot dodge in-flight obligations. Adds HasActiveSwap / CurrentlyReserved errors and backfills the error variant map for SystemHalted (previously missing) plus the new Commit 1/2 additions.
Single RPC check at score_and_reward_miners entry sidesteps the per-block halt replay. RPC failure falls through to normal scoring so a flaky node does not zero every miner's reward.
Validator no longer replays collateral events or enforces min/max collateral in crown-time scoring — the contract's active flag is authoritative now that Commit 2 blocks self-deactivate mid-swap and vote_deactivate handles the min-raise edge case. Removes the CollateralEvent log, collateral/min_collateral snapshots, bootstrap reads, and all associated tests.
Removes the per-block config replay (ConfigEvent, CONFIG_KEYS_TRACKED, config_current/initial) from event_watcher and scoring. Halt is evaluated once at score_and_reward_miners entry; max_collateral and other scalars are no longer consulted because collateral-floor gating is trusted to the contract's active flag. EventKind collapses to ACTIVE/BUSY/RATE.
Wires contract_client.py to the vote_deactivate extrinsic added in Commit 1 so CLI/ops tooling (and the forthcoming alw-utils E2E suite) can invoke the validator-consensus deactivation path.
@entrius entrius merged commit 8e0c0f7 into test Apr 17, 2026
2 checks passed
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.

2 participants