-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Make staking VoterList implementation generic #9440
Description
#9081 introduces a VoterList abstraction to the staking pallet, which uses a number of storage items to implement a data structure that stores voters in based on vote weight in bags made of linked lists.
However, we don't require a mandatory data structure dictating how voters are iterated, as long as we have an iterator that gives the voters in desired order. We can make create a trait, VoterListProvider, that would provide a voter list. The voter_bags module can then be turned into a pallet that implements the trait.
An example use case: we can roll out the voter bags to just Kusama to see how it goes before adding the change to Polkadot. (Previously @shawntabrizi mentioned some other ideas to achieve the same goal, like feature gating voter bags.)
Rough initial trait:
trait VoterListProvider {
// Returns iterator over voter list, which can have `take` called on it.
fn get_voters() -> impl Iterator<Item = VoterData> {}
// Hook for updating the list when a voter is added, or their vote weight changes.
fn on_voter_update(voter: AccountId) {}
// Hook for removing a voter from the list
fn on_voter_removed() {}
// Returns function for getting voters weight (may not be necessary)
fn weight_of_fn() -> -> Box<dyn Fn(&T::AccountId) -> VoteWeight> {}
}and a stub implementation not using voter bags
struct StakingVoterListStub;
impl VoterListProvider for StakingVoterListStub {
fn get_voters() -> impl Iterator<Item = VoterData> {
<pallet_staking::Pallet<T>>::nominators().map(|(v, _)| voter_data(v))
}
// Hook not used
fn on_new_voter(_voter: AccountId) {}
// Hook not used
fn on_voter_removed() {}
// Probably not neccesary
fn weight_of_fn() -> -> Box<dyn Fn(&T::AccountId) -> VoteWeight> {
let issuance = T::Currency::total_issuance();
Box::new(move |who: &T::AccountId| -> VoteWeight {
Self::slashable_balance_of_vote_weight(who, issuance)
})
}
}cc @kianenigma
Metadata
Metadata
Assignees
Labels
Type
Projects
Status