Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Make staking VoterList implementation generic #9440

Closed
Tracked by #9081
emostov opened this issue Jul 26, 2021 · 0 comments · Fixed by #9507
Closed
Tracked by #9081

Make staking VoterList implementation generic #9440

emostov opened this issue Jul 26, 2021 · 0 comments · Fixed by #9507

Comments

@emostov
Copy link
Contributor

emostov commented Jul 26, 2021

#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

This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant