New sub-trait to mock staking miner (#11350)

* new separate config trait for staking miner

* fix some docs and stuff

* relax trait bounds

* some cleanup

* Update frame/election-provider-multi-phase/src/unsigned.rs

* add comment

* self review and fix build

* fix docs

Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
This commit is contained in:
Kian Paimani
2022-05-11 18:45:59 +01:00
committed by GitHub
parent 479dc63af4
commit d06d20d65b
7 changed files with 479 additions and 465 deletions
+24 -5
View File
@@ -23,7 +23,9 @@
#![recursion_limit = "256"]
use codec::{Decode, Encode, MaxEncodedLen};
use frame_election_provider_support::{onchain, ExtendedBalance, SequentialPhragmen, VoteWeight};
use frame_election_provider_support::{
onchain, ElectionDataProvider, ExtendedBalance, SequentialPhragmen, VoteWeight,
};
use frame_support::{
construct_runtime,
pallet_prelude::Get,
@@ -660,6 +662,25 @@ impl onchain::BoundedConfig for OnChainSeqPhragmen {
type TargetsBound = ConstU32<2_000>;
}
impl pallet_election_provider_multi_phase::MinerConfig for Runtime {
type AccountId = AccountId;
type MaxLength = MinerMaxLength;
type MaxWeight = MinerMaxWeight;
type Solution = NposSolution16;
type MaxVotesPerVoter =
<<Self as pallet_election_provider_multi_phase::Config>::DataProvider as ElectionDataProvider>::MaxVotesPerVoter;
// The unsigned submissions have to respect the weight of the submit_unsigned call, thus their
// weight estimate function is wired to this call's weight.
fn solution_weight(v: u32, t: u32, a: u32, d: u32) -> Weight {
<
<Self as pallet_election_provider_multi_phase::Config>::WeightInfo
as
pallet_election_provider_multi_phase::WeightInfo
>::submit_unsigned(v, t, a, d)
}
}
impl pallet_election_provider_multi_phase::Config for Runtime {
type Event = Event;
type Currency = Balances;
@@ -669,9 +690,8 @@ impl pallet_election_provider_multi_phase::Config for Runtime {
type BetterUnsignedThreshold = BetterUnsignedThreshold;
type BetterSignedThreshold = ();
type OffchainRepeat = OffchainRepeat;
type MinerMaxWeight = MinerMaxWeight;
type MinerMaxLength = MinerMaxLength;
type MinerTxPriority = MultiPhaseUnsignedPriority;
type MinerConfig = Self;
type SignedMaxSubmissions = ConstU32<10>;
type SignedRewardBase = SignedRewardBase;
type SignedDepositBase = SignedDepositBase;
@@ -682,7 +702,6 @@ impl pallet_election_provider_multi_phase::Config for Runtime {
type SlashHandler = (); // burn slashes
type RewardHandler = (); // nothing to do upon rewards
type DataProvider = Staking;
type Solution = NposSolution16;
type Fallback = onchain::BoundedExecution<OnChainSeqPhragmen>;
type GovernanceFallback = onchain::BoundedExecution<OnChainSeqPhragmen>;
type Solver = SequentialPhragmen<AccountId, SolutionAccuracyOf<Self>, OffchainRandomBalancing>;
@@ -2017,7 +2036,7 @@ mod tests {
#[test]
fn perbill_as_onchain_accuracy() {
type OnChainAccuracy =
<<Runtime as pallet_election_provider_multi_phase::Config>::Solution as NposSolution>::Accuracy;
<<Runtime as pallet_election_provider_multi_phase::MinerConfig>::Solution as NposSolution>::Accuracy;
let maximum_chain_accuracy: Vec<UpperOf<OnChainAccuracy>> = (0..MaxNominations::get())
.map(|_| <UpperOf<OnChainAccuracy>>::from(OnChainAccuracy::one().deconstruct()))
.collect();