Crate pallet_tasks

Source
Expand description

§Timechain Task Pallet

This chart shows all the extrinsics and events of the task pallet. It categorizes the extrinsics into two types: those that can be called by root or council, and those that can be called by any user. The root or council extrinsics are related to administrative tasks, while user extrinsics are related to task operations and submissions.

graph LR

         C1["Root/Council"]
         C2["Chronicles Shard Member"]
         
         T1["create_task(descriptor)"] 
         T3["reset_task(task_id)"]
         
         T4["submit_result(task_id, result) unsigned"]    
         T5["submit_hash(task_id, hash)"]
         T6["submit_signature()"]
         
         T7["set_shard_task_limit()"]
         
         T8["set_batch_size()"]
         T9["set_read_task_reward()"]
         T10["set_write_task_reward()"]
         T11["set_send_message_task_reward()"]
     
         T12["register_gateway()"]
         T13["unregister_gateways()"]
         T14["sudo_cancel_task()"]
         T15["sudo_cancel_tasks()"]
         
         E1["TaskCreated(TaskId)"]
         E2["TaskResult(TaskId, TaskResult)"]
         E3["GatewayRegistered(NetworkId, [u8; 20], u64)"]
         
         E4["ReadTaskRewardSet(NetworkId, BalanceOf)"]
         E5["WriteTaskRewardSet(NetworkId, BalanceOf)"]
         E6["SendMessageTaskRewardSet(NetworkId, BalanceOf)"]
         
         E7["ShardTaskLimitSet(NetworkId, u32)"]
         E8["BatchSizeSet(NetworkId, u64, u64)"]
         
         C2 --> T1 --> E1 
         C2 --> T4 --> E2
         C2 --> T5 
         C2 --> T6
 
         C1 --> T7 --> E7 
         C1 --> T8 --> E8
         C1 --> T9 --> E4
         C1 --> T10 --> E5
         C1 --> T11 --> E6
         C1 --> T12 --> E3
         C1 --> T13 
         C1 --> T14
         C1 --> T15
         C1 --> T3
         
    
 
 style C1 fill:#9f9,stroke:#333,stroke-width:2px
 style C2 fill:#9f9,stroke:#333,stroke-width:2px
 
 style T1 fill:#f9f,stroke:#333,stroke-width:2px
 style T3 fill:#f9f,stroke:#333,stroke-width:2px
 style T4 fill:#f9f,stroke:#333,stroke-width:2px
 style T5 fill:#f9f,stroke:#333,stroke-width:2px
 style T6 fill:#f9f,stroke:#333,stroke-width:2px
 style T7 fill:#f9f,stroke:#333,stroke-width:2px
 style T8 fill:#f9f,stroke:#333,stroke-width:2px
 style T9 fill:#f9f,stroke:#333,stroke-width:2px
 style T10 fill:#f9f,stroke:#333,stroke-width:2px
 style T11 fill:#f9f,stroke:#333,stroke-width:2px
 style T12 fill:#f9f,stroke:#333,stroke-width:2px
 style T13 fill:#f9f,stroke:#333,stroke-width:2px
 style T14 fill:#f9f,stroke:#333,stroke-width:2px
 style T15 fill:#f9f,stroke:#333,stroke-width:2px
 
 style E1 fill:#bbf,stroke:#333,stroke-width:2px
 style E2 fill:#bbf,stroke:#333,stroke-width:2px
 style E3 fill:#bbf,stroke:#333,stroke-width:2px
 style E4 fill:#bbf,stroke:#333,stroke-width:2px
 style E5 fill:#bbf,stroke:#333,stroke-width:2px
 style E6 fill:#bbf,stroke:#333,stroke-width:2px
 style E7 fill:#bbf,stroke:#333,stroke-width:2px
 style E8 fill:#bbf,stroke:#333,stroke-width:2px

§Task Pallet Lifecycle and Operations

This flowchart outlines the lifecycle of a task in the task pallet. It starts with task creation and checks if the shard is online. If successful, the task is assigned to a shard and progresses through various phases (sign, write, read). Upon completion, rewards are paid out. Tasks can also be reset, and error handling includes retrying or canceling tasks.

flowchart TB

    %% Task Creation
    A[Create Task] --> L{Shard Online};
    L -->|Shard Not Online| SSF[Failure State];
    L -->|Success| B[Unassigned Task];
    
    %% Task Assignment and Execution
    B --> C{Task Scheduled?};
    C -->|Yes| D[Assign Task to Shard];
    D --> E[Set Initial Phase];
    E --> Fund[Add funds from inflation];
    

    
    

    %% Reward Payout
    P --> Q[Reward Payout];
    
    %% Task Reset and Unregistration
    R[Reset Tasks] --> S[Remove Shard Tasks];
    S --> T[Add Unassigned Tasks];
    T --> B;
    U[Unregister Gateways] --> V[Clear Gateway and Shard Data];
    V --> B;
    %% Fund --> F[Task Execution];
		Fund --> W
	  subgraph TaskExecution
	    W[Sign Phase];
	    W --> G 
	    G --> H
	    G[Write Phase];
	    H[Read Phase];
	    P[Finish Task];
	    H --> P; 
	    W --> F[Failure State];
	    G --> F;
	    H --> F; 
    
    end
    %% Error Handling and Retrying
    K[Retry/Cancel Task];
    K -->|Retry| B;
    
    
    F -- Timeout/Error --> K 

    
    %% Styles
    style A fill:#f9f,stroke:#333,stroke-width:2px;
    style F fill:#f96,stroke:#333,stroke-width:2px;
    style R fill:#f9f,stroke:#333,stroke-width:2px;
    style U fill:#f9f,stroke:#333,stroke-width:2px;
    style K fill:#f96,stroke:#333,stroke-width:2px;
    style SSF fill:#f96,stroke:#333,stroke-width:2px;

§Unregister Gateways

This flowchart illustrates the process for unregistering gateways in the task pallet. It ensures that only a root user can perform this action. The process involves clearing a specified number of gateways, all registered shards, and filtering tasks to determine their status and handle them appropriately. Errors during the process are logged and returned.

graph TB;
    U[Unregister Gateways] --> U2[Ensure Root User];
    U2 --> U3[Clear Specified Number of Gateways];
    U3 --> U4[Clear All Registered Shards];
    U4 --> U5[Filter and Process Tasks];
    
    U5 --> U6{Task Loop};
    U6 -->|Unassigned Tasks| U7[Iterate Over Unassigned Tasks];
    U7 --> U8[Check Task Function];
    U8 --> U9[Task Status];
    
    U6 -->|Shard Tasks| U10[Iterate Over Shard Tasks];
    U10 --> U11[Check Task Function];
    U11 --> U9;
    
    U9 --> U13[Return Ok];
    U9 -->|ReadMessages| U14[Log Error and Return];

    %% Styles
    style U fill:#f9f,stroke:#333,stroke-width:2px;
    style U14 fill:#f96,stroke:#333,stroke-width:2px;

§Reset Tasks

This flowchart shows the process for resetting tasks in the task pallet. It ensures that only a root user can initiate the reset. The reset process includes iterating over unassigned tasks and tasks associated with specific shards, resetting their phase state, and adding them back to unassigned tasks if necessary. The iteration stops once the maximum number of tasks to be reset is reached.

graph TB;
	RT[Reset Task] --> RT1[Ensure Root User];
    RT1 -->|Yes| RT2[Continue];
    RT1 -->|No| RT3[Failure State];
    
    %% Reset Unassigned Tasks
    RT2 --> RT10["Iterate Over Unassigned Tasks"];
    RT10 --> RT11{Reset < Max?};
    RT11 -->|Yes| RT12["Get Task ID"];
    RT12 -->|Exists| RT13[Reset TaskPhaseState];
    RT13 -->|Initial Phase| RT14[Reset += 1];
    RT14 --> RT2;
    RT11 -->|No| RT15[Stop Iteration];

    %% Reset Tasks Associated with Specific Shards
    RT2 --> RT4["Iterate Over Task Shards"];
    RT4 --> RT5{To_be_reset < Max?};
    RT5 -->|Yes| RT6[Remove Tasks from Shard Tasks];
    RT6 --> RT7[Get Task ID];
    RT7 -->|Exists| RT8[Add to Unassigned Tasks];
    RT8 -->|Success| RT9[To_be_reset += 1];
    RT9 --> RT2;
    RT5 -->|No| RT15[Stop Iteration];

    %% Styles
    style RT fill:#f9f,stroke:#333,stroke-width:2px;
    style RT3 fill:#f96,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.