Job Lifecycle
Create, claim, submit, approve, dispute, and resolve jobs
create_job
Escrows a reward and creates a new Job PDA.
Parameters:
| Param | Type | Description |
|---|---|---|
reward_amount | u64 | Tokens to escrow (must be > 0) |
data_hash | [u8; 32] | Blake3 hash of the off-chain job payload |
priority | u8 | 0=Low, 1=Medium, 2=High |
max_retries | u8 | Re-open count after expiry |
Effects:
- Creates Job PDA at
["job", queue, job_id_le_bytes] - Transfers
reward_amountto vault - Increments
total_jobs_createdon queue - Status: Open
cancel_job
Cancels an unclaimed job and returns the reward.
Requirements: Job must be in Open status. Only the creator can cancel.
Effects:
- Returns
reward_amountfrom vault to creator's token account - Status: Cancelled (terminal)
claim_job
Worker claims an open job, starting the deadline timer.
Requirements:
- Job must be Open
- Worker must be registered and active
- Worker's
active_jobs < max_concurrent_jobs - Queue must not be paused
Effects:
- Sets
worker,claimed_at,deadlineon the Job - Increments
active_jobson Worker - Status: Claimed
submit_result
Worker submits a result hash for a claimed job.
Parameters:
| Param | Type | Description |
|---|---|---|
result_hash | [u8; 32] | Hash of the off-chain result |
Requirements: Job must be Claimed. Only the assigned worker can submit.
Effects:
- Creates JobResult PDA at
["result", job] - Status: Submitted
approve_result
Creator approves the submitted result, releasing the reward.
Requirements: Job must be Submitted. Only the creator can approve.
Effects:
- Transfers
reward_amountfrom vault to worker's token account - Increments
jobs_completedandtotal_earnedon Worker - Decrements
active_jobson Worker - Status: Completed (terminal)
dispute_result
Creator disputes the submitted result, escalating to the arbiter.
Requirements: Job must be Submitted. Only the creator can dispute.
Effects:
- Status: Disputed
resolve_dispute
Arbiter rules on a disputed job.
Parameters:
| Param | Type | Description |
|---|---|---|
worker_wins | bool | Whether the worker's result is accepted |
If worker wins:
- Reward released to worker
jobs_completedincremented- Status: Completed
If worker loses:
- Worker slashed:
slash_amount = stake * slash_rate_bps / 10000 - Full
slash_amountreturned to creator (plus reward) jobs_failedincremented- Status: Expired