Unverified Commit 948e0f1e authored by Chevdor's avatar Chevdor Committed by GitHub
Browse files

staking-miner: remove need of a file to pass the seed (#3680)

* staking-miner: remove need of a file to pass the seed

* cleanup

* linting round

* fix linting

* fix naming and remove unused field
parent ccfd5b91
Pipeline #154445 passed with stages
in 38 minutes and 41 seconds
......@@ -11,3 +11,4 @@ polkadot.*
!.rpm/*
.DS_Store
.cargo
.env
......@@ -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,
);
}
......
......@@ -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.")
};
......
......@@ -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;
......
......@@ -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
}
......@@ -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 })
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment