Unverified Commit 677d4b10 authored by Kian Paimani's avatar Kian Paimani Committed by GitHub
Browse files
parent a620156c
Pipeline #145178 passed with stages
in 32 minutes and 28 seconds
...@@ -3181,6 +3181,12 @@ dependencies = [ ...@@ -3181,6 +3181,12 @@ dependencies = [
"slab", "slab",
] ]
[[package]]
name = "jsonrpsee"
version = "0.2.0-alpha.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4e48ecdd757b22fae87e87aad2dbadf11c56499c6509763c8ef20db16ffb0e9"
[[package]] [[package]]
name = "jsonrpsee-proc-macros" name = "jsonrpsee-proc-macros"
version = "0.2.0" version = "0.2.0"
...@@ -9984,6 +9990,44 @@ version = "1.1.1" ...@@ -9984,6 +9990,44 @@ version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" checksum = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8"
[[package]]
name = "staking-miner"
version = "0.9.0"
dependencies = [
"env_logger 0.8.4",
"frame-election-provider-support",
"frame-support",
"frame-system",
"hex",
"jsonrpsee",
"jsonrpsee-types",
"jsonrpsee-ws-client",
"kusama-runtime",
"lazy_static",
"log",
"pallet-election-provider-multi-phase",
"pallet-staking",
"pallet-transaction-payment",
"parity-scale-codec",
"paste 1.0.5",
"polkadot-core-primitives",
"polkadot-runtime",
"polkadot-runtime-common",
"remote-externalities",
"serde",
"serde_json",
"sp-core",
"sp-io",
"sp-npos-elections",
"sp-runtime",
"sp-transaction-pool",
"sp-version",
"structopt",
"thiserror",
"tokio 0.2.21",
"westend-runtime",
]
[[package]] [[package]]
name = "static_assertions" name = "static_assertions"
version = "1.1.0" version = "1.1.0"
......
...@@ -79,6 +79,7 @@ members = [ ...@@ -79,6 +79,7 @@ members = [
"parachain/test-parachains", "parachain/test-parachains",
"parachain/test-parachains/adder", "parachain/test-parachains/adder",
"parachain/test-parachains/adder/collator", "parachain/test-parachains/adder/collator",
"utils/staking-miner",
] ]
# We want to be able to build the bridge relayer without pulling it (and all of its # We want to be able to build the bridge relayer without pulling it (and all of its
......
...@@ -1213,7 +1213,7 @@ pub fn polkadot_testnet_genesis( ...@@ -1213,7 +1213,7 @@ pub fn polkadot_testnet_genesis(
}, },
staking: polkadot::StakingConfig { staking: polkadot::StakingConfig {
minimum_validator_count: 1, minimum_validator_count: 1,
validator_count: 2, validator_count: initial_authorities.len() as u32,
stakers: initial_authorities stakers: initial_authorities
.iter() .iter()
.map(|x| { .map(|x| {
...@@ -1312,7 +1312,7 @@ pub fn kusama_testnet_genesis( ...@@ -1312,7 +1312,7 @@ pub fn kusama_testnet_genesis(
}, },
staking: kusama::StakingConfig { staking: kusama::StakingConfig {
minimum_validator_count: 1, minimum_validator_count: 1,
validator_count: 2, validator_count: initial_authorities.len() as u32,
stakers: initial_authorities stakers: initial_authorities
.iter() .iter()
.map(|x| { .map(|x| {
...@@ -1416,7 +1416,7 @@ pub fn westend_testnet_genesis( ...@@ -1416,7 +1416,7 @@ pub fn westend_testnet_genesis(
}, },
staking: westend::StakingConfig { staking: westend::StakingConfig {
minimum_validator_count: 1, minimum_validator_count: 1,
validator_count: 2, validator_count: initial_authorities.len() as u32,
stakers: initial_authorities stakers: initial_authorities
.iter() .iter()
.map(|x| { .map(|x| {
......
...@@ -18,10 +18,14 @@ ...@@ -18,10 +18,14 @@
use frame_support::{ use frame_support::{
parameter_types, parameter_types,
traits::Get, weights::{DispatchClass, Weight},
weights::{DispatchClass, Weight, WeightToFeePolynomial},
}; };
use sp_runtime::Perbill; use sp_runtime::{
traits::{Zero, Dispatchable},
FixedU128, FixedPointNumber, Perbill,
};
use pallet_transaction_payment::OnChargeTransaction;
use frame_support::weights::{DispatchInfo, Pays};
use super::{BlockExecutionWeight, BlockLength, BlockWeights}; use super::{BlockExecutionWeight, BlockLength, BlockWeights};
parameter_types! { parameter_types! {
...@@ -44,18 +48,21 @@ parameter_types! { ...@@ -44,18 +48,21 @@ parameter_types! {
.get(DispatchClass::Normal); .get(DispatchClass::Normal);
} }
/// Compute the expected fee for submitting an election solution. pub fn fee_for_submit_call<T>(
/// multiplier: FixedU128,
/// This is `multiplier` multiplied by the fee for the expected submission weight according to the weight: Weight,
/// weight info. length: u32,
/// ) -> primitives::v1::Balance
/// Assumes that the signed submission queue is full.
pub fn fee_for_submit_call<T, WeightToFee, WeightInfo>(multiplier: Perbill) -> WeightToFee::Balance
where where
T: pallet_election_provider_multi_phase::Config, T: pallet_transaction_payment::Config,
WeightToFee: WeightToFeePolynomial, <T as pallet_transaction_payment::Config>::OnChargeTransaction:
WeightInfo: pallet_election_provider_multi_phase::WeightInfo, OnChargeTransaction<T, Balance = primitives::v1::Balance>,
<T as frame_system::Config>::Call: Dispatchable<Info = DispatchInfo>,
{ {
let expected_weight = WeightInfo::submit(T::SignedMaxSubmissions::get()); let info = DispatchInfo { weight, class: DispatchClass::Normal, pays_fee: Pays::Yes };
multiplier * WeightToFee::calc(&expected_weight) multiplier.saturating_mul_int(pallet_transaction_payment::Pallet::<T>::compute_fee(
length,
&info,
Zero::zero(),
))
} }
...@@ -65,8 +65,8 @@ use xcm_builder::{ ...@@ -65,8 +65,8 @@ use xcm_builder::{
use xcm_executor::XcmExecutor; use xcm_executor::XcmExecutor;
use sp_arithmetic::Perquintill; use sp_arithmetic::Perquintill;
use sp_runtime::{ use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys, create_runtime_str, generic, impl_opaque_keys, ApplyExtrinsicResult, KeyTypeId, Percent,
ApplyExtrinsicResult, KeyTypeId, Percent, Permill, Perbill, Permill, Perbill, FixedPointNumber,
transaction_validity::{TransactionValidity, TransactionSource, TransactionPriority}, transaction_validity::{TransactionValidity, TransactionSource, TransactionPriority},
traits::{ traits::{
BlakeTwo256, Block as BlockT, OpaqueKeys, ConvertInto, AccountIdLookup, BlakeTwo256, Block as BlockT, OpaqueKeys, ConvertInto, AccountIdLookup,
...@@ -101,6 +101,7 @@ pub use pallet_staking::StakerStatus; ...@@ -101,6 +101,7 @@ pub use pallet_staking::StakerStatus;
pub use sp_runtime::BuildStorage; pub use sp_runtime::BuildStorage;
pub use pallet_timestamp::Call as TimestampCall; pub use pallet_timestamp::Call as TimestampCall;
pub use pallet_balances::Call as BalancesCall; pub use pallet_balances::Call as BalancesCall;
pub use pallet_election_provider_multi_phase::Call as EPMCall;
/// Constant values used within the runtime. /// Constant values used within the runtime.
pub mod constants; pub mod constants;
...@@ -348,6 +349,7 @@ impl pallet_session::historical::Config for Runtime { ...@@ -348,6 +349,7 @@ impl pallet_session::historical::Config for Runtime {
type FullIdentificationOf = pallet_staking::ExposureOf<Runtime>; type FullIdentificationOf = pallet_staking::ExposureOf<Runtime>;
} }
use pallet_election_provider_multi_phase::WeightInfo;
parameter_types! { parameter_types! {
// phase durations. 1/4 of the last session for each. // phase durations. 1/4 of the last session for each.
pub const SignedPhase: u32 = EPOCH_DURATION_IN_SLOTS / 4; pub const SignedPhase: u32 = EPOCH_DURATION_IN_SLOTS / 4;
...@@ -360,11 +362,14 @@ parameter_types! { ...@@ -360,11 +362,14 @@ parameter_types! {
// This formula is currently adjusted such that a typical solution will spend an amount equal // This formula is currently adjusted such that a typical solution will spend an amount equal
// to the base deposit for every 50 kb. // to the base deposit for every 50 kb.
pub const SignedDepositByte: Balance = deposit(1, 0) / (50 * 1024); pub const SignedDepositByte: Balance = deposit(1, 0) / (50 * 1024);
pub SignedRewardBase: Balance = fee_for_submit_call::< pub SignedRewardBase: Balance = fee_for_submit_call::<Runtime>(
Runtime, // give 20% threshold.
crate::constants::fee::WeightToFee, sp_runtime::FixedU128::saturating_from_rational(12, 10),
crate::weights::pallet_election_provider_multi_phase::WeightInfo<Runtime>, // maximum weight possible.
>(Perbill::from_perthousand(1500)); weights::pallet_election_provider_multi_phase::WeightInfo::<Runtime>::submit(SignedMaxSubmissions::get()),
// assume a solution of 100kb length.
100 * 1024
);
// fallback: emergency phase. // fallback: emergency phase.
pub const Fallback: pallet_election_provider_multi_phase::FallbackStrategy = pub const Fallback: pallet_election_provider_multi_phase::FallbackStrategy =
......
...@@ -41,7 +41,7 @@ use primitives::v1::{ ...@@ -41,7 +41,7 @@ use primitives::v1::{
ValidatorIndex, InboundDownwardMessage, InboundHrmpMessage, SessionInfo, ValidatorIndex, InboundDownwardMessage, InboundHrmpMessage, SessionInfo,
}; };
use sp_runtime::{ use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys, ApplyExtrinsicResult, create_runtime_str, generic, impl_opaque_keys, ApplyExtrinsicResult, FixedPointNumber,
KeyTypeId, Percent, Permill, Perbill, curve::PiecewiseLinear, KeyTypeId, Percent, Permill, Perbill, curve::PiecewiseLinear,
transaction_validity::{TransactionValidity, TransactionSource, TransactionPriority}, transaction_validity::{TransactionValidity, TransactionSource, TransactionPriority},
traits::{ traits::{
...@@ -77,6 +77,7 @@ pub use pallet_staking::StakerStatus; ...@@ -77,6 +77,7 @@ pub use pallet_staking::StakerStatus;
pub use sp_runtime::BuildStorage; pub use sp_runtime::BuildStorage;
pub use pallet_timestamp::Call as TimestampCall; pub use pallet_timestamp::Call as TimestampCall;
pub use pallet_balances::Call as BalancesCall; pub use pallet_balances::Call as BalancesCall;
pub use pallet_election_provider_multi_phase::Call as EPMCall;
/// Constant values used within the runtime. /// Constant values used within the runtime.
pub mod constants; pub mod constants;
...@@ -328,6 +329,7 @@ impl pallet_session::historical::Config for Runtime { ...@@ -328,6 +329,7 @@ impl pallet_session::historical::Config for Runtime {
type FullIdentificationOf = pallet_staking::ExposureOf<Runtime>; type FullIdentificationOf = pallet_staking::ExposureOf<Runtime>;
} }
use pallet_election_provider_multi_phase::WeightInfo;
parameter_types! { parameter_types! {
// phase durations. 1/4 of the last session for each. // phase durations. 1/4 of the last session for each.
pub const SignedPhase: u32 = EPOCH_DURATION_IN_SLOTS / 4; pub const SignedPhase: u32 = EPOCH_DURATION_IN_SLOTS / 4;
...@@ -340,11 +342,14 @@ parameter_types! { ...@@ -340,11 +342,14 @@ parameter_types! {
// This formula is currently adjusted such that a typical solution will spend an amount equal // This formula is currently adjusted such that a typical solution will spend an amount equal
// to the base deposit for every 50 kb. // to the base deposit for every 50 kb.
pub const SignedDepositByte: Balance = deposit(1, 0) / (50 * 1024); pub const SignedDepositByte: Balance = deposit(1, 0) / (50 * 1024);
pub SignedRewardBase: Balance = fee_for_submit_call::< pub SignedRewardBase: Balance = fee_for_submit_call::<Runtime>(
Runtime, // give 20% threshold.
crate::constants::fee::WeightToFee, sp_runtime::FixedU128::saturating_from_rational(12, 10),
crate::weights::pallet_election_provider_multi_phase::WeightInfo<Runtime>, // maximum weight possible.
>(Perbill::from_perthousand(1500)); weights::pallet_election_provider_multi_phase::WeightInfo::<Runtime>::submit(SignedMaxSubmissions::get()),
// assume a solution of 200kb length.
200 * 1024
);
// fallback: emergency phase. // fallback: emergency phase.
pub const Fallback: pallet_election_provider_multi_phase::FallbackStrategy = pub const Fallback: pallet_election_provider_multi_phase::FallbackStrategy =
......
...@@ -65,7 +65,7 @@ use xcm_builder::{ ...@@ -65,7 +65,7 @@ use xcm_builder::{
}; };
use sp_runtime::{ use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys, create_runtime_str, generic, impl_opaque_keys, FixedPointNumber,
ApplyExtrinsicResult, KeyTypeId, Perbill, curve::PiecewiseLinear, ApplyExtrinsicResult, KeyTypeId, Perbill, curve::PiecewiseLinear,
transaction_validity::{TransactionValidity, TransactionSource, TransactionPriority}, transaction_validity::{TransactionValidity, TransactionSource, TransactionPriority},
traits::{ traits::{
...@@ -100,6 +100,7 @@ pub use pallet_staking::StakerStatus; ...@@ -100,6 +100,7 @@ pub use pallet_staking::StakerStatus;
pub use sp_runtime::BuildStorage; pub use sp_runtime::BuildStorage;
pub use pallet_timestamp::Call as TimestampCall; pub use pallet_timestamp::Call as TimestampCall;
pub use pallet_balances::Call as BalancesCall; pub use pallet_balances::Call as BalancesCall;
pub use pallet_election_provider_multi_phase::Call as EPMCall;
/// Constant values used within the runtime. /// Constant values used within the runtime.
pub mod constants; pub mod constants;
...@@ -333,6 +334,7 @@ impl pallet_session::historical::Config for Runtime { ...@@ -333,6 +334,7 @@ impl pallet_session::historical::Config for Runtime {
type FullIdentificationOf = pallet_staking::ExposureOf<Runtime>; type FullIdentificationOf = pallet_staking::ExposureOf<Runtime>;
} }
use pallet_election_provider_multi_phase::WeightInfo;
parameter_types! { parameter_types! {
// phase durations. 1/4 of the last session for each. // phase durations. 1/4 of the last session for each.
pub const SignedPhase: u32 = EPOCH_DURATION_IN_SLOTS / 4; pub const SignedPhase: u32 = EPOCH_DURATION_IN_SLOTS / 4;
...@@ -345,11 +347,14 @@ parameter_types! { ...@@ -345,11 +347,14 @@ parameter_types! {
// This formula is currently adjusted such that a typical solution will spend an amount equal // This formula is currently adjusted such that a typical solution will spend an amount equal
// to the base deposit for every 50 kb. // to the base deposit for every 50 kb.
pub const SignedDepositByte: Balance = deposit(1, 0) / (50 * 1024); pub const SignedDepositByte: Balance = deposit(1, 0) / (50 * 1024);
pub SignedRewardBase: Balance = fee_for_submit_call::< pub SignedRewardBase: Balance = fee_for_submit_call::<Runtime>(
Runtime, // give 20% threshold.
crate::constants::fee::WeightToFee, sp_runtime::FixedU128::saturating_from_rational(12, 10),
crate::weights::pallet_election_provider_multi_phase::WeightInfo<Runtime>, // maximum weight possible.
>(Perbill::from_perthousand(1500)); weights::pallet_election_provider_multi_phase::WeightInfo::<Runtime>::submit(SignedMaxSubmissions::get()),
// assume a solution of 100kb length.
100 * 1024
);
// fallback: emergency phase. // fallback: emergency phase.
pub const Fallback: pallet_election_provider_multi_phase::FallbackStrategy = pub const Fallback: pallet_election_provider_multi_phase::FallbackStrategy =
......
[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" }
// 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::{
params, prelude::*, rpc_helpers::*, signer::Signer, DryRunConfig, Error, SharedConfig, WsClient,
};
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)
}
})
}
/// Helper method to print the encoded size of the snapshot.
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()
);
})
}
/// Find the stake threshold in order to have at most `count` voters.
#[allow(unused)]
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(|(_voter, weight, _targets)| std::cmp::Reverse(*weight));
match voters.get(count) {
Some(threshold_voter) => println!("smallest allowed voter is {:?}", threshold_voter),
None => {
println!("requested truncation to {} voters but had only {}", count, voters.len());
println!("smallest current voter: {:?}", voters.last());
}
}
})
}
macro_rules! dry_run_cmd_for { ($runtime:ident) => { paste::paste! {
/// Execute the dry-run command.
pub(crate) async fn [<dry_run_cmd_ $runtime>](
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);
let (raw_solution, witness) = crate::mine_unchecked::<Runtime>(&mut ext, config.iterations, false)?;
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);
// 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, 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>](
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")?;
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(())
})
}
}}}
emergency_solution_cmd_for!(polkadot);
emergency_solution_cmd_for!(kusama);
emergency_solution_cmd_for!(westend);
// 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/>.
//! # Polkadot Staking Miner.
//!
//! Simple bot capable of monitoring a polkadot (and cousins) chain and submitting solutions to the
//! 'pallet-election-provider-multi-phase'. See `--help` for more details.
//!