Skip to content

Rework weight_consensus onto contract Backend protocol - #1667

Closed
LandynDev wants to merge 1 commit into
feat/2a-3-python-contract-clientfrom
feat/2a-4-contract-backend
Closed

Rework weight_consensus onto contract Backend protocol#1667
LandynDev wants to merge 1 commit into
feat/2a-3-python-contract-clientfrom
feat/2a-4-contract-backend

Conversation

@LandynDev

Copy link
Copy Markdown
Collaborator

Part of repo-registration phase 2a (task 2a-4). Stacked on #1666 (python client) — merge order #1665 -> #1666 -> this.

Re-lands the consensus core from the closed commitments-based attempt (#1651's successor branch) reworked onto an injected Backend protocol with the repos-v0 contract as transport:

  • backend.pyConsensusBackend protocol: fetch_registry / fetch_baskets / fetch_own_basket / publish_basket / fetch_stakes_and_permits (spec S4; metagraph reads behind the same protocol per S5)
  • contract_backend.pyContractBackend over RepoRegistryContractClient; snapshot block number resolves to a block hash once and every childstate read pins to it (S1 — closes the reorg gap the spec calls out), publish via set_basket signed by hotkey (S3)
  • consensus.py — cherry-picked verbatim except the input seam: structured baskets + validate_prefs replace bytes + decode_prefs (R3: second decode site is now validate-only)
  • codec.pycanonicalize_prefs kept verbatim (R4); zlib wire format, SCALE payload walker, CONSENSUS_MAX_PAYLOAD_BYTES, CONSENSUS_FRESH_WINDOW_BLOCKS deleted
  • chain.py (commitments transport) deleted; mirror_sync.py NOT re-landed — mirror reconciliation moved to das-github-mirror fix: repo names #229; validator has zero mirror-write responsibilities, MirrorClient stays read-only
  • neurons/validator.py — consensus manager init is failure-safe: missing contract address or init error degrades to baked weights, never blocks startup
  • Manager cache/fallback ladder, apply_consensus, postgres storage unchanged per spec

Decisions flagged for review (details in code):

  • basket github_id -> name resolution happens inside ContractBackend at the same pinned hash (deterministic across validators); deregistered ids dropped, per-voter renormalization absorbs the weight
  • publish filters unregistered repo names with a warning and re-quantizes survivors; skip-if-equal prevents tx spam

Tests: +67 (golden aggregation vectors, fallback ladder via FakeBackend, pinned-hash propagation, validate-only decode, publisher edges); full suite 1104 passed; ruff clean.

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.

1 participant