Made with Substrate, for Polkadot.
An onchain implementation of a semi-sorted linked list, with permissionless sorting and update operations.
pallet module for more information about the interfaces this pallet exposes,
including its configuration trait, dispatchables, storage items, events and errors.
This pallet provides an implementation of
frame_election_provider_support::SortedListProvider] and it can typically be used by another
pallet via this API.
This pallet splits
AccountIds into different bags. Within a bag, these
AccountIds are stored
as nodes in a linked-list manner. This pallet then provides iteration over all bags, which
basically allows an infinitely large list of items to be kept in a sorted manner.
Each bags has a upper and lower range of scores, denoted by
Config::BagThresholds. All nodes
within a bag must be within the range of the bag. If not, the permissionless
can be used to move any node to the right bag.
Additional reading, about how this pallet is used in the context of Polkadot’s staking system: https://polkadot.network/blog/staking-update-september-2021/#bags-list-in-depth
example for a diagram of
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.
- items are kept in bags, which are delineated by their range of score (See
- 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.
- In this example, assuming each node has an equal id and score (eg. node 21 has a score of 21), the node 22 can be moved from bag 1 to bag 0 with the
- The migrations of this pallet.
- Mock runtime for pallet-bags-lists tests.
palletmodule in each FRAME pallet hosts the most important items needed to construct this pallet.
- Autogenerated weights for pallet_bags_list
- A Bag is a doubly-linked list of ids, where each id is mapped to a
- The ONLY entry point of this module. All operations to the bags-list should happen through this interface. It is forbidden to access other module members directly.
- A Node is the fundamental element comprising the doubly-linked list described by
- Given a certain score, to which bag does it belong to?