1use std::{sync::Arc, time::Duration};
16
17use serde::{Deserialize, Serialize};
18
19use crate::{AssumptionReceipt, Journal, Receipt};
20
21#[derive(Serialize, Deserialize)]
23pub struct ProofRequest {
24 pub binary: Vec<u8>,
26
27 pub input: Vec<u8>,
29
30 pub assumptions: Vec<AssumptionReceipt>,
32
33 pub segment_limit_po2: Option<u32>,
35}
36
37#[derive(Clone, Debug, Serialize, Deserialize)]
39pub struct JobInfo {
40 pub status: JobStatus,
42
43 pub elapsed_time: Duration,
45}
46
47#[derive(Clone, Debug, Serialize, Deserialize)]
49pub enum JobStatus {
50 Running(String),
52
53 Succeeded(ProofResult),
55
56 Failed(TaskError),
58
59 TimedOut,
61
62 Aborted,
64}
65
66#[derive(Clone, Debug, Serialize, Deserialize)]
68pub struct ProofResult {
69 pub session: Arc<Session>,
71
72 pub receipt: Arc<Receipt>,
74}
75
76#[derive(Debug, Serialize, Deserialize)]
78pub struct Session {
79 pub segment_count: usize,
81
82 pub user_cycles: u64,
84
85 pub total_cycles: u64,
87
88 pub journal: Option<Journal>,
90
91 pub assumptions: Vec<Arc<AssumptionReceipt>>,
93}
94
95#[derive(Clone, Debug, Serialize, Deserialize)]
97pub enum TaskError {
98 Generic(String),
100}
101
102impl JobStatus {
103 pub fn bonsai_status(&self) -> &str {
105 match self {
106 JobStatus::Running(_) => "RUNNING",
107 JobStatus::Succeeded(_) => "SUCCEEDED",
108 JobStatus::Failed(_) => "FAILED",
109 JobStatus::TimedOut => "TIMED_OUT",
110 JobStatus::Aborted => "ABORTED",
111 }
112 }
113}
114
115impl From<anyhow::Error> for TaskError {
116 fn from(value: anyhow::Error) -> Self {
117 Self::Generic(value.to_string())
118 }
119}