{"id":19358419,"url":"https://github.com/paritytech/polkadot-staking-miner","last_synced_at":"2025-04-07T15:05:33.103Z","repository":{"id":42454112,"uuid":"494785278","full_name":"paritytech/polkadot-staking-miner","owner":"paritytech","description":"polkadot staking miner","archived":false,"fork":false,"pushed_at":"2025-03-10T14:22:46.000Z","size":87130,"stargazers_count":28,"open_issues_count":17,"forks_count":14,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-03-17T11:59:59.375Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/paritytech.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-21T13:03:38.000Z","updated_at":"2025-03-10T14:22:49.000Z","dependencies_parsed_at":"2024-01-25T10:58:41.352Z","dependency_job_id":"3c2c0632-8fc7-4cc4-bca2-a4211d51a6f5","html_url":"https://github.com/paritytech/polkadot-staking-miner","commit_stats":null,"previous_names":["paritytech/polkadot-staking-miner","paritytech/staking-miner-v2"],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paritytech%2Fpolkadot-staking-miner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paritytech%2Fpolkadot-staking-miner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paritytech%2Fpolkadot-staking-miner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paritytech%2Fpolkadot-staking-miner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/paritytech","download_url":"https://codeload.github.com/paritytech/polkadot-staking-miner/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247675597,"owners_count":20977376,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T07:11:41.759Z","updated_at":"2025-04-07T15:05:33.080Z","avatar_url":"https://github.com/paritytech.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Polkadot staking miner\n\n[![Daily compatibility check against latest polkadot](https://github.com/paritytech/polkadot-staking-miner/actions/workflows/nightly.yml/badge.svg)](https://github.com/paritytech/polkadot-staking-miner/actions/workflows/nightly.yml)\n\nThis is a re-write of the [staking miner](https://github.com/paritytech/polkadot/tree/master/utils/staking-miner) using [subxt](https://github.com/paritytech/subxt) to avoid hard dependency to each runtime version.\n\nThe binary itself embeds [static metadata](./artifacts/metadata.scale) to\ngenerate a rust codegen at compile-time that [subxt provides](https://github.com/paritytech/subxt).\n\nRuntime upgrades are handled by the polkadot-staking-miner by upgrading storage constants\nand that will work unless there is a breaking change in the pallets `pallet-election-provider-multi-phase`\nor `frame_system`.\n\nBecause detecting breaking changes when connecting to a RPC node when using\n`polkadot-staking-miner` is hard, this repo performs daily integration tests\nagainst `polkadot master` and in most cases [updating the metadata](#update-metadata)\nand fixing the compile errors are sufficient.\n\nIt's also possible to use the `info` command to check whether the metadata\nembedded in the binary is compatible with a remote node, [see the info the command for further information](#info-command)\n\nEach release will specify which runtime version it was tested against but\nit's not possible to know in advance which runtimes it will work with.\n\nThus, it's important to subscribe to releases to this repo or\nadd some logic that triggers an alert once the polkadot-staking-miner crashes.\n\n## Usage\n\nYou can check the help with:\n\n```bash\n$ polkadot-staking-miner --help\n```\n\n### Monitor\n\nTo \"mine solutions\" and earn rewards, use a command like the following.\nPlease try this on a dev-chain before using real funds because it's\npossible to lose money.\n\n```bash\n$ cargo run --release -- --uri ws://localhost:9944 monitor --seed-or-path //Alice --dry-run seq-phragmen\n```\n\nThis is a starting point that will try compute new solutions to the\nvalidator set that also validates that transaction before submitting.\n\nFor further information regarding the different options run:\n\n```bash\n$ cargo run --release -- monitor --help\n```\n\n### Dry run\n\nIt's possible to mine a solution locally without submitting anything to the\nchain but it works only on blocks with a snapshot\n(when the event Phase::Signed → Phase::Off is emitted).\n\n```bash\n$ cargo run --release -- --uri ws://localhost:9944 dry-run --at 0xba86a0ba663df496743eeb077d004ef86bd767716e0d8cb935ab90d3ae174e85 seq-phragmen\n```\n\n### Emergency solution\n\nMine a solution that can be submitted as an emergency solution.\n\n```bash\n$ cargo run --release -- --uri ws://localhost:9944 emergency-solution --at 0xba86a0ba663df496743eeb077d004ef86bd767716e0d8cb935ab90d3ae174e85 seq-phragmen\n```\n\n### Info command\n\nCheck if the polkadot-staking-miner's metadata is compatible with a remote node.\n\n```bash\n$ cargo run --release -- --uri wss://rpc.polkadot.io info\nRemote_node:\n{\n  \"spec_name\": \"polkadot\",\n  \"impl_name\": \"parity-polkadot\",\n  \"spec_version\": 9431,\n  \"impl_version\": 0,\n  \"authoring_version\": 0,\n  \"transaction_version\": 24,\n  \"state_version\": 0\n}\nCompatible: YES\n```\n\n### Experimental monitor multi-block\n\nThis command is similar to the stable `monitor command` but targets the new pallet `pallet-election-provider-multi-block` which is currently only supported on asset-hub-next.\n\n```bash\npolkadot-staking-miner --uri ws://127.0.0.1:9966 experimental-monitor-multi-block --seed-or-path //Alice\n```\n\n### Prepare your SEED\n\nWhile you could pass your seed directly to the cli or Docker, this is highly **NOT** recommended. Instead, you should use an ENV variable.\n\nYou can set it manually using:\n```bash\n# The following line starts with an extra space on purpose, make sure to include it:\n SEED=0x1234...\n```\n\nAlternatively, for development, you may store your seed in a `.env` file that\ncan be loaded to make your seed available:\n\n`.env`:\n```bash\nSEED=0x1234...\nRUST_LOG=polkadot-staking-miner=debug\n```\nYou can load it using `source .env`.\n\n### Docker\n\nA Docker container, especially one holding one of your `SEED` should be kept as secure as possible.\nWhile it won't prevent a malicious actor to read your `SEED` if they gain access to your container,\nit is nonetheless recommended running this container in `read-only` mode:\n\n```bash\ndocker run --rm -it \\\n    --name polkadot-staking-miner \\\n    --read-only \\\n    -e RUST_LOG=info \\\n    -e SEED \\\n    -e URI=wss://your-node:9944 \\\n    polkadot-staking-miner dry-run\n```\n\n## Update metadata\n\nThe static metadata file is stored at [artifacts/metadata.scale](artifacts/metadata.scale)\n\nTo update the metadata you need to connect to a polkadot, kusama or westend node.\n\n```bash\n# Install subxt-cli\n$ cargo install --locked subxt-cli\n# Download the metadata from a local node and replace the current metadata\n# See `https://github.com/paritytech/subxt/tree/master/cli` for further documentation of the `subxt-cli` tool.\n$ subxt metadata --pallets \"ElectionProviderMultiPhase,System\" -f bytes \u003e artifacts/metadata.scale\n# Inspect the generated code\n$ subxt codegen --file artifacts/metadata.scale | rustfmt \u003e code.rs\n```\n\n## Test locally\n\nBecause elections occurs quite rarely and if you want to test it locally\nit's possible build the polkadot binary with `feature --fast-runtime`\nto ensure that elections occurs more often (in order of minutes rather hours/days).\n\n```bash\n$ cargo run --release --package polkadot --features fast-runtime -- --chain westend-dev --tmp --alice --execution Native -lruntime=debug --offchain-worker=Never --ws-port 9999\n# open another terminal and run\n$ cargo run --release -- --uri ws://localhost:9999 monitor --seed-or-path //Alice seq-phragmen\n```\n\n## Prometheus metrics\n\nThe staking-miner starts a prometheus server on port 9999 and that metrics can\nbe fetched by:\n\n```bash\n$ curl localhost:9999/metrics\n```\n\n\n```bash\n# HELP staking_miner_balance The balance of the staking miner account\n# TYPE staking_miner_balance gauge\nstaking_miner_balance 88756574897390270\n# HELP staking_miner_mining_duration_ms The mined solution time in milliseconds.\n# TYPE staking_miner_mining_duration_ms gauge\nstaking_miner_mining_duration_ms 50\n# HELP staking_miner_score_minimal_stake The minimal winner, in terms of total backing stake\n# TYPE staking_miner_score_minimal_stake gauge\nstaking_miner_score_minimal_stake 24426059484170936\n# HELP staking_miner_score_sum_stake The sum of the total backing of all winners\n# TYPE staking_miner_score_sum_stake gauge\nstaking_miner_score_sum_stake 2891461667266507300\n# HELP staking_miner_score_sum_stake_squared The sum squared of the total backing of all winners, aka. the variance.\n# TYPE staking_miner_score_sum_stake_squared gauge\nstaking_miner_score_sum_stake_squared 83801161022319280000000000000000000\n# HELP staking_miner_solution_length_bytes Number of bytes in the solution submitted\n# TYPE staking_miner_solution_length_bytes gauge\nstaking_miner_solution_length_bytes 2947\n# HELP staking_miner_solution_weight Weight of the solution submitted\n# TYPE staking_miner_solution_weight gauge\nstaking_miner_solution_weight 8285574626\n# HELP staking_miner_submissions_started Number of submissions started\n# TYPE staking_miner_submissions_started counter\nstaking_miner_submissions_started 2\n# HELP staking_miner_submissions_success Number of submissions finished successfully\n# TYPE staking_miner_submissions_success counter\nstaking_miner_submissions_success 2\n# HELP staking_miner_submit_and_watch_duration_ms The time in milliseconds it took to submit the solution to chain and to be included in block\n# TYPE staking_miner_submit_and_watch_duration_ms gauge\nstaking_miner_submit_and_watch_duration_ms 17283\n```\n\n## Related projects\n\n- [substrate-etl](https://github.com/gpestana/substrate-etl) - a tool fetch state from substrate-based chains.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparitytech%2Fpolkadot-staking-miner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fparitytech%2Fpolkadot-staking-miner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparitytech%2Fpolkadot-staking-miner/lists"}