|
1 | 1 | use crate::{ |
2 | 2 | ActorId, CancelJobParams, ClaimJobParams, CreateJobParams, ExpireClaimParams, JobId, |
3 | | - SettleJobParams, SubmitProofParams, Verdict, |
| 3 | + SettleJobParams, SubmitProofParams, Verdict, VerificationBackend, |
4 | 4 | }; |
5 | 5 |
|
6 | 6 | #[derive(Debug, Clone, PartialEq, Eq)] |
@@ -60,25 +60,38 @@ impl TaskForestInstruction { |
60 | 60 | })) |
61 | 61 | } |
62 | 62 | "submit_proof" => { |
63 | | - if parts.len() != 5 { |
| 63 | + if parts.len() < 5 { |
64 | 64 | return Err(InstructionDecodeError::InvalidFormat); |
65 | 65 | } |
66 | 66 | Ok(Self::SubmitProof(SubmitProofParams { |
67 | 67 | job_id: parse_u64(parts[1])?, |
68 | 68 | submitter: parse_actor(parts[2]), |
69 | 69 | proof_hash: parts[3].to_string(), |
70 | 70 | now_epoch_secs: parse_u64(parts[4])?, |
| 71 | + evidence_refs: parts[5..].iter().map(|v| (*v).to_string()).collect(), |
71 | 72 | })) |
72 | 73 | } |
73 | 74 | "settle_job" => { |
74 | | - if parts.len() != 5 { |
| 75 | + if parts.len() != 5 && parts.len() != 6 && parts.len() != 7 { |
75 | 76 | return Err(InstructionDecodeError::InvalidFormat); |
76 | 77 | } |
| 78 | + let backend = if parts.len() >= 6 { |
| 79 | + parse_backend(parts[5]) |
| 80 | + } else { |
| 81 | + VerificationBackend::Native |
| 82 | + }; |
| 83 | + let verification_ref = if parts.len() == 7 { |
| 84 | + Some(parts[6].to_string()) |
| 85 | + } else { |
| 86 | + None |
| 87 | + }; |
77 | 88 | Ok(Self::SettleJob(SettleJobParams { |
78 | 89 | job_id: parse_u64(parts[1])?, |
79 | 90 | verdict: parse_verdict(parts[2])?, |
80 | 91 | reason_code: parts[3].to_string(), |
81 | 92 | now_epoch_secs: parse_u64(parts[4])?, |
| 93 | + verification_backend: backend, |
| 94 | + verification_ref, |
82 | 95 | })) |
83 | 96 | } |
84 | 97 | "open_dispute" => { |
@@ -129,6 +142,16 @@ fn parse_verdict(value: &str) -> Result<Verdict, InstructionDecodeError> { |
129 | 142 | } |
130 | 143 | } |
131 | 144 |
|
| 145 | +fn parse_backend(value: &str) -> VerificationBackend { |
| 146 | + match value { |
| 147 | + "native" => VerificationBackend::Native, |
| 148 | + "arcium" => VerificationBackend::Arcium, |
| 149 | + "magicblock" => VerificationBackend::MagicBlock, |
| 150 | + "hybrid" => VerificationBackend::Hybrid, |
| 151 | + other => VerificationBackend::Custom(other.to_string()), |
| 152 | + } |
| 153 | +} |
| 154 | + |
132 | 155 | #[cfg(test)] |
133 | 156 | mod tests { |
134 | 157 | use super::*; |
@@ -161,4 +184,24 @@ mod tests { |
161 | 184 | let result = TaskForestInstruction::unpack(b"submit_proof|1|proof-hash-only|2000"); |
162 | 185 | assert_eq!(result, Err(InstructionDecodeError::InvalidFormat)); |
163 | 186 | } |
| 187 | + |
| 188 | + #[test] |
| 189 | + fn settle_instruction_supports_backend_and_ref() { |
| 190 | + let instruction = TaskForestInstruction::unpack( |
| 191 | + b"settle_job|77|pass|CHECKS_PASS_ALL|1000|arcium|arcium://proof/77", |
| 192 | + ) |
| 193 | + .expect("settle should unpack"); |
| 194 | + |
| 195 | + match instruction { |
| 196 | + TaskForestInstruction::SettleJob(params) => { |
| 197 | + assert_eq!(params.job_id, 77); |
| 198 | + assert_eq!(params.verification_backend, VerificationBackend::Arcium); |
| 199 | + assert_eq!( |
| 200 | + params.verification_ref, |
| 201 | + Some("arcium://proof/77".to_string()) |
| 202 | + ); |
| 203 | + } |
| 204 | + _ => panic!("expected settle instruction"), |
| 205 | + } |
| 206 | + } |
164 | 207 | } |
0 commit comments