Python client lockstep: per-topology difficulty + mineable-topology whitelist#17
Merged
Conversation
…e helpers - scale_codec: add _decode_h256_vec (compact-u32 length + N×32-byte hashes) - client: query_difficulty now takes optional topology_hash; resolves DefaultTopology when None and queries QuantumPow.Difficulties map - client: add query_mineable_topologies (QuantumPowApi_mineable_topologies) - client: add query_difficulty_for (QuantumPowApi_difficulty_for, Option-decode) - client: add add_mineable_topology / remove_mineable_topology extrinsic helpers - pool_client / pool: wire up new read ops as idempotent ops - tests: update query_difficulty callers for new signature; add unit tests for _decode_h256_vec and monkeypatched query_mineable_topologies / query_difficulty_for
…egister_advantage2 --mineable
miner_bootstrap._maybe_seed_chain: register topology BEFORE set_difficulty
(runtime now ensure!s topology is in RegisteredTopologies); pass
topology_hash in set_difficulty params; derive seed_topology_hash from
the snapshot returned after registration (or from the existing snapshot).
query_difficulty is now called with the resolved topology hash.
register_advantage2.main: restructure to the required order —
1. compute target_hash
2. register_topology (idempotent)
3. add_mineable_topology if not already whitelisted (required; runtime
rejects set_default_topology with TopologyNotMineable otherwise)
4. set_difficulty with {topology_hash, difficulty} (per-topology)
5. set_default_topology (topology registered + whitelisted)
download_and_validate_wins: no change needed — already per-topology via
_topology_for(topology_hash) and snapshot.difficulty throughout.
The per-solution participation remark was a stopgap from before the pallet had a miner registry: a free-form System.remark JSON blob per solution to record that a node was mining. The pallet now tracks this natively — register_miner reserves a deposit and records identity, and submit_proof increments proofs_submitted/proofs_won in the Miners map — so the remark is redundant transport for data the chain already owns. Remove the whole producer->consumer chain: - base_miner: participating_cb param + gate emit + _participation_extra - dwave_miner: _participation_extra override (budget_seconds) - miner_worker: _emit_participating and its wiring - miner_controller: _mark_participating, _submit_participation_remark, the op=="participating" drain branch, dedup state, retry constants, and the now-unused submit_remark import The descriptor/identify hardware-specs remarks keep using System.remark (register_miner takes no payload, so there is no pallet equivalent).
test_controller_submits_proof_end_to_end and test_controller_long_haul_multi_block drive _maybe_seed_chain, which reads/writes difficulty through the per-topology QuantumPow.Difficulties map (quip-protocol-rs MR !42). Against an older runtime that path raised StorageFunctionNotFound deep in bootstrap, hard-failing instead of skipping. Add a metadata probe (_chain_has_per_topology_difficulty) and gate both tests on it, mirroring the existing _chain_requires_hybrid_signer pattern, so they skip cleanly until the runtime is deployed.
test_mining_snapshot_either_returns_or_none and test_query_difficulty_either_returns_or_none read difficulty/snapshot through the per-topology QuantumPow.Difficulties map (rc4 / MR !42). Against a pre-MR!42 runtime they raised StorageFunctionNotFound instead of skipping. Add the same _chain_has_per_topology_difficulty metadata probe used by the controller tests and gate both on it.
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.
Draft — do not merge until the runtime change is deployed. Depends on
quip-protocol-rsMR !42 (per-topology difficulty + mineable-topology whitelist). The new runtime API/encoding this targets does not exist on chain until that ships.Summary
Keeps the Python client in lockstep with the Substrate change that binds PoW difficulty per topology and gates mining on a root-controlled whitelist. Also retires the per-solution participation
System.remarkin favor of the pallet's native miner registry.Changes — per-topology difficulty + whitelist
substrate/client.pyquery_difficulty(topology_hash=None)now reads the per-topologyQuantumPow.Difficultiesmap (resolvesDefaultTopologywhenNone; absent entry returnsNone).query_difficulty_for(topology_hash)(runtime APIQuantumPowApi_difficulty_for, decodingOption<DifficultyConfig>).query_mineable_topologies()(runtime APIQuantumPowApi_mineable_topologies, decodingVec<H256>).add_mineable_topology/remove_mineable_topologysubmit helpers.substrate/scale_codec.py:_decode_h256_vec(compact length + N×32 bytes).substrate/miner_bootstrap.py:_maybe_seed_chainregisters the topology before seeding difficulty and passestopology_hashtoset_difficulty(now a two-argument call).tools/register_advantage2.py: restructured to compute the target hash, register, whitelist (add_mineable_topology),set_difficulty(topology_hash, …), thenset_default_topology— the order the new runtime requires (set_difficultyneeds the topology registered;set_default_topologyrejects non-whitelisted targets). This file was previously an uncommitted local tool and is now tracked.tools/download_and_validate_wins.py: no change needed — already re-validates against the per-topology snapshot difficulty.Changes — drop participation System.remark for pallet-native tracking
The per-solution participation remark was a stopgap from before the pallet had a miner registry: a free-form
System.remarkJSON blob per solution to record that a node was mining. The pallet now tracks this natively —register_minerreserves a deposit and records identity, andsubmit_proofincrementsproofs_submitted/proofs_wonin theMinersmap — so the remark is redundant transport for data the chain already owns.register_mineris already submitted at bootstrap (_ensure_registered).Removed the whole producer→consumer chain:
shared/base_miner.py:participating_cbparam + dispatch-gate emit +_participation_extra.QPU/dwave_miner.py:_participation_extraoverride (budget_seconds).shared/miner_worker.py:_emit_participatingand its wiring.substrate/miner_controller.py:_mark_participating,_submit_participation_remark, theop=="participating"drain branch, the participation dedup state, the retry constants, and the now-unusedsubmit_remarkimport.test_base_miner_pump.py,test_dwave_stream_stop.py,test_substrate_miner_controller.py.The descriptor/
identifyhardware-specs remarks keep usingSystem.remark—register_minertakes no payload, so there is no pallet equivalent for broadcasting GPU/CPU specs.Testing
ruff check/ruff format --checkclean on touched files._decode_h256_vectests build real SCALE wire bytes; new runtime-API helpers covered via monkeypatched_state_call.skipif-gated on a running node and require the deployed runtime to exercise end to end.Live test gating
test_controller_submits_proof_end_to_endandtest_controller_long_haul_multi_blockdrive_maybe_seed_chain, which reads/writes difficulty through the per-topologyQuantumPow.Difficultiesmap. They now probe the connected chain's metadata (_chain_has_per_topology_difficulty) and skip cleanly against a pre-MR!42 runtime instead of hard-failing — mirroring the existing_chain_requires_hybrid_signergate. They exercise end to end once the new runtime is deployed to the test chain.Follow-ons (non-blocking)
pool.py/pool_client.py) forwardsquery_mineable_topologiesbut does not thread anatblock parameter (matches the existingquery_current_difficultypattern); admin extrinsics are not surfaced onPoolClient(they use the direct/sudo client).