Skip to main content

VoterList

Calls

putInFrontOf

Move the caller's Id directly in front of lighter.

The dispatch origin for this call must be Signed and can only be called by the Id of the account going in front of lighter.

Only works if

  • both nodes are within the same bag,

  • and origin has a greater Score than lighter.

Namespace

api.tx.voterList.putInFrontOf

Type

function putInFrontOf(
lighter: SeedPrimitivesSignatureAccountId20
)

rebag

Declare that some dislocated account has, through rewards or penalties, sufficiently changed its score that it should properly fall into a different bag than its current one.

Anyone can call this function about any potentially dislocated account.

Will always update the stored score of dislocated to the correct score, based on ScoreProvider.

If dislocated does not exists, it returns an error.

Namespace

api.tx.voterList.rebag

Type

function rebag(
dislocated: SeedPrimitivesSignatureAccountId20
)

Storage

counterForListNodes

Counter for the related counted storage map

Namespace

api.query.voterList.counterForListNodes

Type

function counterForListNodes(

): u32

listBags

A bag stored in storage.

Stores a Bag struct, which stores head and tail pointers to itself.

Namespace

api.query.voterList.listBags

Type

function listBags(
u64
): Option<PalletBagsListListBag>

listNodes

A single node, within some bag.

Nodes store links forward and back within their respective bags.

Namespace

api.query.voterList.listNodes

Type

function listNodes(
SeedPrimitivesSignatureAccountId20
): Option<PalletBagsListListNode>

Events

Rebagged

Moved an account from one bag to another.

Namespace

api.events.voterList.Rebagged

Type

type Rebagged = {
who: SeedPrimitivesSignatureAccountId20,
from: u64,
to: u64
}

ScoreUpdated

Updated the score of some account to the given amount.

Namespace

api.events.voterList.ScoreUpdated

Type

type ScoreUpdated = {
who: SeedPrimitivesSignatureAccountId20,
new_score: u64
}

Errors

List

A error in the list interface implementation.

Namespace

api.errors.voterList.List

Constants

bagThresholds

The list of thresholds separating the various bags.

Ids are separated into unsorted bags according to their score. This specifies the thresholds separating the bags. An id's bag is the largest bag for which the id's score is less than or equal to its upper threshold.

When ids are iterated, higher bags are iterated completely before lower bags. This means that iteration is semi-sorted: ids of higher score tend to come before ids of lower score, but peer ids within a particular bag are sorted in insertion order.

Expressing the constant

This constant must be sorted in strictly increasing order. Duplicate items are not permitted.

There is an implied upper limit of Score::MAX; that value does not need to be specified within the bag. For any two threshold lists, if one ends with Score::MAX, the other one does not, and they are otherwise equal, the two lists will behave identically.

Calculation

It is recommended to generate the set of thresholds in a geometric series, such that there exists some constant ratio such that threshold[k + 1] == (threshold[k] * constant_ratio).max(threshold[k] + 1) for all k.

The helpers in the /utils/frame/generate-bags module can simplify this calculation.

Examples

  • If BagThresholds::get().is_empty(), then all ids are put into the same bag, and iteration is strictly in insertion order.

  • If BagThresholds::get().len() == 64, and the thresholds are determined according to the procedure given above, then the constant ratio is equal to 2.

  • If BagThresholds::get().len() == 200, and the thresholds are determined according to the procedure given above, then the constant ratio is approximately equal to 1.248.

  • If the threshold list begins [1, 2, 3, ...], then an id with score 0 or 1 will fall into bag 0, an id with score 2 will fall into bag 1, etc.

Migration

In the event that this list ever changes, a copy of the old bags list must be retained. With that List::migrate can be called, which will perform the appropriate migration.

Namespace

api.consts.voterList.bagThresholds

Type

type bagThresholds = Vec<u64>