mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-20 16:15:41 +00:00
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
This commit is contained in:
@@ -11,3 +11,4 @@ polkadot.*
|
|||||||
!.rpm/*
|
!.rpm/*
|
||||||
.DS_Store
|
.DS_Store
|
||||||
.cargo
|
.cargo
|
||||||
|
.env
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ async fn print_info<T: EPM::Config>(
|
|||||||
|
|
||||||
let snapshot_size =
|
let snapshot_size =
|
||||||
<EPM::Pallet<T>>::snapshot_metadata().expect("snapshot must exist by now; qed.");
|
<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!(
|
log::info!(
|
||||||
target: LOG_TARGET,
|
target: LOG_TARGET,
|
||||||
"solution score {:?} / deposit {:?} / length {:?}",
|
"solution score {:?} / deposit {:?} / length {:?}",
|
||||||
@@ -80,7 +80,9 @@ async fn print_info<T: EPM::Config>(
|
|||||||
log::info!(
|
log::info!(
|
||||||
target: LOG_TARGET,
|
target: LOG_TARGET,
|
||||||
"payment_queryInfo: (fee = {}) {:?}",
|
"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,
|
info,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -276,15 +276,15 @@ struct DryRunConfig {
|
|||||||
#[derive(Debug, Clone, StructOpt)]
|
#[derive(Debug, Clone, StructOpt)]
|
||||||
struct SharedConfig {
|
struct SharedConfig {
|
||||||
/// The `ws` node to connect to.
|
/// The `ws` node to connect to.
|
||||||
#[structopt(long, short, default_value = DEFAULT_URI)]
|
#[structopt(long, short, default_value = DEFAULT_URI, env = "URI")]
|
||||||
uri: String,
|
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
|
/// 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.
|
/// configured, it might re-try and lose funds through transaction fees/deposits.
|
||||||
#[structopt(long, short)]
|
#[structopt(long, short, env = "SEED")]
|
||||||
account_seed: std::path::PathBuf,
|
seed: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, StructOpt)]
|
#[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 desired_targets = EPM::DesiredTargets::<T>::get().unwrap();
|
||||||
let mut candidates_and_backing = BTreeMap::<T::AccountId, u128>::new();
|
let mut candidates_and_backing = BTreeMap::<T::AccountId, u128>::new();
|
||||||
voters.into_iter().for_each(|(who, stake, targets)| {
|
voters.into_iter().for_each(|(who, stake, targets)| {
|
||||||
if targets.len() == 0 {
|
if targets.is_empty() {
|
||||||
println!("target = {:?}", (who, stake, targets));
|
println!("target = {:?}", (who, stake, targets));
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -491,7 +491,7 @@ async fn main() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let signer_account = any_runtime! {
|
let signer_account = any_runtime! {
|
||||||
signer::read_signer_uri::<_, Runtime>(&shared.account_seed, &client)
|
signer::signer_uri_from_string::<Runtime>(&shared.seed, &client)
|
||||||
.await
|
.await
|
||||||
.expect("Provided account is invalid, terminating.")
|
.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};
|
pub use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
|
||||||
|
|
||||||
/// Default URI to connect to.
|
/// 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.
|
/// The logging target.
|
||||||
pub const LOG_TARGET: &'static str = "staking-miner";
|
pub const LOG_TARGET: &str = "staking-miner";
|
||||||
|
|
||||||
/// The election provider pallet.
|
/// The election provider pallet.
|
||||||
pub use pallet_election_provider_multi_phase as EPM;
|
pub use pallet_election_provider_multi_phase as EPM;
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ where
|
|||||||
Hash: serde::Serialize,
|
Hash: serde::Serialize,
|
||||||
{
|
{
|
||||||
let key = <V as StorageValue<T>>::hashed_key();
|
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)]
|
#[allow(unused)]
|
||||||
@@ -103,5 +103,5 @@ where
|
|||||||
Hash: serde::Serialize,
|
Hash: serde::Serialize,
|
||||||
{
|
{
|
||||||
let key = <M as StorageMap<K, T>>::hashed_key_for(key);
|
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 crate::{prelude::*, rpc_helpers, AccountId, Error, Index, Pair, WsClient, LOG_TARGET};
|
||||||
use sp_core::crypto::Pair as _;
|
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 \
|
"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 \
|
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.";
|
signer got slashed. Terminating.";
|
||||||
@@ -30,10 +29,9 @@ pub(crate) const SIGNER_ACCOUNT_WILL_EXIST: &'static str =
|
|||||||
pub(crate) struct Signer {
|
pub(crate) struct Signer {
|
||||||
/// The account id.
|
/// The account id.
|
||||||
pub(crate) account: AccountId,
|
pub(crate) account: AccountId,
|
||||||
|
|
||||||
/// The full crypto key-pair.
|
/// The full crypto key-pair.
|
||||||
pub(crate) pair: 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>(
|
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
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Read the signer account's URI from the given `path`.
|
/// Read the signer account's URI
|
||||||
pub(crate) async fn read_signer_uri<
|
pub(crate) async fn signer_uri_from_string<
|
||||||
P: AsRef<Path>,
|
|
||||||
T: frame_system::Config<
|
T: frame_system::Config<
|
||||||
AccountId = AccountId,
|
AccountId = AccountId,
|
||||||
Index = Index,
|
Index = Index,
|
||||||
AccountData = pallet_balances::AccountData<Balance>,
|
AccountData = pallet_balances::AccountData<Balance>,
|
||||||
>,
|
>,
|
||||||
>(
|
>(
|
||||||
path: P,
|
seed: &str,
|
||||||
client: &WsClient,
|
client: &WsClient,
|
||||||
) -> Result<Signer, Error> {
|
) -> Result<Signer, Error> {
|
||||||
let uri = std::fs::read_to_string(path)?;
|
let seed = seed.trim();
|
||||||
|
|
||||||
// trim any trailing garbage.
|
let pair = Pair::from_string(seed, None)?;
|
||||||
let uri = uri.trim_end();
|
|
||||||
|
|
||||||
let pair = Pair::from_string(&uri, None)?;
|
|
||||||
let account = T::AccountId::from(pair.public());
|
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?
|
.await?
|
||||||
.ok_or(Error::AccountDoesNotExists)?;
|
.ok_or(Error::AccountDoesNotExists)?;
|
||||||
log::info!(
|
log::info!(
|
||||||
@@ -80,5 +74,5 @@ pub(crate) async fn read_signer_uri<
|
|||||||
Token::from(_info.data.free),
|
Token::from(_info.data.free),
|
||||||
_info
|
_info
|
||||||
);
|
);
|
||||||
Ok(Signer { account, pair, uri: uri.to_string() })
|
Ok(Signer { account, pair })
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user