Skip to content

Latest commit

 

History

History
56 lines (31 loc) · 2.69 KB

PartIII.md

File metadata and controls

56 lines (31 loc) · 2.69 KB

Lesson 1: Introduction to Koii Tasks

Part III: How Do Koii Tasks Work?

The Basics

In the previous lesson, we added 4 console logs for Task, Submission, Audit, and Distribution. These are the four main parts of a Koii task:

  1. Do the work
  2. Submit the results
  3. Verify the work
  4. Distribute rewards and penalties

This ensures that each node operator has an incentive to act honestly and perform the task correctly. Their work will be checked, and if they don't perform the task correctly, they will not only miss out on rewards, they could lose some or all of their staked KOII.

When writing a task, you're able to customize each step: what work you want done, what should be submitted as proof, how that proof should be checked, and what rewards and penalties you want to set.

Runtime flow

Tip

For a more in-depth explanation of how Koii Tasks run, see our docs on runtime flow and gradual consensus.

Now let's see how runtime flow works in the EZ Testing example.

Example

Do the work

Submission.task().

This task simply saves the string "Hello, World!" to the local database

Submit Proofs

Submission.fetchSubmission() and Submission.sendTask().

In this case, we are fetching the string from the local database and submitting it.

Review Proofs

Audit.validateNode().

Here we are verifying whether the submission is the string "Hello, World!".

Distribute Rewards

Inside Distribution.generateDistributionList().

Rewards are distributed to each node that completed the work. Here we are penalizing incorrect submissions by removing 70% of their stake and equally distributing the bounty per round to all successful submissions.

Alternate Testing

When developing your task, you'll want to iterate quickly, and having to deploy a task or launch the desktop node can be a hassle. We've provided a simple solution in the form of a testing script that will allow you to simulate rounds and test your task functionality. The script is available in tests/unitTest.js and you can run it via yarn test.

Now that we've seen how tasks work, let's deploy one. PartIV