Leader Election
Last updated
Last updated
are used to determine which operator (or ) executes a at any given time. These mechanisms ensure the orderly allocation of tasks and optimal system performance while avoiding conflicts. Conflicts can occur when multiple operators try to execute the same task simultaneously, leading to duplicate efforts or inconsistent system states.
Developers can write their own algorithm to determine the Task Performer. For more information, please refer to the .
Below are different leader election mechanisms commonly used in decentralized networks:
Description: The "Task Performer" is chosen in a round-robin fashion, where operators take turns performing tasks in a fixed sequence based on their IDs. The system cycles through the list of operators, ensuring an even distribution of tasks.
Implementation: This can be implemented by taking the block number modulo the number of operators (plus one). The result gives a number in the range [1..count], corresponding to the chosen performer's ID.
Description: The "Task Performer" is chosen randomly and deterministically from the pool of nodes. This method ensures that no operator is favored over another, and it can prevent systematic bias in task distribution.
Implementation: A random number generator can be used to select a task performer from the pool of operators.
Description: The "Task Performer" is selected based on a weighted probability. It ensures that operators with higher Voting Power (or other assigned weights) have a greater likelihood of being chosen while still maintaining an element of randomness.
Implementation: This can be implemented by retrieving the list of all the active operators, performing a weighted random selection to determine the Task Performer.
Description: Uses an auction-based approach where nodes bid for task execution rights. The key idea is that coordination happens through the auction mechanism rather than through leader election.
Implementation: This can be implemented through a two-phase commit process where nodes first publish commitment hashes of their bids (commit phase), then reveal their actual bids (reveal phase). The highest bidder is determined independently by all nodes using the same verification process. The winning node gains the right to perform the task.
Priority-based Selection
Description: Operators are assigned different priority levels, and the highest priority operator is chosen to perform the task. This priority can be based on factors such as reputation, available resources, or past performance.
Implementation: A priority queue can be used to select the operator with the highest priority for the task.
Leader Election via Consensus
Implementation: Operators vote on who should be the leader, and the one with the majority of votes is chosen to perform the task.
Upon Task execution trigger, the node broadcasts a custom message to the P2P network. Peers receive the message and run a leader election algorithm to select the operator responsible for executing the task.
Publishing the Task Request
Invoke the Leader Election Algorithm
When a peer receives a custom message, the /p2p/message
endpoint triggers the leader election algorithm to determine which peer will execute the task.
Round Robin ()
Prevrandao Selection ()
Stake Weighted Leader Selection ()
Leaderless Auction ()
Description: In this approach, operators participate in a consensus mechanism, such as , to elect a leader to perform the task. This is commonly used in distributed systems, where the leader coordinates task execution and ensures system consistency.
Publish the task request as a to the P2P network using the JSON-RPC method.