Skip to content

Commit

Permalink
refactor: update health check timeout in spawn_prover function, rewri…
Browse files Browse the repository at this point in the history
…te prove_batch_append test

Change CI runner to buildjet-8vcpu-ubuntu-2204 for rust tests

run rust.yml on buildjet-16vcpu-ubuntu-2204

debug rust.yml workflow

Add step to download proving keys for big batches

Remove redundant setup steps and update test configurations

Update ProverConfig to use test-specific circuits

cleaning up after rebase to main
  • Loading branch information
sergeytimoshin committed Nov 8, 2024
1 parent 2898eac commit c192b75
Show file tree
Hide file tree
Showing 13 changed files with 573 additions and 587 deletions.
1 change: 1 addition & 0 deletions .github/actionlint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ self-hosted-runner:
- buildjet-2vcpu-ubuntu-2204
- buildjet-4vcpu-ubuntu-2204
- buildjet-8vcpu-ubuntu-2204
- buildjet-16vcpu-ubuntu-2204
# Configuration variables in array of strings defined in your repository or
# organization. `null` means disabling configuration variables check.
# Empty array means no configuration variable is allowed.
Expand Down
2 changes: 1 addition & 1 deletion circuit-lib/light-prover-client/src/gnark/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub async fn spawn_prover(restart: bool, config: ProverConfig) {

let _ = command.spawn().expect("Failed to start prover process");

let health_result = health_check(20, 5).await;
let health_result = health_check(20, 30).await;
if health_result {
info!("Prover started successfully");
} else {
Expand Down
12 changes: 6 additions & 6 deletions circuit-lib/light-prover-client/src/mock_batched_forester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use light_utils::bigint::bigint_to_be_bytes_array;
use reqwest::Client;

use crate::{
batch_append::calculate_hash_chain,
batch_append_2::get_batch_append2_inputs,
batch_append_with_subtrees::calculate_hash_chain,
batch_append_with_proofs::get_batch_append_with_proofs_inputs,
batch_update::get_batch_update_inputs,
gnark::{
batch_append_2_json_formatter::BatchAppend2ProofInputsJson,
batch_append_with_proofs_json_formatter::BatchAppendWithProofsInputsJson,
batch_update_json_formatter::update_inputs_string,
constants::{PROVE_PATH, SERVER_ADDRESS},
proof_helpers::{compress_proof, deserialize_gnark_proof_json, proof_from_json_struct},
Expand Down Expand Up @@ -80,10 +80,10 @@ impl<const HEIGHT: usize> MockBatchedForester<HEIGHT> {
for (i, leaf) in leaves.iter().enumerate() {
if old_leaves[i] == [0u8; 32] {
let index = account_next_index + i;
self.merkle_tree.update(&leaf, index).unwrap();
self.merkle_tree.update(leaf, index).unwrap();
}
}
let circuit_inputs = get_batch_append2_inputs::<HEIGHT>(
let circuit_inputs = get_batch_append_with_proofs_inputs::<HEIGHT>(
old_root,
start_index as u32,
leaves,
Expand All @@ -97,7 +97,7 @@ impl<const HEIGHT: usize> MockBatchedForester<HEIGHT> {
self.merkle_tree.root()
);
let client = Client::new();
let inputs_json = BatchAppend2ProofInputsJson::from_inputs(&circuit_inputs).to_string();
let inputs_json = BatchAppendWithProofsInputsJson::from_inputs(&circuit_inputs).to_string();

let response_result = client
.post(&format!("{}{}", SERVER_ADDRESS, PROVE_PATH))
Expand Down
97 changes: 38 additions & 59 deletions circuit-lib/light-prover-client/tests/gnark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ async fn prove_batch_update() {
false,
ProverConfig {
run_mode: None,
circuits: vec![ProofType::BatchUpdate],
circuits: vec![ProofType::BatchUpdateTest],
},
)
.await;
Expand Down Expand Up @@ -363,102 +363,81 @@ async fn prove_batch_update() {
.send()
.await
.expect("Failed to execute request.");
assert!(response_result.status().is_success());

let status = response_result.status();
let body = response_result.text().await.unwrap();
assert!(
status.is_success(),
"Batch append proof generation failed. Status: {}, Body: {}",
status,
body
);
}
}

#[serial]
#[tokio::test]
async fn prove_batch_append() {
init_logger();
println!("spawning prover");
spawn_prover(
true,
ProverConfig {
run_mode: None,
circuits: vec![ProofType::BatchAppend],
circuits: vec![ProofType::BatchAppendTest],
},
)
.await;
println!("prover spawned");

const HEIGHT: usize = 26;
const CANOPY: usize = 0;
let num_insertions = 10;
let tx_hash = [0u8; 32];

info!("initializing merkle tree for update.");
let mut merkle_tree = MerkleTree::<Poseidon>::new(HEIGHT, CANOPY);
// Do multiple rounds of batch appends
for _ in 0..2 {
info!("initializing merkle tree for append.");
let merkle_tree = MerkleTree::<Poseidon>::new(HEIGHT, CANOPY);

let old_subtrees = merkle_tree.get_subtrees();
let mut leaves = vec![];
let mut nullifiers = vec![];

// Create leaves for this batch append
for i in 0..num_insertions {
let mut bn: [u8; 32] = [0; 32];
bn[31] = i as u8;
let leaf: [u8; 32] = Poseidon::hash(&bn).unwrap();
leaves.push(leaf);
merkle_tree.append(&leaf).unwrap();
let nullifier = Poseidon::hashv(&[&leaf, &tx_hash]).unwrap();
nullifiers.push(nullifier);
}

let mut merkle_proofs = vec![];
let mut path_indices = vec![];
for index in 0..leaves.len() {
let proof = merkle_tree.get_proof_of_leaf(index, true).unwrap();
merkle_proofs.push(proof.to_vec());
path_indices.push(index as u32);
}
let root = merkle_tree.root();
let leaves_hashchain = calculate_hash_chain(&nullifiers);
let inputs = get_batch_update_inputs::<HEIGHT>(
root,
vec![tx_hash; num_insertions],
let leaves_hashchain = calculate_hash_chain(&leaves);

// Generate inputs for batch append operation
let inputs = get_batch_append_inputs::<HEIGHT>(
merkle_tree.layers[0].len(),
old_subtrees.try_into().unwrap(),
leaves,
leaves_hashchain,
merkle_proofs,
path_indices,
num_insertions as u32,
);
let client = Client::new();
let inputs = update_inputs_string(&inputs);

// Send proof request to the server
let client = Client::new();
let inputs = append_inputs_string(&inputs);
let response_result = client
.post(&format!("{}{}", SERVER_ADDRESS, PROVE_PATH))
.header("Content-Type", "text/plain; charset=utf-8")
.body(inputs)
.send()
.await
.expect("Failed to execute request.");
assert!(response_result.status().is_success());
}

let num_insertions = 10;

info!("initializing merkle tree for append.");
let merkle_tree = MerkleTree::<Poseidon>::new(HEIGHT, CANOPY);

let old_subtrees = merkle_tree.get_subtrees();
let mut leaves = vec![];
for i in 0..num_insertions {
let mut bn: [u8; 32] = [0; 32];
bn[31] = i as u8;
let leaf: [u8; 32] = Poseidon::hash(&bn).unwrap();
leaves.push(leaf);
let status = response_result.status();
let body = response_result.text().await.unwrap();
assert!(
status.is_success(),
"Batch append proof generation failed. Status: {}, Body: {}",
status,
body
);
}

let leaves_hashchain = calculate_hash_chain(&leaves);
let inputs = get_batch_append_inputs::<HEIGHT>(
merkle_tree.layers[0].len(),
old_subtrees.try_into().unwrap(),
leaves,
leaves_hashchain,
);
let client = Client::new();
let inputs = append_inputs_string(&inputs);
let response_result = client
.post(&format!("{}{}", SERVER_ADDRESS, PROVE_PATH))
.header("Content-Type", "text/plain; charset=utf-8")
.body(inputs)
.send()
.await
.expect("Failed to execute request.");
assert!(response_result.status().is_success());
}
2 changes: 1 addition & 1 deletion cli/src/utils/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export async function waitForServers(
({ port, path }) => `http-get://127.0.0.1:${port}${path}`,
),
delay: 1000,
timeout: 25000,
timeout: 360_000,
interval: 300,
simultaneous: 2,
validateStatus: function (status: number) {
Expand Down
Loading

0 comments on commit c192b75

Please sign in to comment.