@@ -12,6 +12,7 @@ use ethers::signers::{LocalWallet, Signer};
12
12
use tokio:: time:: sleep;
13
13
use tokio:: time:: Duration ;
14
14
15
+ use anyhow:: { bail, Result } ;
15
16
use async_trait:: async_trait;
16
17
17
18
#[ derive( Clone ) ]
@@ -24,7 +25,7 @@ pub mod stage_service {
24
25
tonic:: include_proto!( "stage.v1" ) ;
25
26
}
26
27
27
- use crate :: network:: prover:: stage_service:: Status ;
28
+ use crate :: network:: prover:: stage_service:: { Status , Step } ;
28
29
29
30
pub struct NetworkProver {
30
31
pub stage_client : StageServiceClient < Channel > ,
@@ -83,7 +84,7 @@ impl NetworkProver {
83
84
request. signature = signature. to_string ( ) ;
84
85
}
85
86
86
- pub async fn download_file ( url : & str ) -> anyhow :: Result < Vec < u8 > > {
87
+ pub async fn download_file ( url : & str ) -> Result < Vec < u8 > > {
87
88
let response = reqwest:: get ( url) . await ?;
88
89
let content = response. bytes ( ) . await ?;
89
90
Ok ( content. to_vec ( ) )
@@ -92,7 +93,7 @@ impl NetworkProver {
92
93
93
94
#[ async_trait]
94
95
impl Prover for NetworkProver {
95
- async fn request_proof < ' a > ( & self , input : & ' a ProverInput ) -> anyhow :: Result < String > {
96
+ async fn request_proof < ' a > ( & self , input : & ' a ProverInput ) -> Result < String > {
96
97
let proof_id = uuid:: Uuid :: new_v4 ( ) . to_string ( ) ;
97
98
let mut request = GenerateProofRequest {
98
99
proof_id : proof_id. clone ( ) ,
@@ -120,7 +121,7 @@ impl Prover for NetworkProver {
120
121
& self ,
121
122
proof_id : & ' a str ,
122
123
timeout : Option < Duration > ,
123
- ) -> anyhow :: Result < Option < ProverResult > > {
124
+ ) -> Result < Option < ProverResult > > {
124
125
let start_time = Instant :: now ( ) ;
125
126
let mut split_start_time = Instant :: now ( ) ;
126
127
let mut split_end_time = Instant :: now ( ) ;
@@ -129,7 +130,7 @@ impl Prover for NetworkProver {
129
130
loop {
130
131
if let Some ( timeout) = timeout {
131
132
if start_time. elapsed ( ) > timeout {
132
- return Err ( anyhow :: anyhow !( "Proof generation timed out." ) ) ;
133
+ bail ! ( "Proof generation timed out." ) ;
133
134
}
134
135
}
135
136
@@ -139,25 +140,27 @@ impl Prover for NetworkProver {
139
140
match Status :: from_i32 ( get_status_response. status as i32 ) {
140
141
Some ( Status :: Computing ) => {
141
142
//log::info!("generate_proof step: {}", get_status_response.step);
142
- match get_status_response. step {
143
- 0 => log:: info!( "generate_proof : queuing the task." ) ,
144
- 1 => {
143
+ match Step :: from_i32 ( get_status_response. step ) {
144
+ Some ( Step :: Init ) => log:: info!( "generate_proof : queuing the task." ) ,
145
+ Some ( Step :: InSplit ) => {
145
146
if last_step == 0 {
146
147
split_start_time = Instant :: now ( ) ;
147
148
}
148
149
log:: info!( "generate_proof : splitting the task." ) ;
149
150
}
150
- 2 => {
151
+ Some ( Step :: InProve ) => {
151
152
if last_step == 1 {
152
153
split_end_time = Instant :: now ( ) ;
153
154
}
154
155
log:: info!( "generate_proof : proving the task." ) ;
155
156
}
156
- 3 => log:: info!( "generate_proof : aggregating the proof." ) ,
157
- 4 => log:: info!( "generate_proof : aggregating the proof." ) ,
158
- 5 => log:: info!( "generate_proof : finalizing the proof." ) ,
159
- 6 => log:: info!( "generate_proof : completing the proof." ) ,
160
- i32:: MIN ..=-1_i32 | 7_i32 ..=i32:: MAX => todo ! ( ) ,
157
+ Some ( Step :: InAgg ) => log:: info!( "generate_proof : aggregating the proof." ) ,
158
+ Some ( Step :: InAggAll ) => {
159
+ log:: info!( "generate_proof : aggregating the proof." )
160
+ }
161
+ Some ( Step :: InFinal ) => log:: info!( "generate_proof : finalizing the proof." ) ,
162
+ Some ( Step :: End ) => log:: info!( "generate_proof : completing the proof." ) ,
163
+ None => todo ! ( ) ,
161
164
}
162
165
last_step = get_status_response. step ;
163
166
sleep ( Duration :: from_secs ( 30 ) ) . await ;
@@ -195,11 +198,7 @@ impl Prover for NetworkProver {
195
198
}
196
199
_ => {
197
200
log:: error!( "generate_proof failed status: {}" , get_status_response. status) ;
198
- //return Ok(None);
199
- return Err ( anyhow:: anyhow!(
200
- "generate_proof failed status: {}" ,
201
- get_status_response. status
202
- ) ) ;
201
+ bail ! ( "generate_proof failed status: {}" , get_status_response. status) ;
203
202
}
204
203
}
205
204
}
@@ -210,17 +209,15 @@ impl Prover for NetworkProver {
210
209
_vk_path : & ' a str ,
211
210
_input : & ' a ProverInput ,
212
211
_timeout : Option < Duration > ,
213
- ) -> anyhow:: Result < ( ) > {
214
- log:: info!( "The proof network does not support the method." ) ;
215
-
212
+ ) -> Result < ( ) > {
216
213
panic ! ( "The proof network does not support the method!" ) ;
217
214
}
218
215
219
216
async fn prove < ' a > (
220
217
& self ,
221
218
input : & ' a ProverInput ,
222
219
timeout : Option < Duration > ,
223
- ) -> anyhow :: Result < Option < ProverResult > > {
220
+ ) -> Result < Option < ProverResult > > {
224
221
log:: info!( "calling request_proof." ) ;
225
222
let proof_id = self . request_proof ( input) . await ?;
226
223
log:: info!( "calling wait_proof, proof_id={}" , proof_id) ;
0 commit comments