Harden contract + simplify scoring: trust active flag#57
Merged
Conversation
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
approved these changes
Apr 17, 2026
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.
Summary
vote_deactivatevalidator-consensus method to the contract, gated oncollateral < min_collateral— dormant escape hatch for the rare min-raise case, no permanent storage bloat.deactivate()while mid-swap or reserved so miners can't dodge in-flight obligations.event_watcher.py/scoring.py— the contract's active flag is now authoritative.Result:
crown_holders_at_instantcollapses toactive ∧ rewardable ∧ ¬busy ∧ rate > 0. Validator state tracks only the active set, busy deltas, and swap outcomes.Commit chain
Add vote_deactivate validator-consensus escape hatchBlock miner deactivation while mid-swap or reservedShort-circuit scoring to full recycle when contract is haltedDrop collateral tracking from scoring; trust active flagDrop config-event tracking; halt checked at scoring entryPlan:
plans/scoring-simplification-and-contract-hardening.mdEscape-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 callsvote_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— passescd allways && python -m pytest -q— 279 passedruff check && ruff format --check— cleanalw miner deactivatewhile reserved → expectCurrentlyReservedset_halted(true)→ next scoring window logsV1 scoring: halted, recycled full pool./tests/run.sh --chains btc