Crate pallet_elections

Source
Expand description

§Elections Pallet

The flowchart represents the logical flow and interactions within the pallet, detailing how various functions and operations are interconnected. It begins with different entry points corresponding to various operations: setting shard configuration, setting electable members, handling member online/offline events, handling shard offline events.

Set Shard Configuration Flow starts by ensuring the caller is a root user, validating the shard size and threshold, updating the storage, emitting an event, iterating through unassigned members, and trying to elect a new shard.

Member Online Flow checks if the member is part of a shard. If not, it verifies if the member is electable, adds them to the unassigned list, and attempts to elect a new shard. If the member is already part of a shard, it simply notifies the shards interface.

Shard Offline Flow adds the shard members to the unassigned list and tries to elect a new shard.

Try Elect Shard Flow evaluates if a new shard can be formed, removes the selected members from the unassigned list, and creates a new shard using the shards interface.

New Shard Members Flow retrieves the required shard size, gathers unassigned and online members, ensures there are enough members to form a shard, sorts members by stake, selects the top members to form the shard, and returns the selected members.

flowchart TB



        New3[set_shard_config] --> setShardConfig1[Ensure root]
        validateShard[Validate shard_size >= shard_threshold]
        updateStorage[Update ShardSize and ShardThreshold]
        emitEvent[Emit ShardConfigSet event]
        iterateUnassigned[Iterate through Unassigned members]
        tryElectShard1[try_elect_shard]
        
        setShardConfig1 --> validateShard
        validateShard -->|Valid| updateStorage
        updateStorage --> emitEvent
        emitEvent --> iterateUnassigned
        iterateUnassigned --> tryElectShard1

    
        New2[member_online] --> memberOnline1[Check if member is shard member]
        checkElectable[Check if member is electable]
        insertUnassigned[Insert member to Unassigned]
        tryElectShard2[try_elect_shard]
        notifyShards1[Notify Shards interface]
        
        memberOnline1 -->|No| checkElectable
        checkElectable --> insertUnassigned
        insertUnassigned --> tryElectShard2
        tryElectShard2 --> notifyShards1
        
        memberOnline1 -->|Yes| notifyShards2[Notify Shards interface]


        shardOffline1[shard_offline]
        insertUnassignedShard[Insert shard members to Unassigned]
        tryElectShard3[try_elect_shard]
        
        shardOffline1 --> insertUnassignedShard
        insertUnassignedShard --> tryElectShard3
        
        memberOffline[member_offline]
		    memberOffline --> removeUnassigned[Remove member from Unassigned]
		    removeUnassigned --> notifyShards3[Notify Shards interface]

    

 

    %%tryElectShard1 -->|Calls| tryElectShard4
    %%tryElectShard3 -->|Calls| tryElectShard4
    %%tryElectShard2 -->|Calls| tryElectShard4
    %%createShard -->|Calls| New1

%% styles
style New2 fill:#9f9,stroke:#333,stroke-width:2px;
style New3 fill:#9f9,stroke:#333,stroke-width:2px
style memberOffline fill:#9f9,stroke:#333,stroke-width:2px;
style shardOffline1 fill:#9f9,stroke:#333,stroke-width:2px;
style tryElectShard1 fill:#9f9,stroke:#333,stroke-width:2px;
style tryElectShard2 fill:#9f9,stroke:#333,stroke-width:2px;
style tryElectShard3 fill:#9f9,stroke:#333,stroke-width:2px;


style emitEvent fill:#bbf,stroke:#333,stroke-width:2px;

flowchart TD

        tryElectShard4[try_elect_shard]
        checkNewShard[Check if new shard can be formed]
        removeSelectedMembers[Remove selected members from Unassigned]
        createShard[Create shard using Shards interface]
        
        tryElectShard4 --> checkNewShard
        checkNewShard -->|Yes| removeSelectedMembers
        removeSelectedMembers --> createShard

    

        New1[new_shard_members] --> newShardMembers2[Retrieve required shard size]
        collectUnassigned[Collect unassigned members and filter online members]
        checkEnoughMembers[Enough members to form shard?]
        returnNone[Return None]
        sortMembers[Sort members by stake]
        selectTopMembers[Select top members to form shard]
        returnSelected[Return selected members]
        
        newShardMembers2 --> collectUnassigned
        collectUnassigned --> checkEnoughMembers
        checkEnoughMembers -->|No| returnNone
        checkEnoughMembers -->|Yes| sortMembers
        sortMembers --> selectTopMembers
        selectTopMembers --> returnSelected
        
        
    setElectable[set_electable]
    setElectable -->|Ensure root| clearElectable[Clear current electable list]
    clearElectable --> insertElectable[Insert new electable members]
 

        
        
%% styles

style New1 fill:#9f9,stroke:#333,stroke-width:2px;
style tryElectShard4 fill:#9f9,stroke:#333,stroke-width:2px;
style setElectable fill:#9f9,stroke:#333,stroke-width:2px;

Re-exports§

Modules§

  • The pallet module in each FRAME pallet hosts the most important items needed to construct this pallet.