mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-29 21:57:55 +00:00
Make bags-list generic over node value and instantiable (#10997)
* make instantiable * update * cargo fmt * Clean up * bags-list: Make it generic over node value * Respond to some feedback * Apply suggestions from code review Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Add back default impl for weight update worst case * Update to Score in more places' * Use VoteWeight, not u64 to reduce test diff * FMT * FullCodec implies Codec * formatting * Fixup bags list remote test Co-authored-by: doordashcon <jesse.chejieh@gmail.com> Co-authored-by: Doordashcon <90750465+Doordashcon@users.noreply.github.com> Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
@@ -189,7 +189,7 @@ impl<T: Config> ListScenario<T> {
|
||||
|
||||
// find a destination weight that will trigger the worst case scenario
|
||||
let dest_weight_as_vote =
|
||||
T::SortedListProvider::weight_update_worst_case(&origin_stash1, is_increase);
|
||||
T::SortedListProvider::score_update_worst_case(&origin_stash1, is_increase);
|
||||
|
||||
let total_issuance = T::Currency::total_issuance();
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
//! Test utilities
|
||||
|
||||
use crate::{self as pallet_staking, *};
|
||||
use frame_election_provider_support::{onchain, SortedListProvider};
|
||||
use frame_election_provider_support::{onchain, SortedListProvider, VoteWeight};
|
||||
use frame_support::{
|
||||
assert_ok, parameter_types,
|
||||
traits::{
|
||||
@@ -240,8 +240,9 @@ parameter_types! {
|
||||
impl pallet_bags_list::Config for Test {
|
||||
type Event = Event;
|
||||
type WeightInfo = ();
|
||||
type VoteWeightProvider = Staking;
|
||||
type ScoreProvider = Staking;
|
||||
type BagThresholds = BagThresholds;
|
||||
type Score = VoteWeight;
|
||||
}
|
||||
|
||||
impl onchain::Config for Test {
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
//! Implementations for the Staking FRAME Pallet.
|
||||
|
||||
use frame_election_provider_support::{
|
||||
data_provider, ElectionDataProvider, ElectionProvider, SortedListProvider, Supports,
|
||||
VoteWeight, VoteWeightProvider, VoterOf,
|
||||
data_provider, ElectionDataProvider, ElectionProvider, ScoreProvider, SortedListProvider,
|
||||
Supports, VoteWeight, VoterOf,
|
||||
};
|
||||
use frame_support::{
|
||||
pallet_prelude::*,
|
||||
@@ -1244,13 +1244,15 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config> VoteWeightProvider<T::AccountId> for Pallet<T> {
|
||||
fn vote_weight(who: &T::AccountId) -> VoteWeight {
|
||||
impl<T: Config> ScoreProvider<T::AccountId> for Pallet<T> {
|
||||
type Score = VoteWeight;
|
||||
|
||||
fn score(who: &T::AccountId) -> Self::Score {
|
||||
Self::weight_of(who)
|
||||
}
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn set_vote_weight_of(who: &T::AccountId, weight: VoteWeight) {
|
||||
fn set_score_of(who: &T::AccountId, weight: Self::Score) {
|
||||
// this will clearly results in an inconsistent state, but it should not matter for a
|
||||
// benchmark.
|
||||
let active: BalanceOf<T> = weight.try_into().map_err(|_| ()).unwrap();
|
||||
@@ -1279,6 +1281,7 @@ impl<T: Config> VoteWeightProvider<T::AccountId> for Pallet<T> {
|
||||
pub struct UseNominatorsMap<T>(sp_std::marker::PhantomData<T>);
|
||||
impl<T: Config> SortedListProvider<T::AccountId> for UseNominatorsMap<T> {
|
||||
type Error = ();
|
||||
type Score = VoteWeight;
|
||||
|
||||
/// Returns iterator over voter list, which can have `take` called on it.
|
||||
fn iter() -> Box<dyn Iterator<Item = T::AccountId>> {
|
||||
@@ -1290,11 +1293,11 @@ impl<T: Config> SortedListProvider<T::AccountId> for UseNominatorsMap<T> {
|
||||
fn contains(id: &T::AccountId) -> bool {
|
||||
Nominators::<T>::contains_key(id)
|
||||
}
|
||||
fn on_insert(_: T::AccountId, _weight: VoteWeight) -> Result<(), Self::Error> {
|
||||
fn on_insert(_: T::AccountId, _weight: Self::Score) -> Result<(), Self::Error> {
|
||||
// nothing to do on insert.
|
||||
Ok(())
|
||||
}
|
||||
fn on_update(_: &T::AccountId, _weight: VoteWeight) {
|
||||
fn on_update(_: &T::AccountId, _weight: Self::Score) {
|
||||
// nothing to do on update.
|
||||
}
|
||||
fn on_remove(_: &T::AccountId) {
|
||||
@@ -1302,7 +1305,7 @@ impl<T: Config> SortedListProvider<T::AccountId> for UseNominatorsMap<T> {
|
||||
}
|
||||
fn unsafe_regenerate(
|
||||
_: impl IntoIterator<Item = T::AccountId>,
|
||||
_: Box<dyn Fn(&T::AccountId) -> VoteWeight>,
|
||||
_: Box<dyn Fn(&T::AccountId) -> Self::Score>,
|
||||
) -> u32 {
|
||||
// nothing to do upon regenerate.
|
||||
0
|
||||
|
||||
@@ -166,7 +166,10 @@ pub mod pallet {
|
||||
/// Something that can provide a sorted list of voters in a somewhat sorted way. The
|
||||
/// original use case for this was designed with `pallet_bags_list::Pallet` in mind. If
|
||||
/// the bags-list is not desired, [`impls::UseNominatorsMap`] is likely the desired option.
|
||||
type SortedListProvider: SortedListProvider<Self::AccountId>;
|
||||
type SortedListProvider: SortedListProvider<
|
||||
Self::AccountId,
|
||||
Score = frame_election_provider_support::VoteWeight,
|
||||
>;
|
||||
|
||||
/// The maximum number of `unlocking` chunks a [`StakingLedger`] can have. Effectively
|
||||
/// determines how many unique eras a staker may be unbonding in.
|
||||
|
||||
Reference in New Issue
Block a user