This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Staking Miner #3141
Merged
Merged
Staking Miner #3141
Changes from 21 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
36502dc
Companion for Decouple Staking and Election - Part 3: Signed Phase
coriolinus 1e509e9
Merge remote-tracking branch 'origin/master' into prgn-companion-for-…
coriolinus 9638fcf
Merge remote-tracking branch 'origin/master' into prgn-companion-for-…
coriolinus 59646c2
Merge branch 'prgn-companion-for-7910' of github.com:paritytech/polka…
kianenigma 271d351
Template added
kianenigma 7e21f24
Add stuff
kianenigma 61cf070
First working version
kianenigma 95b6ea0
revamp rpc stuff
kianenigma 1709494
remove all the stale js stuff
kianenigma 0c10c66
Major updates, closer to completion.
kianenigma a4aa730
removing my generic WIP for tidyness.
kianenigma 72db361
add --at
kianenigma dc1a623
ass measure snapshot
kianenigma 5fa5a3f
some new little debugging thigs
kianenigma 138e8b9
pre-merge
kianenigma c3cfe94
Merge branch 'master' of github.com:paritytech/polkadot into kiz-stak…
kianenigma 863ea3a
Master.into()
kianenigma 3980e85
Fix
kianenigma d1ba0cb
revert dep update
kianenigma fe76cee
update to master
kianenigma 3777a8a
revert all the toml shit
kianenigma 64c22d9
Apply suggestions from code review
kianenigma bcd394d
cleanup
kianenigma e74218e
Fix more
kianenigma 3ce287f
Fix era
kianenigma 7dd7e64
Apply suggestions from code review
kianenigma ab87195
Few fixes
kianenigma c77bf51
Better reward scheme
kianenigma b25ee40
y
kianenigma 10508ae
Update utils/staking-miner/src/main.rs
kianenigma f83ddb6
Update utils/staking-miner/src/dry_run.rs
kianenigma 913e75a
Update utils/staking-miner/src/dry_run.rs
kianenigma 89e0a38
Update utils/staking-miner/src/monitor.rs
kianenigma dcbe582
More chnages
kianenigma f10f00b
Merge branch 'kiz-staking-miner' of github.com:paritytech/polkadot in…
kianenigma df8725b
Fix
kianenigma 1e4f6be
Master.into()
kianenigma 01e92c4
Make it restart automatically.
kianenigma 979cfcc
Final touches
kianenigma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| *.key |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| [package] | ||
| name = "staking-miner" | ||
| version = "0.9.0" | ||
| authors = ["Parity Technologies <admin@parity.io>"] | ||
| edition = "2018" | ||
|
|
||
| [dependencies] | ||
| codec = { package = "parity-scale-codec", version = "2.0.0" } | ||
| tokio = { version = "0.2", features = ["macros"] } | ||
| log = "0.4.11" | ||
| env_logger = "0.8.3" | ||
| structopt = "0.3.0" | ||
| jsonrpsee-ws-client = { version = "0.2.0", default-features = false, features = ["tokio02"] } | ||
| jsonrpsee-types = { version = "0.2.0" } | ||
| jsonrpsee = "=0.2.0-alpha.6" | ||
| serde_json = "1.0" | ||
| serde = "1.0.0" | ||
| hex = "0.4.0" | ||
| lazy_static = "1.4.0" | ||
| paste = "1.0.5" | ||
| thiserror = "1.0.0" | ||
|
|
||
| remote-externalities = { git = "https://github.com/paritytech/substrate", branch = "master" } | ||
|
|
||
| sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" } | ||
| sp-io = { git = "https://github.com/paritytech/substrate", branch = "master" } | ||
| sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" } | ||
| sp-npos-elections = { git = "https://github.com/paritytech/substrate", branch = "master" } | ||
| sp-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "master" } | ||
|
|
||
|
|
||
| frame-system = { git = "https://github.com/paritytech/substrate", branch = "master" } | ||
| frame-support = { git = "https://github.com/paritytech/substrate", branch = "master" } | ||
| frame-election-provider-support = { git = "https://github.com/paritytech/substrate", branch = "master" } | ||
| pallet-election-provider-multi-phase = { git = "https://github.com/paritytech/substrate", branch = "master" } | ||
| pallet-staking = { git = "https://github.com/paritytech/substrate", branch = "master" } | ||
| pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", branch = "master" } | ||
|
|
||
| core-primitives = { package = "polkadot-core-primitives", path = "../../core-primitives" } | ||
|
|
||
| runtime-common = { package = "polkadot-runtime-common", path = "../../runtime/common" } | ||
| polkadot-runtime = { path = "../../runtime/polkadot" } | ||
| kusama-runtime = { path = "../../runtime/kusama" } | ||
| westend-runtime = { path = "../../runtime/westend" } | ||
|
|
||
| [dev-dependencies] | ||
| sp-version = { git = "https://github.com/paritytech/substrate", branch = "master" } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| bottom drive obey lake curtain smoke basket hold race lonely fit walk//Alice | ||
kianenigma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| // Copyright 2021 Parity Technologies (UK) Ltd. | ||
| // This file is part of Polkadot. | ||
|
|
||
| // Polkadot is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
|
|
||
| // Polkadot is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
|
|
||
| // You should have received a copy of the GNU General Public License | ||
| // along with Polkadot. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| //! The dry-run command. | ||
|
|
||
| use crate::{prelude::*, Signer, SharedConfig, DryRunConfig, WsClient, Error, rpc_helpers::*, params}; | ||
| use codec::Encode; | ||
|
|
||
| /// Forcefully create the snapshot. This can be used to compute the election at anytime. | ||
| fn force_create_snapshot<T: EPM::Config>(ext: &mut Ext) -> Result<(), Error> { | ||
| ext.execute_with(|| { | ||
| if <EPM::Snapshot<T>>::exists() { | ||
| log::info!(target: LOG_TARGET, "snapshot already exists."); | ||
| Ok(()) | ||
| } else { | ||
| log::info!(target: LOG_TARGET, "creating a fake snapshot now."); | ||
| <EPM::Pallet<T>>::create_snapshot().map(|_| ()).map_err(Into::into) | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| fn measure_snapshot_size<T: EPM::Config>(ext: &mut Ext) { | ||
| ext.execute_with(|| { | ||
| log::info!(target: LOG_TARGET, "Metadata: {:?}", <EPM::Pallet<T>>::snapshot_metadata()); | ||
| log::info!( | ||
| target: LOG_TARGET, | ||
| "Encoded Length: {:?}", | ||
| <EPM::Pallet<T>>::snapshot() | ||
| .expect("snapshot must exist before calling `measure_snapshot_size`") | ||
| .encode() | ||
| .len() | ||
| ); | ||
| }) | ||
| } | ||
|
|
||
| fn find_threshold<T: EPM::Config>(ext: &mut Ext, count: usize) { | ||
| ext.execute_with(|| { | ||
| let mut voters = <EPM::Pallet<T>>::snapshot() | ||
| .expect("snapshot must exist before calling `measure_snapshot_size`") | ||
| .voters; | ||
| voters.sort_by_key(|v| v.1); | ||
kianenigma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| dbg!(voters.into_iter().rev().take(count).last()); | ||
| }) | ||
| } | ||
|
|
||
| macro_rules! dry_run_cmd_for { ($runtime:ident) => { paste::paste! { | ||
| /// Execute the dry-run command. | ||
| pub(crate) async fn [<dry_run_cmd_ $runtime>]( | ||
kianenigma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| client: WsClient, | ||
| shared: SharedConfig, | ||
| config: DryRunConfig, | ||
| signer: Signer, | ||
| ) -> Result<(), Error> { | ||
| use $crate::[<$runtime _runtime_exports>]::*; | ||
| let mut ext = crate::create_election_ext::<Runtime, Block>(shared.uri.clone(), config.at, true).await?; | ||
| force_create_snapshot::<Runtime>(&mut ext)?; | ||
| measure_snapshot_size::<Runtime>(&mut ext); | ||
| find_threshold::<Runtime>(&mut ext, 20_000); | ||
kianenigma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| let (raw_solution, witness) = crate::mine_unchecked::<Runtime>(&mut ext, 100)?; | ||
| log::info!(target: LOG_TARGET, "mined solution with {:?}", &raw_solution.score); | ||
|
|
||
| let nonce = crate::get_account_info::<Runtime>(&client, &signer.account, config.at) | ||
| .await? | ||
| .map(|i| i.nonce) | ||
| .expect("signer account is checked to exist upon startup; it can only die if it \ | ||
| transfers funds out of it, or get slashed. If it does not exist at this point, \ | ||
| it is likely due to a bug, or the signer got slashed. Terminating." | ||
| ); | ||
| let tip = 0 as Balance; | ||
| let era = sp_runtime::generic::Era::Immortal; | ||
| let extrinsic = ext.execute_with(|| create_uxt(raw_solution, witness, signer.clone(), nonce, tip, era)); | ||
|
|
||
| let bytes = sp_core::Bytes(extrinsic.encode().to_vec()); | ||
| let outcome = rpc_decode::<sp_runtime::ApplyExtrinsicResult>(&client, "system_dryRun", params!{ bytes }).await?; | ||
| log::info!(target: LOG_TARGET, "dry-run outcome is {:?}", outcome); | ||
| Ok(()) | ||
| } | ||
| }}} | ||
|
|
||
| dry_run_cmd_for!(polkadot); | ||
| dry_run_cmd_for!(kusama); | ||
| dry_run_cmd_for!(westend); | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| // Copyright 2021 Parity Technologies (UK) Ltd. | ||
| // This file is part of Polkadot. | ||
|
|
||
| // Polkadot is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
|
|
||
| // Polkadot is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
|
|
||
| // You should have received a copy of the GNU General Public License | ||
| // along with Polkadot. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| //! The emergency-solution command. | ||
|
|
||
| use crate::{prelude::*, SharedConfig, WsClient, Error}; | ||
| use std::io::Write; | ||
| use codec::Encode; | ||
|
|
||
| macro_rules! emergency_solution_cmd_for { ($runtime:ident) => { paste::paste! { | ||
| /// Execute the emergency-solution command. | ||
| pub(crate) async fn [<emergency_solution_cmd_ $runtime>]( | ||
| _client: WsClient, | ||
| shared: SharedConfig, | ||
| ) -> Result<(), Error> { | ||
| use $crate::[<$runtime _runtime_exports>]::*; | ||
| let mut ext = crate::create_election_ext::<Runtime, Block>(shared.uri.clone(), None, false).await?; | ||
| ext.execute_with(|| { | ||
| assert!(EPM::Pallet::<Runtime>::current_phase().is_emergency()); | ||
| // NOTE: this internally calls feasibility_check, but we just re-do it here as an easy way | ||
| // to get a `ReadySolution`. | ||
| let (raw_solution, _) = <EPM::Pallet<Runtime>>::mine_solution(50)?; | ||
| log::info!(target: LOG_TARGET, "mined solution with {:?}", &raw_solution.score); | ||
| let ready_solution = EPM::Pallet::<Runtime>::feasibility_check(raw_solution, EPM::ElectionCompute::Signed)?; | ||
| let encoded_ready = ready_solution.encode(); | ||
| let encoded_support = ready_solution.supports.encode(); | ||
| let mut solution_file = std::fs::File::create("solution.bin")?; | ||
| let mut supports_file = std::fs::File::create("solution.supports.bin")?; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i assume this works with no |
||
| solution_file.write_all(&encoded_ready)?; | ||
| supports_file.write_all(&encoded_support)?; | ||
| log::info!(target: LOG_TARGET, "ReadySolution: size {:?} / score = {:?}", encoded_ready.len(), ready_solution.score); | ||
| log::trace!(target: LOG_TARGET, "Supports: {}", sp_core::hexdisplay::HexDisplay::from(&encoded_support)); | ||
| Ok(()) | ||
| }) | ||
| } | ||
| }}} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nothing to change for now, but in the future would nice to have cli options for
|
||
|
|
||
| emergency_solution_cmd_for!(polkadot); | ||
| emergency_solution_cmd_for!(kusama); | ||
| emergency_solution_cmd_for!(westend); | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.