diff --git a/polkadot/.gitignore b/polkadot/.gitignore index a654e51fd7c81507c3c9e9926af55452150b3a31..5ea0458ddfc8dee40a7707ef95d27684009ee4d6 100644 --- a/polkadot/.gitignore +++ b/polkadot/.gitignore @@ -11,3 +11,4 @@ polkadot.* !.rpm/* .DS_Store .cargo +.env diff --git a/polkadot/utils/staking-miner/src/dry_run.rs b/polkadot/utils/staking-miner/src/dry_run.rs index 79190793f9e9a576f6be5e7b52c5c3f5083d7c8d..236d63ce4cc16b363468db3bdcf3d4b9e0a1e14c 100644 --- a/polkadot/utils/staking-miner/src/dry_run.rs +++ b/polkadot/utils/staking-miner/src/dry_run.rs @@ -61,7 +61,7 @@ async fn print_info<T: EPM::Config>( let snapshot_size = <EPM::Pallet<T>>::snapshot_metadata().expect("snapshot must exist by now; qed."); - let deposit = EPM::Pallet::<T>::deposit_for(&raw_solution, snapshot_size); + let deposit = EPM::Pallet::<T>::deposit_for(raw_solution, snapshot_size); log::info!( target: LOG_TARGET, "solution score {:?} / deposit {:?} / length {:?}", @@ -80,7 +80,9 @@ async fn print_info<T: EPM::Config>( log::info!( target: LOG_TARGET, "payment_queryInfo: (fee = {}) {:?}", - info.as_ref().map(|d| Token::from(d.partial_fee)).unwrap_or(Token::from(0)), + info.as_ref() + .map(|d| Token::from(d.partial_fee)) + .unwrap_or_else(|_| Token::from(0)), info, ); } diff --git a/polkadot/utils/staking-miner/src/main.rs b/polkadot/utils/staking-miner/src/main.rs index 2aabe722150df2b1ac4ab18e9dc6f18dd35ed7a9..1769382e62af1260ab0902fbd24c2c4a6d563692 100644 --- a/polkadot/utils/staking-miner/src/main.rs +++ b/polkadot/utils/staking-miner/src/main.rs @@ -276,15 +276,15 @@ struct DryRunConfig { #[derive(Debug, Clone, StructOpt)] struct SharedConfig { /// The `ws` node to connect to. - #[structopt(long, short, default_value = DEFAULT_URI)] + #[structopt(long, short, default_value = DEFAULT_URI, env = "URI")] uri: String, - /// The file from which we read the account seed. + /// The seed of a funded account in hex. /// - /// WARNING: don't use an account with a large stash for this. Based on how the bot is - /// configured, it might re-try lose funds through transaction fees/deposits. - #[structopt(long, short)] - account_seed: std::path::PathBuf, + /// WARNING: Don't use an account with a large stash for this. Based on how the bot is + /// configured, it might re-try and lose funds through transaction fees/deposits. + #[structopt(long, short, env = "SEED")] + seed: String, } #[derive(Debug, Clone, StructOpt)] @@ -354,7 +354,7 @@ fn mine_dpos<T: EPM::Config>(ext: &mut Ext) -> Result<(), Error> { let desired_targets = EPM::DesiredTargets::<T>::get().unwrap(); let mut candidates_and_backing = BTreeMap::<T::AccountId, u128>::new(); voters.into_iter().for_each(|(who, stake, targets)| { - if targets.len() == 0 { + if targets.is_empty() { println!("target = {:?}", (who, stake, targets)); return } @@ -491,7 +491,7 @@ async fn main() { }; let signer_account = any_runtime! { - signer::read_signer_uri::<_, Runtime>(&shared.account_seed, &client) + signer::signer_uri_from_string::<Runtime>(&shared.seed, &client) .await .expect("Provided account is invalid, terminating.") }; diff --git a/polkadot/utils/staking-miner/src/prelude.rs b/polkadot/utils/staking-miner/src/prelude.rs index e3c25887af2dbe38489856d4a5aeb1af892ec648..db9ce4e2c1e29f2bf170f0bc7aa80d345e27c1e5 100644 --- a/polkadot/utils/staking-miner/src/prelude.rs +++ b/polkadot/utils/staking-miner/src/prelude.rs @@ -34,9 +34,9 @@ pub type Hash = core_primitives::Hash; pub use sp_runtime::traits::{Block as BlockT, Header as HeaderT}; /// Default URI to connect to. -pub const DEFAULT_URI: &'static str = "wss://rpc.polkadot.io"; +pub const DEFAULT_URI: &str = "wss://rpc.polkadot.io"; /// The logging target. -pub const LOG_TARGET: &'static str = "staking-miner"; +pub const LOG_TARGET: &str = "staking-miner"; /// The election provider pallet. pub use pallet_election_provider_multi_phase as EPM; diff --git a/polkadot/utils/staking-miner/src/rpc_helpers.rs b/polkadot/utils/staking-miner/src/rpc_helpers.rs index e759917adee661dd7df671a72f7a3cb4bb0aa7bc..cc086b1235b13519cf06801a63b1206c372cda3c 100644 --- a/polkadot/utils/staking-miner/src/rpc_helpers.rs +++ b/polkadot/utils/staking-miner/src/rpc_helpers.rs @@ -82,7 +82,7 @@ where Hash: serde::Serialize, { let key = <V as StorageValue<T>>::hashed_key(); - get_storage::<V::Query>(&client, params! { key, maybe_at }).await + get_storage::<V::Query>(client, params! { key, maybe_at }).await } #[allow(unused)] @@ -103,5 +103,5 @@ where Hash: serde::Serialize, { let key = <M as StorageMap<K, T>>::hashed_key_for(key); - get_storage::<M::Query>(&client, params! { key, maybe_at }).await + get_storage::<M::Query>(client, params! { key, maybe_at }).await } diff --git a/polkadot/utils/staking-miner/src/signer.rs b/polkadot/utils/staking-miner/src/signer.rs index 9ced41a93e7266ec6e00cf6d92ab8d5893b20289..8dd2696b3309577f904a9b7c4262bcab2cee9b84 100644 --- a/polkadot/utils/staking-miner/src/signer.rs +++ b/polkadot/utils/staking-miner/src/signer.rs @@ -18,9 +18,8 @@ use crate::{prelude::*, rpc_helpers, AccountId, Error, Index, Pair, WsClient, LOG_TARGET}; use sp_core::crypto::Pair as _; -use std::path::Path; -pub(crate) const SIGNER_ACCOUNT_WILL_EXIST: &'static str = +pub(crate) const SIGNER_ACCOUNT_WILL_EXIST: &str = "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."; @@ -30,10 +29,9 @@ pub(crate) const SIGNER_ACCOUNT_WILL_EXIST: &'static str = pub(crate) struct Signer { /// The account id. pub(crate) account: AccountId, + /// The full crypto key-pair. pub(crate) pair: Pair, - /// The raw URI read from file. - pub(crate) uri: String, } pub(crate) async fn get_account_info<T: frame_system::Config>( @@ -51,26 +49,22 @@ pub(crate) async fn get_account_info<T: frame_system::Config>( .await } -/// Read the signer account's URI from the given `path`. -pub(crate) async fn read_signer_uri< - P: AsRef<Path>, +/// Read the signer account's URI +pub(crate) async fn signer_uri_from_string< T: frame_system::Config< AccountId = AccountId, Index = Index, AccountData = pallet_balances::AccountData<Balance>, >, >( - path: P, + seed: &str, client: &WsClient, ) -> Result<Signer, Error> { - let uri = std::fs::read_to_string(path)?; - - // trim any trailing garbage. - let uri = uri.trim_end(); + let seed = seed.trim(); - let pair = Pair::from_string(&uri, None)?; + let pair = Pair::from_string(seed, None)?; let account = T::AccountId::from(pair.public()); - let _info = get_account_info::<T>(&client, &account, None) + let _info = get_account_info::<T>(client, &account, None) .await? .ok_or(Error::AccountDoesNotExists)?; log::info!( @@ -80,5 +74,5 @@ pub(crate) async fn read_signer_uri< Token::from(_info.data.free), _info ); - Ok(Signer { account, pair, uri: uri.to_string() }) + Ok(Signer { account, pair }) }