14 major breaking releases

18.0.0 Mar 5, 2023
17.0.0 Feb 26, 2023
16.0.0 Feb 19, 2023
15.0.0 Feb 12, 2023
0.0.0 Nov 21, 2022

#514 in Magic Beans

Download history 155/week @ 2022-12-13 66/week @ 2022-12-20 10/week @ 2022-12-27 8/week @ 2023-01-03 64/week @ 2023-01-10 72/week @ 2023-01-17 21/week @ 2023-01-24 70/week @ 2023-01-31 51/week @ 2023-02-07 72/week @ 2023-02-14 75/week @ 2023-02-21 44/week @ 2023-02-28 10/week @ 2023-03-07 30/week @ 2023-03-14

181 downloads per month
Used in 2 crates

Apache-2.0

2MB
39K SLoC

pallet-bags-list

Auto-generated README.md for publishing to crates.io


lib.rs:

Bags-List Pallet

A semi-sorted list, where items hold an AccountId based on some Score. The AccountId (id for short) might be synonym to a voter or nominator in some context, and Score signifies the chance of each id being included in the final [SortedListProvider::iter].

It implements [frame_election_provider_support::SortedListProvider] to provide a semi-sorted list of accounts to another pallet. It needs some other pallet to give it some information about the weights of accounts via [frame_election_provider_support::ScoreProvider].

This pallet is not configurable at genesis. Whoever uses it should call appropriate functions of the SortedListProvider (e.g. on_insert, or unsafe_regenerate) at their genesis.

Goals

The data structure exposed by this pallet aims to be optimized for:

  • insertions and removals.
  • iteration over the top* N items by score, where the precise ordering of items doesn't particularly matter.

Details

  • items are kept in bags, which are delineated by their range of score (See [Config::BagThresholds]).
  • for iteration, bags are chained together from highest to lowest and elements within the bag are iterated from head to tail.
  • items within a bag are iterated in order of insertion. Thus removing an item and re-inserting it will worsen its position in list iteration; this reduces incentives for some types of spam that involve consistently removing and inserting for better position. Further, ordering granularity is thus dictated by range between each bag threshold.
  • if an item's score changes to a value no longer within the range of its current bag the item's position will need to be updated by an external actor with rebag (update), or removal and insertion.

Dependencies

~8–44MB
~757K SLoC