Skip to content

Commit

Permalink
add proof process status when submit proof
Browse files Browse the repository at this point in the history
  • Loading branch information
zkrollupdev committed Oct 31, 2023
1 parent 7011feb commit 58c4463
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
9 changes: 6 additions & 3 deletions src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ impl Prover {
let _ = task::spawn(async move { //maybe multi-thread compute task in future

let task_handle = task::spawn(async move {
let mut status:u8=1;
let time_started = Instant::now();
let agg_proof_result = match generate_proof(
l2_rpc,
Expand All @@ -187,7 +188,10 @@ impl Prover {
maxtransactionsperblock,
maxbytespertxlist).await{
Ok(r) => r,
Err(_) => ProofResult::default(),
Err(_) => {
status=0;
ProofResult::default()
},
};
let time_gap =(Instant::now().duration_since(time_started).as_millis() as u32)/1000;
info!("try to sumbit the block {} proof to zkpool,proof is {:?},time consumed:{}",block,agg_proof_result,time_gap);
Expand All @@ -198,15 +202,14 @@ impl Prover {
proofoutput=format!("{}#{}",proofoutput,var.to_string())
}
let proof_res = format!("{}#{}",proofoutput,agg_proof_result.proof);


let message = StratumMessage::Submit(
Id::Num(0),
project_name.clone(),
block.to_string(),
proof_res,
agg_proof_result.k,
time_gap,
status,
);
if let Err(error) = client.sender().send(message).await {
error!("Failed to send PoolResponse: {}", error);
Expand Down
11 changes: 6 additions & 5 deletions stratum/src/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl Default for StratumCodec {
struct NotifyParams(String,u64,String,u64);

#[derive(Serialize, Deserialize)]
struct SubmitParams(String,String, String,u8,u32);
struct SubmitParams(String,String, String,u8,u32,u8);

#[derive(Serialize, Deserialize)]
struct HeartBeatParams(String, String);
Expand Down Expand Up @@ -138,11 +138,11 @@ impl Encoder<StratumMessage> for StratumCodec {
};
serde_json::to_vec(&request).unwrap_or_default()
}
StratumMessage::Submit(id, project_name,block, proof,degree,time) => {
StratumMessage::Submit(id, project_name,block, proof,degree,time,status) => {
let request = Request {
jsonrpc: Version::V2,
method: "zkpool.submit",
params: Some(SubmitParams(project_name,block, proof,degree,time)),
params: Some(SubmitParams(project_name,block, proof,degree,time,status)),
id: Some(id),
};
serde_json::to_vec(&request).unwrap_or_default()
Expand Down Expand Up @@ -263,15 +263,16 @@ impl Decoder for StratumCodec {
StratumMessage::Notify(id.unwrap(),project_name,task_id,task_content,degree)
}
"zkpool.submit" => {
if params.len() != 5 {
if params.len() != 6 {
return Err(io::Error::new(io::ErrorKind::InvalidData, "Invalid params"));
}
let project_name = unwrap_str_value(&params[0])?;
let block = unwrap_str_value(&params[1])?;
let proof = unwrap_str_value(&params[2])?;
let degree = unwrap_u64_value(&params[3])? as u8;
let time = unwrap_u64_value(&params[4])?;
StratumMessage::Submit(id.unwrap_or(Id::Num(0)), project_name,block, proof,degree,time as u32)
let status = unwrap_u64_value(&params[5])? as u8;
StratumMessage::Submit(id.unwrap_or(Id::Num(0)), project_name,block, proof,degree,time as u32,status)
}
_ => {
return Err(io::Error::new(io::ErrorKind::InvalidData, "Unknown method"));
Expand Down
2 changes: 1 addition & 1 deletion stratum/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub enum StratumMessage {

Heartbeat(Id,String,String),

Submit(Id, String,String, String,u8,u32),
Submit(Id, String,String, String,u8,u32,u8),

Response(Id, Option<ResponseParams>, Option<Error<()>>),
}
Expand Down

0 comments on commit 58c4463

Please sign in to comment.