Skip to content

Commit

Permalink
fix: fix verify
Browse files Browse the repository at this point in the history
  • Loading branch information
BC-A committed Sep 26, 2024
1 parent a69ad01 commit 4058a42
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/config/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ pub static GLOBAL_ENV: Lazy<GlobalEnv> = Lazy::new(|| GlobalEnv {
bridge_service_addr: std::env::var("BRIDGE_SERVICE_ADDR")
.unwrap_or("http://localhost:8001".to_string()),
debug_proof: std::env::var("DEBUG_PROOF")
.unwrap_or_else(|_| String::from("TRUE"))
.eq_ignore_ascii_case("TRUE"),
.unwrap_or_else(|_| String::from("FALSE"))
.eq_ignore_ascii_case("FALSE"),
});
28 changes: 22 additions & 6 deletions src/settlement/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,18 @@ pub fn gen_proof_without_prover(
) {
let mut batch = next_batch;
while batch <= last_submitted_block {
let proof: String = std::fs::read_to_string("proof/proof.json").unwrap_or_default();
let public_input: String =
std::fs::read_to_string("proof/public_input.json").unwrap_or_default();
let proof_path = format!("{}/proof/proof.json", env!("CARGO_MANIFEST_DIR"));
let public_input_path = format!("{}/proof/public_input.json", env!("CARGO_MANIFEST_DIR"));
let proof: String = std::fs::read_to_string(proof_path).unwrap_or_default();
let public_input: String = std::fs::read_to_string(public_input_path).unwrap_or_default();

let mut default_bytes: [u8; 32] = Default::default();
default_bytes[24..].copy_from_slice(&(batch).to_le_bytes());
let execute_result = ProofResult {
block_number: batch,
proof,
public_input,
post_state_root: default_bytes,
..Default::default()
};
log::info!("execute batch {} success: {:?}", batch, execute_result);
Expand Down Expand Up @@ -341,7 +346,17 @@ impl Settler {
}
};

if last_submitted_block >= last_sequence_finality_block_number {
let last_verified_block = match db.get(keys::KEY_LAST_VERIFIED_BLOCK_NUMBER) {
None => {
db.put(keys::KEY_LAST_VERIFIED_BLOCK_NUMBER.to_vec(), 0_u64.to_be_bytes().to_vec());
0
}
Some(block_number_bytes) => {
u64::from_be_bytes(block_number_bytes.try_into().unwrap())
}
};

if last_submitted_block >= last_sequence_finality_block_number || last_verified_block < last_submitted_block{
log::info!("no new block to submit, try again later");
continue;
}
Expand Down Expand Up @@ -375,6 +390,7 @@ impl Settler {
};

// 1. update the last verified block number, trigger the next verify task

db.put(keys::KEY_LAST_VERIFIED_BLOCK_NUMBER.to_vec(), execute_result.block_number.to_be_bytes().to_vec());

let status_key = format!("{}{}", std::str::from_utf8(prefix::PREFIX_BLOCK_STATUS).unwrap(), execute_result.block_number);
Expand Down Expand Up @@ -588,7 +604,7 @@ mod tests {
#[ignore = "slow"]
async fn test_proof_worker() {
env::set_var("RUST_LOG", "debug");
env::set_var("DEBUG_PROOF", "FALSE");
env::set_var("DEBUG_PROOF", "TRUE");
env_logger::init();
let path = "tmp/test_proof_worker";
let max_dbs = 20;
Expand All @@ -602,7 +618,7 @@ mod tests {

arc_db.put(
keys::KEY_LAST_SUBMITTED_BLOCK_NUMBER.to_vec(),
3_u64.to_be_bytes().to_vec(),
1_u64.to_be_bytes().to_vec(),
);
arc_db.put(keys::KEY_NEXT_BATCH.to_vec(), 0_u64.to_be_bytes().to_vec());

Expand Down

0 comments on commit 4058a42

Please sign in to comment.